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

Commit 93a9fff

Browse files
author
Jake Ginnivan
committed
Add url into commit range
1 parent 26c5afc commit 93a9fff

10 files changed

Lines changed: 94 additions & 64 deletions

src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.KeepsCustomisations.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Another comment
99

10-
Commits: AC39885536...CA74E870F2
10+
Commits: [AC39885536...CA74E870F2](url/AC39885536...CA74E870F2)
1111

1212

1313
# 0.1.0 (03 January 2012)
@@ -25,4 +25,4 @@ This is a comment about the release
2525

2626
Which spans multiple lines
2727

28-
Commits: E413A880DB...F6924D7A0B
28+
Commits: [E413A880DB...F6924D7A0B](url/E413A880DB...F6924D7A0B)

src/GitReleaseNotes.Tests/ReleaseNotesGeneratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void AllTagsWithNoCommitsOrIssuesAfterLastRelease()
2424

2525
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
2626
repo, issueTracker, new SemanticReleaseNotes(), new string[0],
27-
tagToStartFrom, currentReleaseInfo);
27+
tagToStartFrom, currentReleaseInfo, issueTracker.DiffUrlFormat);
2828

2929
Approvals.Verify(releaseNotes.ToString());
3030
}
@@ -45,7 +45,7 @@ public void AllTags()
4545

4646
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
4747
repo, issueTracker, new SemanticReleaseNotes(), new string[0],
48-
tagToStartFrom, currentReleaseInfo);
48+
tagToStartFrom, currentReleaseInfo, string.Empty);
4949

5050
Approvals.Verify(releaseNotes.ToString());
5151
}
@@ -86,7 +86,7 @@ public void AppendOnlyNewItems()
8686

8787
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
8888
repo, issueTracker, previousReleaseNotes, new string[0],
89-
tagToStartFrom, currentReleaseInfo);
89+
tagToStartFrom, currentReleaseInfo, string.Empty);
9090

9191
Approvals.Verify(releaseNotes.ToString());
9292
}
@@ -143,7 +143,7 @@ Which spans multiple lines
143143

144144
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
145145
repo, issueTracker, previousReleaseNotes, new string[0],
146-
tagToStartFrom, currentReleaseInfo);
146+
tagToStartFrom, currentReleaseInfo, "url/{0}...{1}");
147147

148148
Approvals.Verify(releaseNotes.ToString());
149149
}

