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

Commit d03be70

Browse files
committed
Merge pull request #11 from JakeGinnivan/Publish
Publish
2 parents 8ffca6d + 096412e commit d03be70

23 files changed

Lines changed: 283 additions & 112 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#*.jpg binary
4444
#*.png binary
4545
#*.gif binary
46+
*.approved.txt binary
4647

4748
###############################################################################
4849
# diff behavior for common document formats

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ UpgradeLog*.XML
109109
build/
110110
src/GitReleaseNotes.sln.ide/graph
111111
*.orig
112+
src/_NCrunch_GitReleaseNotes

src/GitReleaseNotes.Tests/GitReleaseNotes.Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@
5959
<Reference Include="xunit">
6060
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
6161
</Reference>
62+
<Reference Include="xunit.extensions">
63+
<HintPath>..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll</HintPath>
64+
</Reference>
6265
</ItemGroup>
6366
<ItemGroup>
6467
<Compile Include="ArgumentTests.cs" />
6568
<Compile Include="CommitGrouperTests.cs" />
6669
<Compile Include="IssueTrackers\GitHub\GitHubIssueTrackerTests.cs" />
6770
<Compile Include="IssueTrackers\IssueNumberExtractor.cs" />
6871
<Compile Include="Properties\AssemblyInfo.cs" />
69-
<Compile Include="ReleaseNotesWriterTests.cs" />
72+
<Compile Include="ReleaseFileWriterTests.cs" />
73+
<Compile Include="ReleaseNotesGeneratorTests.cs" />
7074
</ItemGroup>
7175
<ItemGroup>
7276
<None Include="packages.config" />

src/GitReleaseNotes.Tests/IssueTrackers/GitHub/GitHubIssueTrackerTests.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NSubstitute;
88
using Octokit;
99
using Xunit;
10+
using Xunit.Extensions;
1011

