Skip to content

Commit

Permalink
+ Added support for building templates from branches as well as speci…
Browse files Browse the repository at this point in the history
…fic commits.
  • Loading branch information
cabal95 committed Jul 31, 2018
1 parent b311b34 commit f725b06
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 25 deletions.
30 changes: 25 additions & 5 deletions RockDevBooster/Views/GitHubVersions.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,54 @@
<Label
HorizontalAlignment="Left"
Margin="10,8,0,0"
Content="Version"
Content="Source"
VerticalAlignment="Top"
Width="75"
Style="{StaticResource labelStyleBold}"
/>
<ComboBox Name="cbTags"
<ComboBox Name="cbSourceType"
Margin="90,10,10,0"
VerticalAlignment="Top"
SelectionChanged="cbSourceType_SelectionChanged"/>
<Label Name="lSource"
HorizontalAlignment="Left"
Margin="10,34,0,0"
Content="Version"
VerticalAlignment="Top"
Width="75"
Style="{StaticResource labelStyleBold}"
/>
<TextBox Name="txtSource"
Margin="90,37,10,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Style="{StaticResource textboxStyle}"
Width="Auto"
Visibility="Hidden"
HorizontalAlignment="Stretch"/>
<ComboBox Name="cbSource"
Margin="90,37,10,0"
VerticalAlignment="Top"
SelectionChanged="cbTags_SelectionChanged"
/>

<Button Name="btnImport"
Content="&#xF0ED; Import"
Margin="0,37,10,0"
Margin="0,82,10,0"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Width="80"
Click="btnImport_Click"
Style="{StaticResource buttonStyleIconAction}"/>

<TextBlock Name="txtStatus"
Margin="10,78,10,0"
Margin="10,123,10,0"
TextWrapping="Wrap"
Text="Status"
TextAlignment="Center" Height="16" VerticalAlignment="Top"/>

<TextBox Name="txtConsole"
Margin="0,99,0,0"
Margin="0,144,0,0"
TextWrapping="NoWrap"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible"
Expand Down
138 changes: 118 additions & 20 deletions RockDevBooster/Views/GitHubVersions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace com.blueboxmoon.RockDevBooster.Views
/// <summary>
/// Interaction logic for GitHubVersions.xaml
/// </summary>
public partial class GitHubVersions : UserControl
public partial class GitHubVersions : UserControl, IViewDidShow
{
#region Protected Properties

Expand All @@ -23,6 +23,10 @@ public partial class GitHubVersions : UserControl
/// </summary>
protected ReleaseBuilder ReleaseBuilder { get; set; }

protected List<GitHubItem> GitHubTags { get; set; }

protected List<GitHubItem> GitHubBranches { get; set; }

#endregion

#region Constructors
Expand All @@ -38,8 +42,6 @@ public GitHubVersions()
{
txtStatus.Text = "Loading...";
btnImport.IsEnabled = false;

new Task( LoadData ).Start();
}
}

Expand All @@ -52,8 +54,39 @@ public GitHubVersions()
/// </summary>
protected void UpdateState()
{
var tags = cbTags.ItemsSource as List<GitHubTag>;
btnImport.IsEnabled = cbTags.SelectedIndex != -1 && !string.IsNullOrEmpty( tags[cbTags.SelectedIndex].Name );
if ( cbSourceType.Text == "Release Version" )
{
var tags = cbSource.ItemsSource as List<GitHubItem>;
int index = cbSource.SelectedIndex;

btnImport.IsEnabled = index != -1 && !string.IsNullOrEmpty( tags[index].Name );
}
else if ( cbSourceType.Text == "Branch" )
{
var branches = cbSource.ItemsSource as List<GitHubItem>;
int index = cbSource.SelectedIndex;

btnImport.IsEnabled = index != -1 && !string.IsNullOrEmpty( branches[index].Name );
}
else if ( cbSourceType.Text == "SHA-1 Commit" )
{
btnImport.IsEnabled = !string.IsNullOrWhiteSpace( txtSource.Text );
}
}

#endregion

#region Methods

/// <summary>
/// The view has become visible on screen.
/// </summary>
public void ViewDidShow()
{
if ( GitHubTags == null )
{
new Task( LoadData ).Start();
}
}