src/GitReleaseNotes/IssueTrackers/GitHub/GitHubIssueTracker.cs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,60 @@ namespace GitReleaseNotes.IssueTrackers.GitHub
1010
{
1111
public class GitHubIssueTracker : IIssueTracker
1212
{
13-
private readonly Func<IGitHubClient> _gitHubClientFactory;
14-
private readonly GitReleaseNotesArguments _arguments;
15-
private readonly IRepository _repository;
16-
private readonly ILog _log;
13+
private readonly Func<IGitHubClient> gitHubClientFactory;
14+
private readonly GitReleaseNotesArguments arguments;
15+
private readonly IRepository gitRepository;
16+
private readonly ILog log;
1717

18-
public GitHubIssueTracker(IRepository repository, Func<IGitHubClient> gitHubClientFactory, ILog log, GitReleaseNotesArguments arguments)
18+
public GitHubIssueTracker(IRepository gitRepository, Func<IGitHubClient> gitHubClientFactory, ILog log, GitReleaseNotesArguments arguments)
1919
{
20-
_repository = repository;
21-
_log = log;
22-
_arguments = arguments;
23-
_gitHubClientFactory = gitHubClientFactory;
20+
this.gitRepository = gitRepository;
21+
this.log = log;
22+
this.arguments = arguments;
23+
this.gitHubClientFactory = gitHubClientFactory;
2424
}
2525

2626
public bool RemotePresentWhichMatches
2727
{
2828
get
2929
{
30-
return _repository.Network.Remotes.Any(r => r.Url.ToLower().Contains("github.com"));
30+
return gitRepository.Network.Remotes.Any(r => r.Url.ToLower().Contains("github.com"));
31+
}
32+
}
33+
34+
public string DiffUrlFormat
35+
{
36+
get
37+
{
38+
string organisation;
39+
string repository;
40+
GetRepository(arguments, out organisation, out repository);
41+
42+
return "https://github.com/" + organisation + "/" + repository + "/compare/{0}...{1}";
3143
}
3244
}
3345

3446
public bool VerifyArgumentsAndWriteErrorsToConsole()
3547
{
3648
if (!RemotePresentWhichMatches)
3749
{
38-
if (_arguments.Repo == null)
50+
if (arguments.Repo == null)
3951
{
40-
_log.WriteLine("GitHub repository name must be specified [/Repo .../...]");
52+
log.WriteLine("GitHub repository name must be specified [/Repo .../...]");
4153
return false;
4254
}
43-
var repoParts = _arguments.Repo.Split('/');
55+
var repoParts = arguments.Repo.Split('/');
4456

4557
if (repoParts.Length != 2)
4658
{
47-
_log.WriteLine("GitHub repository name should be in format Organisation/RepoName");
59+
log.WriteLine("GitHub repository name should be in format Organisation/RepoName");
4860
return false;
4961
}
5062
}
5163

52-
if (_arguments.Publish && string.IsNullOrEmpty(_arguments.Version))
64+
if (arguments.Publish && string.IsNullOrEmpty(arguments.Version))
5365
{
54-
_log.WriteLine("You must specifiy the version [/Version ...] (will be tag) when using the /Publish flag");
66+
log.WriteLine("You must specifiy the version [/Version ...] (will be tag) when using the /Publish flag");
5567
return false;
5668
}
5769

@@ -62,14 +74,14 @@ public void PublishRelease(string releaseNotesOutput)
6274
{
6375
string organisation;
6476
string repository;
65-
GetRepository(_arguments, out organisation, out repository);
77+
GetRepository(arguments, out organisation, out repository);
6678

67-
var releaseUpdate = new ReleaseUpdate(_arguments.Version)
79+
var releaseUpdate = new ReleaseUpdate(arguments.Version)
6880
{
69-
Name = _arguments.Version,
81+
Name = arguments.Version,
7082
Body = releaseNotesOutput
7183
};
72-
var release = _gitHubClientFactory().Release.CreateRelease(organisation, repository, releaseUpdate);
84+
var release = gitHubClientFactory().Release.CreateRelease(organisation, repository, releaseUpdate);
7385
release.Wait();
7486
}
7587

@@ -81,7 +93,7 @@ private void GetRepository(GitReleaseNotesArguments arguments, out string organi
8193
return;
8294
if (TryRemote(out organisation, out repository, "origin"))
8395
return;
84-
var remoteName = _repository.Network.Remotes.First(r => r.Url.ToLower().Contains("github.com")).Name;
96+
var remoteName = gitRepository.Network.Remotes.First(r => r.Url.ToLower().Contains("github.com")).Name;
8597
if (TryRemote(out organisation, out repository, remoteName))
8698
return;
8799
}
@@ -93,7 +105,7 @@ private void GetRepository(GitReleaseNotesArguments arguments, out string organi
93105

94106
private bool TryRemote(out string organisation, out string repository, string remoteName)
95107
{
96-
var remote = _repository.Network.Remotes[remoteName];
108+
var remote = gitRepository.Network.Remotes[remoteName];
97109
if (remote != null && remote.Url.ToLower().Contains("github.com"))
98110
{
99111
var urlWithoutGitExtension = remote.Url.EndsWith(".git") ? remote.Url.Substring(0, remote.Url.Length - 4) : remote.Url;
@@ -114,9 +126,9 @@ public IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since)
114126
{
115127
string organisation;
116128
string repository;
117-
GetRepository(_arguments, out organisation, out repository);
129+
GetRepository(arguments, out organisation, out repository);
118130

119-
var gitHubClient = _gitHubClientFactory();
131+
var gitHubClient = gitHubClientFactory();
120132
var forRepository = gitHubClient.Issue.GetForRepository(organisation, repository, new RepositoryIssueRequest
121133
{
122134
Filter = IssueFilter.All,
@@ -135,7 +147,7 @@ public IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since)
135147
}
136148

137149
var user = userCache[login];
138-
if (user != null)
150+
if (user != null)
139151
return user.Name;
140152
return null;
141153
};
@@ -147,7 +159,10 @@ public IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since)
147159
IssueType = i.PullRequest == null ? IssueType.Issue : IssueType.PullRequest,
148160
Labels = i.Labels.Select(l => l.Name).ToArray(),
149161
DateClosed = i.ClosedAt.Value,
150-
Contributors = i.PullRequest == null ? new Contributor[0] : new[] { new Contributor(getUserName(i.User), i.User.Login, i.User.HtmlUrl) }
162+
Contributors = i.PullRequest == null ? new Contributor[0] : new[]
163+
{
164+
new Contributor(getUserName(i.User), i.User.Login, i.User.HtmlUrl)
165+
}
151166
});
152167
}
153168
}

src/GitReleaseNotes/IssueTrackers/IIssueTracker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface IIssueTracker
99
void PublishRelease(string releaseNotesOutput);
1010
IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since);
1111
bool RemotePresentWhichMatches { get; }
12+
string DiffUrlFormat { get; }
1213
}
1314
}

