Skip to content

Commit 6adce84

Browse files
authored
Merge pull request #125 from gep13/feature/GH-124
(GH-124) Added new label verb
2 parents f03f902 + 88c9bc0 commit 6adce84

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="LabelSubOptions.cs" company="GitTools Contributors">
3+
// Copyright (c) 2015 - Present - GitTools Contributors
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace GitReleaseManager.Cli.Options
8+
{
9+
using CommandLine;
10+
11+
[Verb("label", HelpText = "Deletes existing labels and replaces with set of default labels.")]
12+
public class LabelSubOptions : BaseGitHubSubOptions
13+
{
14+
}
15+
}

Source/GitReleaseManager.Cli/Options/MainOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class MainOptions
2222

2323
public ShowConfigSubOptions ShowConfigVerb { get; set; }
2424

25+
public LabelSubOptions LabelVerb { get; set; }
26+
2527
////[HelpVerbOption]
2628
////public string DoHelpForVerb(string verbName)
2729
////{

Source/GitReleaseManager.Cli/Program.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static int Main(string[] args)
3535

3636
var fileSystem = new FileSystem();
3737

38-
return Parser.Default.ParseArguments<CreateSubOptions, AddAssetSubOptions, CloseSubOptions, PublishSubOptions, ExportSubOptions, InitSubOptions, ShowConfigSubOptions>(args)
38+
return Parser.Default.ParseArguments<CreateSubOptions, AddAssetSubOptions, CloseSubOptions, PublishSubOptions, ExportSubOptions, InitSubOptions, ShowConfigSubOptions, LabelSubOptions>(args)
3939
.MapResult(
4040
(CreateSubOptions opts) => CreateReleaseAsync(opts, fileSystem).Result,
4141
(AddAssetSubOptions opts) => AddAssetsAsync(opts).Result,
@@ -44,6 +44,7 @@ private static int Main(string[] args)
4444
(ExportSubOptions opts) => ExportReleasesAsync(opts, fileSystem).Result,
4545
(InitSubOptions opts) => CreateSampleConfigFile(opts, fileSystem),
4646
(ShowConfigSubOptions opts) => ShowConfig(opts, fileSystem),
47+
(LabelSubOptions opts) => CreateLabelsAsync(opts).Result,
4748
errs => 1);
4849
}
4950

@@ -179,6 +180,46 @@ private static int ShowConfig(ShowConfigSubOptions subOptions, IFileSystem fileS
179180
return 0;
180181
}
181182

183+
private static async Task<int> CreateLabelsAsync(LabelSubOptions subOptions)
184+
{
185+
try
186+
{
187+
ConfigureLogging(subOptions.LogFilePath);
188+
189+
var newLabels = new List<NewLabel>();
190+
newLabels.Add(new NewLabel("Breaking change", "b60205"));
191+
newLabels.Add(new NewLabel("Bug", "ee0701"));
192+
newLabels.Add(new NewLabel("Build", "009800"));
193+
newLabels.Add(new NewLabel("Documentation", "d4c5f9"));
194+
newLabels.Add(new NewLabel("Feature", "84b6eb"));
195+
newLabels.Add(new NewLabel("Improvement", "207de5"));
196+
newLabels.Add(new NewLabel("Question", "cc317c"));
197+
newLabels.Add(new NewLabel("good first issue", "7057ff"));
198+
newLabels.Add(new NewLabel("help wanted", "33aa3f"));
199+
200+
var github = subOptions.CreateGitHubClient();
201+
202+
var labels = await github.Issue.Labels.GetAllForRepository(subOptions.RepositoryOwner, subOptions.RepositoryName);
203+
204+
foreach (var label in labels)
205+
{
206+
await github.Issue.Labels.Delete(subOptions.RepositoryOwner, subOptions.RepositoryName, label.Name);
207+
}
208+
209+
foreach (var label in newLabels)
210+
{
211+
await github.Issue.Labels.Create(subOptions.RepositoryOwner, subOptions.RepositoryName, label);
212+
}
213+
214+
return 0;
215+
}
216+
catch (Exception ex)
217+
{
218+
Console.WriteLine(ex);
219+
220+
return 1;
221+
}
222+
}
182223
private static async Task<Release> CreateReleaseFromMilestone(GitHubClient github, string owner, string repository, string milestone, string targetCommitish, IList<string> assets, bool prerelease, Config configuration)
183224
{
184225
var releaseNotesBuilder = new ReleaseNotesBuilder(new DefaultGitHubClient(github, owner, repository), owner, repository, milestone, configuration);

0 commit comments

Comments
 (0)