1112
namespace GitReleaseNotes.Tests.IssueTrackers.GitHub
1213
{
@@ -16,11 +17,13 @@ public class GitHubIssueTrackerTests
1617
private readonly GitHubIssueTracker _sut;
1718
private readonly GitReleaseNotesArguments _gitReleaseNotesArguments;
1819
private readonly IIssuesClient _issuesClient;
20+
private readonly ILog _log;
1921

2022
public GitHubIssueTrackerTests()
2123
{
24+
_log = Substitute.For<ILog>();
2225
_gitHubClient = Substitute.For<IGitHubClient>();
23-
_sut = new GitHubIssueTracker(new IssueNumberExtractor(), _gitHubClient);
26+
_sut = new GitHubIssueTracker(new IssueNumberExtractor(), () => _gitHubClient, _log);
2427
_gitReleaseNotesArguments = new GitReleaseNotesArguments
2528
{
2629
Repo = "Org/Repo",
@@ -55,6 +58,64 @@ public void CreatesReleaseNotesForClosedGitHubIssues()
5558
Assert.Equal("Issue Title", releaseNotes.Releases[0].ReleaseNoteItems[0].Title);
5659
}
5760

61+
[Fact]
62+
public void ErrorLoggedWhenRepoIsNotSpecified()
63+
{
64+
var result = _sut.VerifyArgumentsAndWriteErrorsToConsole(new GitReleaseNotesArguments());
65+
66+
Assert.False(result);
67+
_log.Received().WriteLine("GitHub repository name must be specified [/Repo .../...]");
68+
}
69+
70+
[Theory]
71+
[InlineData("Foo", false)]
72+
[InlineData("Org/Repo", true)]
73+
[InlineData("Org/Repo/SomethingElse", false)]
74+
public void RepositoryMustBeInCorrectFormat(string repo, bool success)
75+
{
76+
var result = _sut.VerifyArgumentsAndWriteErrorsToConsole(new GitReleaseNotesArguments
77+
{
78+
Repo = repo,
79+
Token = "Foo"
80+
});
81+
82+
if (success)
83+
{
84+
Assert.True(result);
85+
}
86+
else
87+
{
88+
Assert.False(result);
89+
_log.Received().WriteLine("GitHub repository name should be in format Organisation/RepoName");
90+
}
91+
}
92+
93+
[Fact]
94+
public void MustSpecifyToken()
95+
{
96+
var result = _sut.VerifyArgumentsAndWriteErrorsToConsole(new GitReleaseNotesArguments
97+
{
98+
Repo = "Foo/Bar"
99+
});
100+
101+
Assert.False(result);
102+
_log.Received().WriteLine("You must specify a GitHub Authentication token with the /Token argument");
103+
}
104+
105+
[Fact]
106+
public void MustSpecifyVersionWhenPublishFlagIsSet()
107+
{
108+
var result = _sut.VerifyArgumentsAndWriteErrorsToConsole(new GitReleaseNotesArguments
109+
{
110+
Repo = "Foo/Bar",
111+
Token = "Baz",
112+
Publish = true
113+
});
114+
115+
Assert.False(result);
116+
_log.Received().WriteLine("You must specifiy the version [/Version ...] (will be tag) when using the /Publish flag");
117+
}
118+
58119
private static Commit CreateCommit(string message, DateTimeOffset when)
59120
{
60121
var commit = Substitute.For<Commit>();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.IO;
2+
using System.Linq;
3+
using NSubstitute;
4+
using Xunit;
5+
6+
namespace GitReleaseNotes.Tests
7+
{
8+
public class ReleaseFileWriterTests
9+
{
10+
private readonly IFileSystem _fileSystem;
11+
private const string RepositoryRoot = "c:\\Repo";
12+
private readonly ReleaseFileWriter _sut;
13+
14+
public ReleaseFileWriterTests()
15+
{
16+
_fileSystem = Substitute.For<IFileSystem>();
17+
_sut = new ReleaseFileWriter(_fileSystem, RepositoryRoot);
18+
}
19+
20+
[Fact]
21+
public void RelativePathIsWrittenToRepositoryRoot()
22+
{
23+
var arguments = new GitReleaseNotesArguments
24+
{
25+
Categories = "internal refactoring",
26+
OutputFile = "ReleaseFile.md"
27+
};
28+
29+
_sut.OutputReleaseNotesFile(RepositoryRoot, arguments);
30+
31+
var fileName = _fileSystem.ReceivedCalls().Single(c => c.GetMethodInfo().Name == "WriteAllText").GetArguments()[0];
32+
Assert.Equal(Path.Combine(RepositoryRoot, "ReleaseFile.md"), fileName);
33+
}
34+
35+
[Fact]
36+
public void AbsolutePathIsWrittenToRepositoryRoot()
37+
{
38+
var arguments = new GitReleaseNotesArguments
39+
{
40+
Categories = "internal refactoring",
41+
OutputFile = "c:\\AnotherDir\\ReleaseFile.md"
42+
};
43+
44+
_sut.OutputReleaseNotesFile(RepositoryRoot, arguments);
45+
46+
var fileName = _fileSystem.ReceivedCalls().Single(c => c.GetMethodInfo().Name == "WriteAllText").GetArguments()[0];
47+
Assert.Equal("c:\\AnotherDir\\ReleaseFile.md", fileName);
48+
}
49+
}
50+
}

src/GitReleaseNotes.Tests/ReleaseNotesWriterTests.LabelOfBugIsCategorisedAsFix.approved.txt renamed to src/GitReleaseNotes.Tests/ReleaseNotesGenerator.LabelOfBugIsCategorisedAsFix.approved.txt

File renamed without changes.

src/GitReleaseNotes.Tests/ReleaseNotesWriterTests.AdditionalCategoriesCanBeSpecifiedOnCommandLine.approved.txt renamed to src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.AdditionalCategoriesCanBeSpecifiedOnCommandLine.approved.txt

File renamed without changes.

src/GitReleaseNotes.Tests/ReleaseNotesWriterTests.ApproveSimpleTests.approved.txt renamed to src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.ApproveSimpleTests.approved.txt

File renamed without changes.

src/GitReleaseNotes.Tests/ReleaseNotesWriterTests.ItemIsCategorised.approved.txt renamed to src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.ItemIsCategorised.approved.txt

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
 - Issue 1 [#1](http://github.com/org/repo/issues/1) +fix

0 commit comments

Comments
 (0)