src/GitReleaseNotes/IssueTrackers/Jira/JiraIssueTracker.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,46 @@ namespace GitReleaseNotes.IssueTrackers.Jira
66
{
77
public class JiraIssueTracker : IIssueTracker
88
{
9-
private readonly GitReleaseNotesArguments _arguments;
10-
private readonly IJiraApi _jiraApi;
9+
private readonly GitReleaseNotesArguments arguments;
10+
private readonly IJiraApi jiraApi;
1111

1212
public JiraIssueTracker(IJiraApi jiraApi, GitReleaseNotesArguments arguments)
1313
{
14-
_jiraApi = jiraApi;
15-
_arguments = arguments;
14+
this.jiraApi = jiraApi;
15+
this.arguments = arguments;
1616
}
1717

1818
public bool VerifyArgumentsAndWriteErrorsToConsole()
1919
{
20-
if (string.IsNullOrEmpty(_arguments.JiraServer) ||
21-
!Uri.IsWellFormedUriString(_arguments.JiraServer, UriKind.Absolute))
20+
if (string.IsNullOrEmpty(arguments.JiraServer) ||
21+
!Uri.IsWellFormedUriString(arguments.JiraServer, UriKind.Absolute))
2222
{
2323
Console.WriteLine("A valid Jira server must be specified [/JiraServer ]");
2424
return false;
2525
}
2626

27-
if (string.IsNullOrEmpty(_arguments.ProjectId))
27+
if (string.IsNullOrEmpty(arguments.ProjectId))
2828
{
2929
Console.WriteLine("/JiraProjectId is a required parameter for Jira");
3030
return false;
3131
}
3232

33-
if (string.IsNullOrEmpty(_arguments.Username))
33+
if (string.IsNullOrEmpty(arguments.Username))
3434
{
3535
Console.WriteLine("/Username is a required to authenticate with Jira");
3636
return false;
3737
}
38-
if (string.IsNullOrEmpty(_arguments.Password))
38+
if (string.IsNullOrEmpty(arguments.Password))
3939
{
4040
Console.WriteLine("/Password is a required to authenticate with Jira");
4141
return false;
4242
}
4343

44-
if (string.IsNullOrEmpty(_arguments.Jql))
44+
if (string.IsNullOrEmpty(arguments.Jql))
4545
{
46-
_arguments.Jql = string.Format("project = {0} AND " +
46+
arguments.Jql = string.Format("project = {0} AND " +
4747
"(issuetype = Bug OR issuetype = Story OR issuetype = \"New Feature\") AND " +
48-
"status in (Closed, Done, Resolved)", _arguments.ProjectId);
48+
"status in (Closed, Done, Resolved)", arguments.ProjectId);
4949
}
5050

5151
return true;
@@ -58,9 +58,10 @@ public void PublishRelease(string releaseNotesOutput)
5858

5959
public IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since)
6060
{
61-
return _jiraApi.GetClosedIssues(_arguments, since).ToArray();
61+
return jiraApi.GetClosedIssues(arguments, since).ToArray();
6262
}
6363

6464
public bool RemotePresentWhichMatches { get { return false; }}
65+
public string DiffUrlFormat { get { return string.Empty; } }
6566
}
6667
}

