Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Commit 26c5afc

Browse files
author
Jake Ginnivan
committed
Keep spacing/additional lines when reading old release notes
1 parent 09e5b99 commit 26c5afc

13 files changed

Lines changed: 230 additions & 85 deletions

src/GitReleaseNotes.Tests/IssueTrackers/Jira/JiraIssueTrackerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public JiraIssueTrackerTests()
4242
// JiraProjectId = "JIRA"
4343
// }, toScan);
4444

45-
// Assert.Equal("Issue Title", releaseNotes.Releases[0].ReleaseNoteItems[0].Title);
45+
// Assert.Equal("Issue Title", releaseNotes.Releases[0].ReleaseNoteLines[0].Title);
4646
//}
4747

4848
private static Commit CreateCommit(string message, DateTimeOffset when)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# 0.2.0 (05 January 2012)
2+
3+
**Note this release does some stuff!**
4+
5+
6+
- [2] - Edited Issue3
7+
8+
Another comment
9+
10+
Commits: AC39885536...CA74E870F2
11+
12+
13+
# 0.1.0 (03 January 2012)
14+
15+
## Features
16+
- [0] - Edited Issue1
17+
- [1] - Edited Issue2
18+
- [2] - Edited Issue3
19+
20+
## Fixes
21+
- [3] - Edited Issue4
22+
- [4] - Edited Issue5
23+
24+
This is a comment about the release
25+
26+
Which spans multiple lines
27+
28+
Commits: E413A880DB...F6924D7A0B