#endregion
Expand All @@ -67,28 +100,38 @@ private async void LoadData()
{
var client = new GitHubClient( new ProductHeaderValue( "RockDevBooster" ) );
var tags = client.Repository.GetAllTags( "SparkDevNetwork", "Rock" );
var branches = client.Repository.Branch.GetAll( "SparkDevNetwork", "Rock" );
var minimumVersion = new Version( 1, 1, 0 );

List<GitHubTag> list;
try
{
list = ( await tags )
.Select( t => new GitHubTag( t ) )
GitHubTags = ( await tags )
.Select( t => new GitHubItem( t ) )
.Where( t => t.Version >= minimumVersion )
.OrderByDescending( t => t.Version )
.ToList();

GitHubBranches = ( await branches )
.Select( b => new GitHubItem( b ) )
.OrderBy( b => b.Name )
.ToList();
}
catch
{
list = new List<GitHubTag>();
GitHubTags = new List<GitHubItem>();
GitHubBranches = new List<GitHubItem>();
}
list.Insert( 0, new GitHubTag() );
GitHubTags.Insert( 0, new GitHubItem() );
GitHubBranches.Insert( 0, new GitHubItem() );

Dispatcher.Invoke( () =>
{
cbTags.ItemsSource = list;
txtStatus.Text = string.Empty;
cbTags.SelectedIndex = 0;
cbSourceType.Items.Add( "Release Version" );
cbSourceType.Items.Add( "Branch" );
cbSourceType.Items.Add( "SHA-1 Commit" );
cbSourceType.SelectedIndex = 0;

txtStatus.Text = "Ready";
} );
}

Expand All @@ -103,14 +146,27 @@ private async void LoadData()
/// <param name="e">The event arguments.</param>
private void btnImport_Click( object sender, RoutedEventArgs e )
{
var tags = cbTags.ItemsSource as List<GitHubTag>;
var tag = tags[cbTags.SelectedIndex];
var vs = VisualStudioInstall.GetDefaultInstall();
GitHubItem item;

if ( cbSourceType.SelectedItem.ToString() == "Release Version" || cbSourceType.SelectedItem.ToString() == "Branch" )
{
var items = cbSource.ItemsSource as List<GitHubItem>;
item = items[cbSource.SelectedIndex];
}
else
{
item = new GitHubItem
{
Name = txtSource.Text.ToLowerInvariant(),
ZipballUrl = string.Format( "https://github.com/SparkDevNetwork/Rock/archive/{0}.zip", txtSource.Text.ToLowerInvariant() )
};
}

//
// Check if this template already exists.
//
var templateName = "RockBase-" + tag.Name;
var templateName = "RockBase-" + item.Name;
if ( File.Exists( Path.Combine( Support.GetTemplatesPath(), templateName + ".zip" ) ) )
{
MessageBox.Show( "A template with the name " + templateName + " already exists.", "Cannot import", MessageBoxButton.OK, MessageBoxImage.Hand );
Expand All @@ -136,7 +192,7 @@ private void btnImport_Click( object sender, RoutedEventArgs e )
//
new Task( () =>
{
ReleaseBuilder.DownloadRelease( tag.ZipballUrl, vs.GetExecutable(), "RockBase-" + tag.Name );
ReleaseBuilder.DownloadRelease( item.ZipballUrl, vs.GetExecutable(), "RockBase-" + item.Name );
} ).Start();
}

Expand Down Expand Up @@ -191,26 +247,61 @@ private void ReleaseBuilder_StatusTextChanged( object sender, string text )
} );
}

/// <summary>
/// Handles the SelectionChanged event of the cbSourceType control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs" /> instance containing the event data.</param>
private void cbSourceType_SelectionChanged( object sender, SelectionChangedEventArgs e )
{
if ( cbSourceType.SelectedItem.ToString() == "Release Version" )
{
lSource.Content = "Version";
txtSource.Visibility = Visibility.Hidden;

cbSource.ItemsSource = GitHubTags;
cbSource.SelectedIndex = 0;
cbSource.Visibility = Visibility.Visible;
}
else if ( cbSourceType.SelectedItem.ToString() == "Branch" )
{
lSource.Content = "Branch";
txtSource.Visibility = Visibility.Hidden;

cbSource.ItemsSource = GitHubBranches;
cbSource.SelectedIndex = 0;
cbSource.Visibility = Visibility.Visible;
}
else if ( cbSourceType.SelectedItem.ToString() == "SHA-1 Commit" )
{
lSource.Content = "Commit";
txtSource.Visibility = Visibility.Visible;
cbSource.Visibility = Visibility.Hidden;
}

UpdateState();
}

#endregion

#region Classes

/// <summary>
/// Helper class to identify a GutHub Tag Release.
/// </summary>
protected class GitHubTag
protected class GitHubItem
{
public string Name { get; set; }

public string ZipballUrl { get; set; }

public Version Version { get; set; }

public GitHubTag()
public GitHubItem()
{
}

public GitHubTag( RepositoryTag tag )
public GitHubItem( RepositoryTag tag )
{
Name = tag.Name;
ZipballUrl = tag.ZipballUrl;
Expand All @@ -223,6 +314,13 @@ public GitHubTag( RepositoryTag tag )
Version = v;
}

public GitHubItem( Branch branch )
{
Name = branch.Name;
ZipballUrl = string.Format( "https://github.com/SparkDevNetwork/Rock/archive/{0}.zip", branch.Name );
Version = new Version();
}

public override string ToString()
{
return Name ?? string.Empty;
Expand Down

0 comments on commit f725b06

Please sign in to comment.