src/GitReleaseNotes/IssueTrackers/YouTrack/YouTrackIssueTracker.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,46 @@ namespace GitReleaseNotes.IssueTrackers.YouTrack
66
{
77
public sealed class YouTrackIssueTracker : IIssueTracker
88
{
9-
private readonly GitReleaseNotesArguments _arguments;
10-
private readonly IYouTrackApi _youTrackApi;
9+
private readonly GitReleaseNotesArguments arguments;
10+
private readonly IYouTrackApi youTrackApi;
1111

1212
public YouTrackIssueTracker(IYouTrackApi youTrackApi, GitReleaseNotesArguments arguments)
1313
{
14-
_youTrackApi = youTrackApi;
15-
_arguments = arguments;
14+
this.youTrackApi = youTrackApi;
15+
this.arguments = arguments;
1616
}
1717

1818
public bool VerifyArgumentsAndWriteErrorsToConsole()
1919
{
20-
if (string.IsNullOrEmpty(_arguments.YouTrackServer) ||
21-
!Uri.IsWellFormedUriString(_arguments.YouTrackServer, UriKind.Absolute))
20+
if (string.IsNullOrEmpty(arguments.YouTrackServer) ||
21+
!Uri.IsWellFormedUriString(arguments.YouTrackServer, UriKind.Absolute))
2222
{
2323
Console.WriteLine("A valid YouTrack server must be specified [/YouTrackServer ]");
2424
return false;
2525
}
2626

27-
if (string.IsNullOrEmpty(_arguments.ProjectId))
27+
if (string.IsNullOrEmpty(arguments.ProjectId))
2828
{
2929
Console.WriteLine("/ProjectId is a required parameter for YouTrack");
3030
return false;
3131
}
3232

33-
if (string.IsNullOrEmpty(_arguments.Username))
33+
if (string.IsNullOrEmpty(arguments.Username))
3434
{
3535
Console.WriteLine("/Username is a required to authenticate with YouTrack");
3636
return false;
3737
}
38-
if (string.IsNullOrEmpty(_arguments.Password))
38+
if (string.IsNullOrEmpty(arguments.Password))
3939
{
4040
Console.WriteLine("/Password is a required to authenticate with YouTrack");
4141
return false;
4242
}
4343

44-
if (string.IsNullOrEmpty(_arguments.YouTrackFilter))
44+
if (string.IsNullOrEmpty(arguments.YouTrackFilter))
4545
{
46-
_arguments.YouTrackFilter = string.Format(
46+
arguments.YouTrackFilter = string.Format(
4747
"project:{0} State:Resolved State:-{{Won't fix}} State:-{{Can't Reproduce}} State:-Duplicate",
48-
_arguments.ProjectId);
48+
arguments.ProjectId);
4949
}
5050

5151
return true;
@@ -58,7 +58,7 @@ public void PublishRelease(string releaseNotesOutput)
5858

5959
public IEnumerable<OnlineIssue> GetClosedIssues(DateTimeOffset? since)
6060
{
61-
return _youTrackApi.GetClosedIssues(_arguments, since).ToArray();
61+
return youTrackApi.GetClosedIssues(arguments, since).ToArray();
6262
}
6363

6464
public bool RemotePresentWhichMatches
@@ -68,5 +68,7 @@ public bool RemotePresentWhichMatches
6868
return false;
6969
}
7070
}
71+
72+
public string DiffUrlFormat { get { return string.Empty; }}
7173
}
7274
}

src/GitReleaseNotes/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ private static int GenerateReleaseNotes(string[] args)
110110
currentReleaseInfo.Name = arguments.Version;
111111
currentReleaseInfo.When = DateTimeOffset.Now;
112112
}
113-
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(gitRepo, issueTracker, previousReleaseNotes, categories, tagToStartFrom, currentReleaseInfo);
113+
var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
114+
gitRepo, issueTracker,
115+
previousReleaseNotes, categories,
116+
tagToStartFrom, currentReleaseInfo,
117+
issueTracker.DiffUrlFormat);
118+
114119
var releaseNotesOutput = releaseNotes.ToString();
115120
releaseFileWriter.OutputReleaseNotesFile(releaseNotesOutput, outputFile);
116121

src/GitReleaseNotes/ReleaseDiffInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public class ReleaseDiffInfo
44
{
55
public string BeginningSha { get; set; }
66
public string EndSha { get; set; }
7-
public string Url { get; set; }
7+
public string DiffUrlFormat { get; set; }
88
}
99
}

src/GitReleaseNotes/ReleaseNotesGenerator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ namespace GitReleaseNotes
88
{
99
public static class ReleaseNotesGenerator
1010
{
11-
public static SemanticReleaseNotes GenerateReleaseNotes(IRepository gitRepo, IIssueTracker issueTracker, SemanticReleaseNotes previousReleaseNotes, string[] categories, TaggedCommit tagToStartFrom, ReleaseInfo currentReleaseInfo)
11+
public static SemanticReleaseNotes GenerateReleaseNotes(
12+
IRepository gitRepo, IIssueTracker issueTracker, SemanticReleaseNotes previousReleaseNotes,
13+
string[] categories, TaggedCommit tagToStartFrom, ReleaseInfo currentReleaseInfo,
14+
string diffUrlFormat)
1215
{
1316
var releases = ReleaseFinder.FindReleases(gitRepo, tagToStartFrom, currentReleaseInfo);
1417
var findIssuesSince =
@@ -28,7 +31,9 @@ from release in releases
2831
let endSha = release.LastCommit == null ? null : release.LastCommit.Substring(0, 10)
2932
select new SemanticRelease(release.Name, release.When, releaseNoteItems, new ReleaseDiffInfo
3033
{
31-
BeginningSha = beginningSha, EndSha = endSha
34+
BeginningSha = beginningSha,
35+
EndSha = endSha,
36+
DiffUrlFormat = diffUrlFormat
3237
})).ToList();
3338

3439
return new SemanticReleaseNotes(semanticReleases, categories).Merge(previousReleaseNotes);

0 commit comments

Comments
 (0)