src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,63 @@ public void AppendOnlyNewItems()
8282
- [0] - Edited Issue1
8383
- [1] - Edited Issue2
8484
85+
Commits: E413A880DB...F6924D7A0B");
86+
87+
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
88+
repo, issueTracker, previousReleaseNotes, new string[0],
89+
tagToStartFrom, currentReleaseInfo);
90+
91+
Approvals.Verify(releaseNotes.ToString());
92+
}
93+
94+
[Fact]
95+
public void KeepsCustomisations()
96+
{
97+
98+
IRepository repo;
99+
IIssueTracker issueTracker;
100+
new TestDataCreator(new DateTimeOffset(2012, 1, 1, 0, 0, 0, new TimeSpan()))
101+
.CreateRelease("0.1.0", "Issue1", "Issue2")
102+
.CreateRelease("0.2.0", "Issue3")
103+
.Build(out repo, out issueTracker);
104+
105+
var tagToStartFrom = GitRepositoryInfoFinder.GetFirstCommit(repo);
106+
var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(repo);
107+
108+
var previousReleaseNotes = SemanticReleaseNotes.Parse(@"# vNext
109+
110+
111+
Commits: ...
112+
113+
114+
# 0.2.0 (05 January 2012)
115+
116+
**Note this release does some stuff!**
117+
118+
119+
- [2] - Edited Issue3
120+
121+
Another comment
122+
123+
Commits: AC39885536...CA74E870F2
124+
125+
126+
# 0.1.0 (03 January 2012)
127+
128+
## Features
129+
- [0] - Edited Issue1
130+
- [1] - Edited Issue2
131+
- [2] - Edited Issue3
132+
133+
## Fixes
134+
- [3] - Edited Issue4
135+
- [4] - Edited Issue5
136+
137+
This is a comment about the release
138+
139+
Which spans multiple lines
140+
141+
85142
Commits: E413A880DB...F6924D7A0B");
86143

87144
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(

src/GitReleaseNotes.Tests/SemanticReleaseNotesTests.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void ApproveSimpleTests()
1313
{
1414
var releaseNotes = new SemanticReleaseNotes(new[]
1515
{
16-
new SemanticRelease("", null, new List<ReleaseNoteItem>
16+
new SemanticRelease("", null, new List<IReleaseNoteLine>
1717
{
1818
new ReleaseNoteItem("Issue 1", "#1", new Uri("http://github.com/org/repo/issues/1"), new string[0], DateTime.Now, new[]{ new Contributor("Foo Bar", "@foo", "http://url.com/foo") }),
1919
new ReleaseNoteItem("Issue 1", null, null, new string[0], DateTime.Now, new Contributor[0])
@@ -34,7 +34,7 @@ public void ItemIsCategorised()
3434
{
3535
var releaseNotes = new SemanticReleaseNotes(new[]
3636
{
37-
new SemanticRelease("", null, new List<ReleaseNoteItem>
37+
new SemanticRelease("", null, new List<IReleaseNoteLine>
3838
{
3939
new ReleaseNoteItem("Issue 1", "#1", new Uri("http://github.com/org/repo/issues/1"),
4040
new[] {"feature"}, DateTimeOffset.Now, new Contributor[0])
@@ -55,7 +55,7 @@ public void MultipleReleases()
5555
{
5656
var releaseNotes = new SemanticReleaseNotes(new[]
5757
{
58-
new SemanticRelease("", null, new List<ReleaseNoteItem>
58+
new SemanticRelease("", null, new List<IReleaseNoteLine>
5959
{
6060
new ReleaseNoteItem("Issue 1", "#1", new Uri("http://github.com/org/repo/issues/1"),
6161
new[] {"feature"}, DateTimeOffset.Now, new Contributor[0])
@@ -64,7 +64,7 @@ public void MultipleReleases()
6464
BeginningSha = "12345678",
6565
EndSha = "67890123"
6666
}),
67-
new SemanticRelease("1.2.0", new DateTimeOffset(2013, 12, 06, 0,0,0, new TimeSpan()), new List<ReleaseNoteItem>
67+
new SemanticRelease("1.2.0", new DateTimeOffset(2013, 12, 06, 0,0,0, new TimeSpan()), new List<IReleaseNoteLine>
6868
{
6969
new ReleaseNoteItem("Issue 2", "#2", new Uri("http://github.com/org/repo/issues/2"),
7070
new[] {"feature"}, DateTimeOffset.Now, new Contributor[0]),
@@ -87,7 +87,7 @@ public void LabelOfBugIsCategorisedAsFix()
8787
{
8888
var releaseNotes = new SemanticReleaseNotes(new[]
8989
{
90-
new SemanticRelease("", null, new List<ReleaseNoteItem>
90+
new SemanticRelease("", null, new List<IReleaseNoteLine>
9191
{
9292
new ReleaseNoteItem("Issue 1", "#1", new Uri("http://github.com/org/repo/issues/1"), new[] {"bug"}, DateTimeOffset.Now, new Contributor[0])
9393
}, new ReleaseDiffInfo
@@ -107,7 +107,7 @@ public void AdditionalCategoriesCanBeSpecifiedOnCommandLine()
107107
{
108108
var releaseNotes = new SemanticReleaseNotes(new[]
109109
{
110-
new SemanticRelease("", null, new List<ReleaseNoteItem>
110+
new SemanticRelease("", null, new List<IReleaseNoteLine>
111111
{
112112
new ReleaseNoteItem("Issue 1", "#1", new Uri("http://github.com/org/repo/issues/1"),
113113
new[] {"internal refactoring"}, DateTimeOffset.Now, new Contributor[0])
@@ -137,7 +137,7 @@ public void CanReadBasicReleaseNotes()
137137
readReleaseNotes.Releases[0].DiffInfo.BeginningSha.ShouldBe("1234567");
138138
readReleaseNotes.Releases[0].DiffInfo.EndSha.ShouldBe("6789012");
139139
readReleaseNotes.Releases[0].ReleaseName.ShouldBe(null);
140-
readReleaseNotes.Releases[0].ReleaseNoteItems.Count.ShouldBe(1);
140+
readReleaseNotes.Releases[0].ReleaseNoteLines.Count.ShouldBe(1);
141141
readReleaseNotes.Releases[0].ReleaseNoteItems[0].Title.ShouldBe("Issue 1 [#1](http://github.com/org/repo/issues/1)");
142142
}
143143

@@ -157,9 +157,10 @@ public void CanReadReleaseNotesWithComments()
157157
readReleaseNotes.Releases[0].DiffInfo.BeginningSha.ShouldBe("1234567");
158158
readReleaseNotes.Releases[0].DiffInfo.EndSha.ShouldBe("6789012");
159159
readReleaseNotes.Releases[0].ReleaseName.ShouldBe(null);
160-
readReleaseNotes.Releases[0].ReleaseNoteItems.Count.ShouldBe(2);
161-
readReleaseNotes.Releases[0].ReleaseNoteItems[0].Title.ShouldBe("Issue 1 [#1](http://github.com/org/repo/issues/1)");
162-
readReleaseNotes.Releases[0].ReleaseNoteItems[1].Title.ShouldBe("Note: Some shiz..");
160+
readReleaseNotes.Releases[0].ReleaseNoteLines.Count.ShouldBe(3);
161+
readReleaseNotes.Releases[0].ReleaseNoteLines[0].ToString(new string[0]).ShouldBe(" - Issue 1 [#1](http://github.com/org/repo/issues/1)");
162+
readReleaseNotes.Releases[0].ReleaseNoteLines[1].ToString(new string[0]).ShouldBe(string.Empty);
163+
readReleaseNotes.Releases[0].ReleaseNoteLines[2].ToString(new string[0]).ShouldBe("Note: Some shiz..");
163164
}
164165

165166
[Fact]
@@ -176,7 +177,7 @@ public void CanReadCategorisedIssuesReleaseNotes()
176177
readReleaseNotes.Releases[0].DiffInfo.BeginningSha.ShouldBe("12345678");
177178
readReleaseNotes.Releases[0].DiffInfo.EndSha.ShouldBe("67890123");
178179
readReleaseNotes.Releases[0].ReleaseName.ShouldBe(null);
179-
readReleaseNotes.Releases[0].ReleaseNoteItems.Count.ShouldBe(1);
180+
readReleaseNotes.Releases[0].ReleaseNoteItems.Length.ShouldBe(1);
180181
readReleaseNotes.Releases[0].ReleaseNoteItems[0].Title.ShouldBe("Issue 1 [#1](http://github.com/org/repo/issues/1) +feature +new");
181182
}
182183

@@ -204,13 +205,13 @@ public void CanReadReleaseNotesContainingMultipleReleases()
204205
readReleaseNotes.Releases[0].DiffInfo.EndSha.ShouldBe("67890123");
205206
readReleaseNotes.Releases[0].ReleaseName.ShouldBe(null);
206207
readReleaseNotes.Releases[0].When.ShouldBe(null);
207-
readReleaseNotes.Releases[0].ReleaseNoteItems.Count.ShouldBe(1);
208+
readReleaseNotes.Releases[0].ReleaseNoteLines.Count.ShouldBe(1);
208209
readReleaseNotes.Releases[0].ReleaseNoteItems[0].Title.ShouldBe("Issue 1 [#1](http://github.com/org/repo/issues/1) +feature +new");
209210
readReleaseNotes.Releases[1].DiffInfo.BeginningSha.ShouldBe("asdsadaf");
210211
readReleaseNotes.Releases[1].DiffInfo.EndSha.ShouldBe("bfdsadre");
211212
readReleaseNotes.Releases[1].ReleaseName.ShouldBe("1.2.0");
212213
readReleaseNotes.Releases[1].When.ShouldBe(new DateTimeOffset(new DateTime(2013, 12, 6)));
213-
readReleaseNotes.Releases[1].ReleaseNoteItems.Count.ShouldBe(2);
214+
readReleaseNotes.Releases[1].ReleaseNoteLines.Count.ShouldBe(2);
214215
readReleaseNotes.Releases[1].ReleaseNoteItems[0].Title.ShouldBe("Issue 2 [#2](http://github.com/org/repo/issues/2) +feature");
215216
readReleaseNotes.Releases[1].ReleaseNoteItems[1].Title.ShouldBe("Issue 3 [#3](http://github.com/org/repo/issues/3) +fix");
216217
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>

src/GitReleaseNotes/BlankLine.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace GitReleaseNotes
2+
{
3+
public class BlankLine : IReleaseNoteLine
4+
{
5+
public string ToString(string[] categories)
6+
{
7+
return string.Empty;
8+
}
9+
}
10+
}

src/GitReleaseNotes/GitReleaseNotes.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
</ItemGroup>
6060
<ItemGroup>
6161
<Compile Include="ArgumentVerifier.cs" />
62+
<Compile Include="BlankLine.cs" />
6263
<Compile Include="Contributor.cs" />
64+
<Compile Include="IReleaseNoteLine.cs" />
6365
<Compile Include="ReleaseFinder.cs" />
6466
<Compile Include="FileSystem\FileSystem.cs" />
6567
<Compile Include="FileSystem\IFileSystem.cs" />
@@ -90,6 +92,7 @@
9092
<Compile Include="FileSystem\ReleaseFileWriter.cs" />
9193
<Compile Include="ReleaseInfo.cs" />
9294
<Compile Include="FileSystem\ReleaseNotesFileReader.cs" />
95+
<Compile Include="ReleaseNoteLine.cs" />
9396
<Compile Include="ReleaseNotesGenerator.cs" />
9497
<Compile Include="SemanticRelease.cs" />
9598
<Compile Include="SemanticReleaseNotes.cs" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace GitReleaseNotes
2+
{
3+
public interface IReleaseNoteLine
4+
{
5+
string ToString(string[] categories);
6+
}
7+
}
Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,70 @@
11
using System;
2+
using System.Linq;
23

34
namespace GitReleaseNotes
45
{
5-
public class ReleaseNoteItem
6+
public class ReleaseNoteItem : IReleaseNoteLine
67
{
7-
private readonly string _title;
8-
private readonly string _issueNumber;
9-
private readonly Uri _htmlUrl;
10-
private readonly string[] _tags;
11-
private readonly DateTimeOffset? _resolvedOn;
12-
private Contributor[] _contributors;
8+
private readonly string title;
9+
private readonly string issueNumber;
10+
private readonly Uri htmlUrl;
11+
private readonly string[] tags;
12+
private readonly DateTimeOffset? resolvedOn;
13+
private readonly Contributor[] contributors;
1314

1415
public ReleaseNoteItem(string title, string issueNumber, Uri htmlUrl, string[] tags, DateTimeOffset? resolvedOn, Contributor[] contributors)
1516
{
16-
_title = title;
17-
_issueNumber = issueNumber;
18-
_htmlUrl = htmlUrl;
19-
_tags = tags ?? new string[0];
20-
_resolvedOn = resolvedOn;
21-
_contributors = contributors;
17+
this.title = title;
18+
this.issueNumber = issueNumber;
19+
this.htmlUrl = htmlUrl;
20+
this.tags = tags ?? new string[0];
21+
this.resolvedOn = resolvedOn;
22+
this.contributors = contributors;
2223
}
2324

2425
public string Title
2526
{
26-
get { return _title; }
27+
get { return title; }
2728
}
2829

2930
public Uri HtmlUrl
3031
{
31-
get { return _htmlUrl; }
32+
get { return htmlUrl; }
3233
}
3334

3435
public string[] Tags
3536
{
36-
get { return _tags; }
37+
get { return tags; }
3738
}
3839

3940
public string IssueNumber
4041
{
41-
get { return _issueNumber; }
42+
get { return issueNumber; }
4243
}
4344

4445
public DateTimeOffset? ResolvedOn
4546
{
46-
get { return _resolvedOn; }
47+
get { return resolvedOn; }
4748
}
4849

49-
public Contributor[] Contributors { get { return _contributors; }}
50+
public Contributor[] Contributors { get { return contributors; }}
51+
52+
public string ToString(string[] categories)
53+
{
54+
var taggedCategory = Tags.FirstOrDefault(t => categories.Any(c => c.Equals(t, StringComparison.InvariantCultureIgnoreCase)));
55+
if ("bug".Equals(taggedCategory, StringComparison.InvariantCultureIgnoreCase))
56+
taggedCategory = "fix";
57+
var category = taggedCategory == null
58+
? null
59+
: String.Format(" +{0}", taggedCategory.Replace(" ", "-"));
60+
var issueNum = IssueNumber == null ? null : String.Format(" [{0}]", IssueNumber);
61+
var url = HtmlUrl == null ? null : String.Format("({0})", HtmlUrl);
62+
var contributors = Contributors == null || Contributors.Length == 0 ?
63+
string.Empty : " contributed by " + String.Join(", ", Contributors.Select(r => String.Format("{0} ([{1}]({2}))", r.Name, r.Username, r.Url)));
64+
65+
return string.Format(" - {1}{2}{4}{0}{5}{3}", Title, issueNum, url, category,
66+
Title.TrimStart().StartsWith("-") ? null : " - ",
67+
contributors).Replace(" ", " ").Replace("- -", "-");
68+
}
5069
}
5170
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace GitReleaseNotes
2+
{
3+
public class ReleaseNoteLine : IReleaseNoteLine
4+
{
5+
private readonly string line;
6+
7+
public ReleaseNoteLine(string line)
8+
{
9+
this.line = line;
10+
}
11+
12+
public string ToString(string[] categories)
13+
{
14+
return line;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)