Skip to content

Commit 2764065

Browse files
committed
(GH-51) Adding ability to only export specific release
Rather than only exporting all release notes, add ability to only export specific tag
1 parent be4d47f commit 2764065

File tree

7 files changed

+80
-31
lines changed

7 files changed

+80
-31
lines changed

Source/GitHubReleaseManager.Cli/Options/ExportSubOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public class ExportSubOptions : BaseGitHubSubOptions
1212
{
1313
[Option('f', "fileOutputPath", HelpText = "Path to the file export releases.", Required = true)]
1414
public string FileOutputPath { get; set; }
15+
16+
[Option('t', "tagName", HelpText = "The name of the release (Typically this is the generated SemVer Version Number).", Required = false)]
17+
public string TagName { get; set; }
1518
}
1619
}

Source/GitHubReleaseManager.Cli/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, I
132132

133133
if (string.IsNullOrEmpty(subOptions.Milestone))
134134
{
135-
await CreateReleaseFromMilestone(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.TargetCommitish, subOptions.AssetPaths, configuration);
135+
await CreateReleaseFromMilestone(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone, subOptions.TargetCommitish, subOptions.AssetPaths, subOptions.PreRelease, configuration);
136136
}
137137
else
138138
{
139-
await CreateReleaseFromInputFile(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Name, subOptions.InputFilePath, subOptions.TargetCommitish, subOptions.AssetPaths, configuration);
139+
await CreateReleaseFromInputFile(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Name, subOptions.InputFilePath, subOptions.TargetCommitish, subOptions.AssetPaths, subOptions.PreRelease, configuration);
140140
}
141141

142142
return 0;
@@ -210,7 +210,7 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
210210
var github = subOptions.CreateGitHubClient();
211211
var configuration = ConfigurationProvider.Provide(subOptions.TargetDirectory, fileSystem);
212212

213-
var releasesMarkdown = await ExportReleases(github, subOptions.RepositoryOwner, subOptions.RepositoryName, configuration);
213+
var releasesMarkdown = await ExportReleases(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.TagName, configuration);
214214

215215
using (var sw = new StreamWriter(File.Open(subOptions.FileOutputPath, FileMode.OpenOrCreate)))
216216
{
@@ -337,11 +337,11 @@ private static async Task AddAssets(GitHubClient github, string owner, string re
337337
}
338338
}
339339

340-
private static async Task<string> ExportReleases(GitHubClient github, string owner, string repository, Config configuration)
340+
private static async Task<string> ExportReleases(GitHubClient github, string owner, string repository, string tagName, Config configuration)
341341
{
342342
var releaseNotesExporter = new ReleaseNotesExporter(new DefaultGitHubClient(github, owner, repository), configuration);
343343

344-
var result = await releaseNotesExporter.ExportReleaseNotes();
344+
var result = await releaseNotesExporter.ExportReleaseNotes(tagName);
345345

346346
return result;
347347
}

Source/GitHubReleaseManager.Tests/FakeGitHubClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public FakeGitHubClient()
1919
this.Milestones = new List<Milestone>();
2020
this.Issues = new List<Issue>();
2121
this.Releases = new List<Release>();
22+
this.Release = new Release();
2223
}
2324

2425
public List<Milestone> Milestones { get; private set; }
@@ -27,6 +28,8 @@ public FakeGitHubClient()
2728

2829
public List<Release> Releases { get; private set; }
2930

31+
public Release Release { get; private set; }
32+
3033
public int NumberOfCommits { private get; set; }
3134

3235
public Task<int> GetNumberOfCommitsBetween(Milestone previousMilestone, Milestone currentMilestone)
@@ -44,6 +47,11 @@ public Task<List<Release>> GetReleases()
4447
return Task.FromResult(this.Releases);
4548
}
4649

50+
public Task<Release> GetSpecificRelease(string tagName)
51+
{
52+
return Task.FromResult(this.Release);
53+
}
54+
4755
public ReadOnlyCollection<Milestone> GetMilestones()
4856
{
4957
return new ReadOnlyCollection<Milestone>(this.Milestones);

Source/GitHubReleaseManager.Tests/ReleaseNotesExporterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static void AcceptTest(Config configuration, params Release[] releases)
6666
}
6767

6868
var builder = new ReleaseNotesExporter(fakeClient, configuration);
69-
var notes = builder.ExportReleaseNotes().Result;
69+
var notes = builder.ExportReleaseNotes(null).Result;
7070

7171
Approvals.Verify(notes);
7272
}

Source/GitHubReleaseManager/DefaultGitHubClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public async Task<List<Release>> GetReleases()
5858
return allReleases.OrderByDescending(r => r.CreatedAt).ToList();
5959
}
6060

