Skip to content

Commit

Permalink
Merge pull request #258 from akordowski/feature/GH-188-configure-defa…
Browse files Browse the repository at this point in the history
…ult-labels

(GH-188) Configure default labels
  • Loading branch information
gep13 authored Jul 26, 2020
2 parents c0c65fd + 7d61711 commit 1deaf3c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 21 deletions.
70 changes: 70 additions & 0 deletions Source/GitReleaseManager/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,72 @@ public Config()
IssueCommentFormat = IssueCommentFormat,
};

Labels = new List<LabelConfig>
{
new LabelConfig
{
Name = "Breaking Change",
Description = "Functionality breaking changes",
Color = "b60205",
},

new LabelConfig
{
Name = "Bug",
Description = "Something isn't working",
Color = "ee0701",
},

new LabelConfig
{
Name = "Build",
Description = "Build pipeline",
Color = "009800",
},

new LabelConfig
{
Name = "Documentation",
Description = "Improvements or additions to documentation",
Color = "d4c5f9",
},

new LabelConfig
{
Name = "Feature",
Description = "Request for a new feature",
Color = "84b6eb",
},

new LabelConfig
{
Name = "Good First Issue",
Description = "Good for newcomers",
Color = "7057ff",
},

new LabelConfig
{
Name = "Help Wanted",
Description = "Extra attention is needed",
Color = "33aa3f",
},

new LabelConfig
{
Name = "Improvement",
Description = "Improvement of an existing feature",
Color = "207de5",
},

new LabelConfig
{
Name = "Question",
Description = "Further information is requested",
Color = "cc317c",
},
};

IssueLabelsInclude = new List<string>
{
"Bug",
Expand Down Expand Up @@ -86,6 +152,10 @@ public Config()
[YamlMember(Alias = "close")]
public CloseConfig Close { get; set; }

[Description("Configuration values used when creating labels")]
[YamlMember(Alias = "labels")]
public IList<LabelConfig> Labels { get; }

[Description("The labels that will be used to include issues in release notes.")]
[YamlMember(Alias = "issue-labels-include")]
public IList<string> IssueLabelsInclude { get; private set; }
Expand Down
16 changes: 16 additions & 0 deletions Source/GitReleaseManager/Configuration/LabelConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace GitReleaseManager.Core.Configuration
{
using YamlDotNet.Serialization;

public class LabelConfig
{
[YamlMember(Alias = "name")]
public string Name { get; set; }

[YamlMember(Alias = "description")]
public string Description { get; set; }

[YamlMember(Alias = "color")]
public string Color { get; set; }
}
}
46 changes: 25 additions & 21 deletions Source/GitReleaseManager/GitHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,31 +343,35 @@ public async Task PublishRelease(string owner, string repository, string tagName

public async Task CreateLabels(string owner, string repository)
{
var newLabels = new List<NewLabel>
if (_configuration.Labels.Any())
{
new NewLabel("Breaking change", "b60205"),
new NewLabel("Bug", "ee0701"),
new NewLabel("Build", "009800"),
new NewLabel("Documentation", "d4c5f9"),
new NewLabel("Feature", "84b6eb"),
new NewLabel("Improvement", "207de5"),
new NewLabel("Question", "cc317c"),
new NewLabel("good first issue", "7057ff"),
new NewLabel("help wanted", "33aa3f"),
};
var newLabels = new List<NewLabel>();

foreach (var label in _configuration.Labels)
{
newLabels.Add(new NewLabel(label.Name, label.Color)
{
Description = label.Description,
});
}

_logger.Verbose("Grabbing all existing labels on '{Owner}/{Repository}'", owner, repository);
var labels = await _gitHubClient.Issue.Labels.GetAllForRepository(owner, repository).ConfigureAwait(false);
_logger.Verbose("Grabbing all existing labels on '{Owner}/{Repository}'", owner, repository);
var labels = await _gitHubClient.Issue.Labels.GetAllForRepository(owner, repository).ConfigureAwait(false);

_logger.Verbose("Removing existing labels");
_logger.Debug("{@Labels}", labels);
var deleteLabelsTasks = labels.Select(label => _gitHubClient.Issue.Labels.Delete(owner, repository, label.Name));
await Task.WhenAll(deleteLabelsTasks).ConfigureAwait(false);
_logger.Verbose("Removing existing labels");
_logger.Debug("{@Labels}", labels);
var deleteLabelsTasks = labels.Select(label => _gitHubClient.Issue.Labels.Delete(owner, repository, label.Name));
await Task.WhenAll(deleteLabelsTasks).ConfigureAwait(false);

_logger.Verbose("Creating new standard labels");
_logger.Debug("{@Labels}", newLabels);
var createLabelsTasks = newLabels.Select(label => _gitHubClient.Issue.Labels.Create(owner, repository, label));
await Task.WhenAll(createLabelsTasks).ConfigureAwait(false);
_logger.Verbose("Creating new standard labels");
_logger.Debug("{@Labels}", newLabels);
var createLabelsTasks = newLabels.Select(label => _gitHubClient.Issue.Labels.Create(owner, repository, label));
await Task.WhenAll(createLabelsTasks).ConfigureAwait(false);
}
else
{
_logger.Warning("No labels defined");
}
}

private static NewRelease CreateNewRelease(string name, string tagName, string body, bool prerelease, string targetCommitish)
Expand Down
32 changes: 32 additions & 0 deletions docs/input/docs/configuration/default-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ close:
- [GitHub release](https://github.com/{owner}/{repository}/releases/tag/{milestone})
Your **[GitReleaseManager](https://github.com/GitTools/GitReleaseManager)** bot :package::rocket:
labels:
- name: Breaking Change
description: Functionality breaking changes
color: b60205
- name: Bug
description: Something isn't working
color: ee0701
- name: Build
description: Build pipeline
color: 009800
- name: Documentation
description: Improvements or additions to documentation
color: d4c5f9
- name: Feature
description: Request for a new feature
color: 84b6eb
- name: Good First Issue
description: Good for newcomers
color: 7057ff
- name: Help Wanted
description: Extra attention is needed
color: 33aa3f
- name: Improvement
description: Improvement of an existing feature
color: 207de5
- name: Question
description: Further information is requested
color: cc317c
issue-labels-include:
- Bug
- Duplicate
Expand Down Expand Up @@ -154,6 +182,10 @@ tokenized values, such as milestone, owner, repository, with the actual values.
this comment template, it is possible to replace information for example,
the milestone name, the owner/repository information, etc.

## Labels

Pre-defined issue labels.

## Issues to include

See the [Issues to include](include-issues) section.
Expand Down

0 comments on commit 1deaf3c

Please sign in to comment.