Skip to content
This repository was archived by the owner on Aug 29, 2020. It is now read-only.

Commit 51abaa9

Browse files
committed
Merge pull request #27 from adamralph/26-prefixed-labels
#26 prefixed labels
2 parents 6a697ad + 7af6418 commit 51abaa9

6 files changed

+33
-39
lines changed

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
ReleaseNotesCompiler
1+
GitHubReleaseNotes
22
====================
33

4-
In order to improve the quality for our release notes we'll generate them based on the relevant github issues.
4+
Generates release notes for a milestone in a GitHub repo based on issues associated with the milestone.
55

66
### Conventions
77

8-
* All closed issues for a milestone will be included
9-
* All issues must have one of the following tags `Bug`, `Feature`, `Internal refactoring`, `Improvement`. Where `Internal refactoring` will be included in a milestone but excluded from the release notes.
10-
* For now the text is taken from the name of the issue
11-
* Milestones are named {major.minor.patch}
12-
* Version is picked up from the build number (GFV) and that info is used to find the milestone
13-
* We'll generate release notes as markdown for display on the website
14-
* by default only the first 30 line of an issue description is included in the release noted. If you want to control exactly how many lines are included then use a `--` to add a horizontal rule. Then only the contents above that horizontal rule will be included.
8+
* All closed issues for a milestone will be included.
9+
* All issues must have exactly one `Type: xxx` label. E.g. `Type: Bug`, `Type: Feature`, `Type: Refactoring`, etc. Only issues labelled `Type: Bug` and `Type: Feature `will be included in the release notes. Issues with other `Type: xxx` labels will be included in the milestone but excluded from the release notes.
10+
* Milestones are named `{major.minor.patch}`.
11+
* The version is picked up from the build number (GFV) and that info is used to find the milestone.
12+
* Release notes are generated as markdown.
1513

1614
### Plans
1715

@@ -21,5 +19,3 @@ In order to improve the quality for our release notes we'll generate them based
2119
* Want to be able to output in a manner compatible with http://www.semanticreleasenotes.org/
2220
* We'll generate release notes as X for inclusion in our nugets
2321
* For each milestone a corresponding GitHub release will be created with the same name and set to tag master with the same tag when published
24-
25-

src/Compiler/ReleaseNotesBuilder.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.IO;
35
using System.Linq;
46
using System.Text;
57
using System.Threading.Tasks;
68
using Octokit;
79

810
namespace ReleaseNotesCompiler
911
{
10-
using System.IO;
11-
1212
public class ReleaseNotesBuilder
1313
{
1414
IGitHubClient gitHubClient;
@@ -26,6 +26,11 @@ public ReleaseNotesBuilder(IGitHubClient gitHubClient, string user, string repos
2626
this.milestoneTitle = milestoneTitle;
2727
}
2828

29+
public static string LabelPrefix
30+
{
31+
get { return "Type: "; }
32+
}
33+
2934
public async Task<string> BuildReleaseNotes()
3035
{
3136
LoadMilestones();
@@ -92,7 +97,6 @@ string GetCommitsLink(Milestone previousMilestone)
9297
void AddIssues(StringBuilder stringBuilder, List<Issue> issues)
9398
{
9499
Append(issues, "Feature", stringBuilder);
95-
Append(issues, "Improvement", stringBuilder);
96100
Append(issues, "Bug", stringBuilder);
97101
}
98102

@@ -135,31 +139,34 @@ async Task<List<Issue>> GetIssues(Milestone milestone)
135139

136140
static void CheckForValidLabels(Issue issue)
137141
{
138-
var count = issue.Labels.Count(l =>
139-
l.Name == "Bug" ||
140-
l.Name == "Internal refactoring" ||
141-
l.Name == "Feature" ||
142-
l.Name == "Improvement");
143-
if (count != 1)
142+
if (issue.Labels.Count(label => label.Name.StartsWith(LabelPrefix)) != 1)
144143
{
145-
var message = string.Format("Bad Issue {0} expected to find a single label with either 'Bug', 'Internal refactoring', 'Improvement' or 'Feature'.", issue.HtmlUrl);
146-
throw new Exception(message);
144+
var message = string.Format(
145+
CultureInfo.CurrentCulture,
146+
"Bad issue {0}. Expected to find a single label starting with '{1}'.",
147+
issue.HtmlUrl,
148+
LabelPrefix);
149+
150+
throw new InvalidOperationException(message);
147151
}
148152
}
149153

150-
void Append(IEnumerable<Issue> issues, string label, StringBuilder stringBuilder)
154+
void Append(IEnumerable<Issue> issues, string labelName, StringBuilder builder)
151155
{
152-
var features = issues.Where(x => x.Labels.Any(l => l.Name == label))
156+
var relevantIssues = issues
157+
.Where(issue => issue.Labels.Any(label => label.Name == LabelPrefix + labelName))
153158
.ToList();
154-
if (features.Count > 0)
159+
160+
if (relevantIssues.Any())
155161
{
156-
stringBuilder.AppendFormat(features.Count == 1 ? "__{0}__\r\n" : "__{0}s__\r\n", label);
162+
builder.AppendFormat(relevantIssues.Count == 1 ? "__{0}__\r\n" : "__{0}s__\r\n", labelName);
157163

158-
foreach (var issue in features)
164+
foreach (var issue in relevantIssues)
159165
{
160-
stringBuilder.AppendFormat("- [__#{0}__]({1}) {2}\r\n", issue.Number, issue.HtmlUrl, issue.Title);
166+
builder.AppendFormat("- [__#{0}__]({1}) {2}\r\n", issue.Number, issue.HtmlUrl, issue.Title);
161167
}
162-
stringBuilder.AppendLine();
168+
169+
builder.AppendLine();
163170
}
164171
}
165172

src/Tests/ReleaseNotesBuilderTests.NoCommitsSomeIssues.approved.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
__Feature__
55
- [__#2__](http://example.com/2) Issue 2
66

7-
__Improvement__
8-
- [__#3__](http://example.com/3) Issue 3
9-
107
__Bug__
118
- [__#1__](http://example.com/1) Issue 1
129

src/Tests/ReleaseNotesBuilderTests.SingularCommitsSomeIssues.approved.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
__Feature__
55
- [__#2__](http://example.com/2) Issue 2
66

7-
__Improvement__
8-
- [__#3__](http://example.com/3) Issue 3
9-
107
__Bug__
118
- [__#1__](http://example.com/1) Issue 1
129

src/Tests/ReleaseNotesBuilderTests.SomeCommitsSomeIssues.approved.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
__Feature__
55
- [__#2__](http://example.com/2) Issue 2
66

7-
__Improvement__
8-
- [__#3__](http://example.com/3) Issue 3
9-
107
__Bug__
118
- [__#1__](http://example.com/1) Issue 1
129

src/Tests/ReleaseNotesBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static Issue CreateIssue(int number, params string[] labels)
100100
Title = "Issue " + number,
101101
HtmlUrl = new Uri("http://example.com/" + number),
102102
Body = "Some issue",
103-
Labels = labels.Select(x => new Label { Name = x }).ToArray(),
103+
Labels = labels.Select(x => new Label { Name = ReleaseNotesBuilder.LabelPrefix + x }).ToArray(),
104104
};
105105
}
106106
}

0 commit comments

Comments
 (0)