61+
public async Task<Release> GetSpecificRelease(string tagName)
62+
{
63+
var allReleases = await this.gitHubClient.Release.GetAll(this.user, this.repository);
64+
return allReleases.FirstOrDefault(r => r.TagName == tagName);
65+
}
66+
6167
public ReadOnlyCollection<Milestone> GetMilestones()
6268
{
6369
var milestonesClient = this.gitHubClient.Issue.Milestone;

Source/GitHubReleaseManager/IGitHubClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface IGitHubClient
2020
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Not appropriate")]
2121
Task<List<Release>> GetReleases();
2222

23+
Task<Release> GetSpecificRelease(string tagName);
24+
2325
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Not appropriate")]
2426
ReadOnlyCollection<Milestone> GetMilestones();
2527
}

Source/GitHubReleaseManager/ReleaseNotesExporter.cs

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,73 @@ public ReleaseNotesExporter(IGitHubClient gitHubClient, Config configuration)
2525
}
2626

2727
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Not appropriate.")]
28-
public async Task<string> ExportReleaseNotes()
28+
public async Task<string> ExportReleaseNotes(string tagName)
2929
{
30-
var releases = await this.gitHubClient.GetReleases();
31-
3230
var stringBuilder = new StringBuilder();
3331

34-
if (releases.Count > 0)
32+
if (string.IsNullOrEmpty(tagName))
3533
{
36-
foreach (var release in releases)
34+
var releases = await this.gitHubClient.GetReleases();
35+
36+
if (releases.Count > 0)
3737
{
38-
if (this.configuration.Export.IncludeCreatedDateInTitle)
39-
{
40-
stringBuilder.AppendLine(string.Format("## {0} ({1})", release.TagName, release.CreatedAt.ToString(this.configuration.Export.CreatedDateStringFormat)));
41-
}
42-
else
38+
foreach (var release in releases)
4339
{
44-
stringBuilder.AppendLine(string.Format("## {0}", release.TagName));
45-
}
46-
47-
stringBuilder.AppendLine(Environment.NewLine);
40+
if (this.configuration.Export.IncludeCreatedDateInTitle)
41+
{
42+
stringBuilder.AppendLine(string.Format("## {0} ({1})", release.TagName, release.CreatedAt.ToString(this.configuration.Export.CreatedDateStringFormat)));
43+
}
44+
else
45+
{
46+
stringBuilder.AppendLine(string.Format("## {0}", release.TagName));
47+
}
4848

49-
if (this.configuration.Export.PerformRegexRemoval)
50-
{
51-
var regexPattern = new Regex(this.configuration.Export.RegexText, this.configuration.Export.IsMultilineRegex ? RegexOptions.Multiline : RegexOptions.Singleline);
52-
var replacement = string.Empty;
53-
var replacedBody = regexPattern.Replace(release.Body, replacement);
54-
stringBuilder.AppendLine(replacedBody);
55-
}
56-
else
57-
{
58-
stringBuilder.AppendLine(release.Body);
49+
stringBuilder.AppendLine(Environment.NewLine);
50+
51+
if (this.configuration.Export.PerformRegexRemoval)
52+
{
53+
var regexPattern = new Regex(this.configuration.Export.RegexText, this.configuration.Export.IsMultilineRegex ? RegexOptions.Multiline : RegexOptions.Singleline);
54+
var replacement = string.Empty;
55+
var replacedBody = regexPattern.Replace(release.Body, replacement);
56+
stringBuilder.AppendLine(replacedBody);
57+
}
58+
else
59+
{
60+
stringBuilder.AppendLine(release.Body);
61+
}
5962
}
6063
}
64+
else
65+
{
66+
stringBuilder.Append("Unable to find any releases for specified repository.");
67+
}
6168
}
6269
else
6370
{
64-
stringBuilder.Append("Unable to find any releases for specified repository.");
71+
var release = await this.gitHubClient.GetSpecificRelease(tagName);
72+
73+
if (this.configuration.Export.IncludeCreatedDateInTitle)
74+
{
75+
stringBuilder.AppendLine(string.Format("## {0} ({1})", release.TagName, release.CreatedAt.ToString(this.configuration.Export.CreatedDateStringFormat)));
76+
}
77+
else
78+
{
79+
stringBuilder.AppendLine(string.Format("## {0}", release.TagName));
80+
}
81+
82+
stringBuilder.AppendLine(Environment.NewLine);
83+
84+
if (this.configuration.Export.PerformRegexRemoval)
85+
{
86+
var regexPattern = new Regex(this.configuration.Export.RegexText, this.configuration.Export.IsMultilineRegex ? RegexOptions.Multiline : RegexOptions.Singleline);
87+
var replacement = string.Empty;
88+
var replacedBody = regexPattern.Replace(release.Body, replacement);
89+
stringBuilder.AppendLine(replacedBody);
90+
}
91+
else
92+
{
93+
stringBuilder.AppendLine(release.Body);
94+
}
6595
}
6696

6797
return stringBuilder.ToString();

0 commit comments

Comments
 (0)