Skip to content

Commit 877bc5b

Browse files
committed
Contributors
1 parent 06513b0 commit 877bc5b

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace GitReleaseManager.Core.Extensions
5+
{
6+
internal static class LinqExtensions
7+
{
8+
// This is the equivalent of DistinctBy which is available in .NET 6
9+
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
10+
{
11+
HashSet<TKey> seenKeys = new HashSet<TKey>();
12+
foreach (TSource element in source)
13+
{
14+
if (seenKeys.Add(keySelector(element)))
15+
{
16+
yield return element;
17+
}
18+
}
19+
}
20+
}
21+
}

src/GitReleaseManager.Core/ReleaseNotes/ReleaseNotesBuilder.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using GitReleaseManager.Core.Configuration;
77
using GitReleaseManager.Core.Exceptions;
8+
using GitReleaseManager.Core.Extensions;
89
using GitReleaseManager.Core.Helpers;
910
using GitReleaseManager.Core.Model;
1011
using GitReleaseManager.Core.Provider;
@@ -66,12 +67,19 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
6667

6768
var commitsLink = _vcsProvider.GetCommitsUrl(_user, _repository, _targetMilestone?.Title, previousMilestone?.Title);
6869

69-
foreach (var issue in issues)
70+
var issuesDict = GetIssuesDict(issues);
71+
72+
// The call to GetIssuesDict above will filter out the issues that are not taged with one of the configured tags.
73+
// Therefore it's more efficient to fetch the linked issues AFTER GetIssuesDict has been invoked.
74+
foreach (var kvp in issuesDict)
7075
{
71-
issue.LinkedIssue = await _vcsProvider.GetLinkedIssueAsync(_user, _repository, issue.Number).ConfigureAwait(false);
76+
foreach (var issue in kvp.Value)
77+
{
78+
issue.LinkedIssue = await _vcsProvider.GetLinkedIssueAsync(_user, _repository, issue.Number).ConfigureAwait(false);
79+
}
7280
}
7381

74-
var issuesDict = GetIssuesDict(issues);
82+
var contributors = GetContributors(issues);
7583

7684
var templateModel = new
7785
{
@@ -80,6 +88,11 @@ public async Task<string> BuildReleaseNotesAsync(string user, string repository,
8088
issues.Count,
8189
Items = issuesDict,
8290
},
91+
Contributors = new
92+
{
93+
Count = contributors.Count,
94+
Items = contributors,
95+
},
8396
Commits = new
8497
{
8598
Count = numberOfCommits,
@@ -113,6 +126,18 @@ private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
113126
return issuesByLabel;
114127
}
115128

129+
private static List<User> GetContributors(List<Issue> issues)
130+
{
131+
var contributors = issues
132+
.Select(i => i.User)
133+
.Union(issues.Select(i => i.LinkedIssue?.User))
134+
.Where(u => u != null)
135+
.DistinctBy(u => u.Login)
136+
.ToList();
137+
138+
return contributors;
139+
}
140+
116141
private string GetValidLabel(string label, int issuesCount)
117142
{
118143
var alias = _configuration.LabelAliases.FirstOrDefault(x => x.Name.Equals(label, StringComparison.OrdinalIgnoreCase));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="{{contributor.avatar_url}}" alt="{{contributor.login}}" height="32" width="32"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
__Contributors__
4+
5+
{{ contributors.count }} contributors made this release possible.
6+
7+
{{ for contributor in contributors.items
8+
include 'contributor-details'
9+
end }}
10+

src/GitReleaseManager.Core/Templates/default/index.sbn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
include 'milestone'
55
end
66
include 'issues' | string.rstrip
7+
include 'contributors'
78
if template_kind == "CREATE"
89
include 'create/footer'
910
end

src/GitReleaseManager.IntegrationTests/ReleaseNotesBuilderIntegrationTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ public async Task SingleMilestone()
5555
{
5656
var fileSystem = new FileSystem(new CreateSubOptions());
5757
var currentDirectory = Environment.CurrentDirectory;
58+
5859
var configuration = ConfigurationProvider.Provide(currentDirectory, fileSystem);
60+
configuration.IssueLabelsExclude.Add("Internal Refactoring"); // This is necessary to generate the release notes for GitReleaseManager version 0.12.0
5961

6062
var vcsProvider = new GitHubProvider(_gitHubClient, _mapper);
6163
var releaseNotesBuilder = new ReleaseNotesBuilder(vcsProvider, _logger, fileSystem, configuration, new TemplateFactory(fileSystem, configuration, TemplateKind.Create));
62-
var result = await releaseNotesBuilder.BuildReleaseNotesAsync("Chocolatey", "ChocolateyGUI", "0.12.4", ReleaseTemplates.DEFAULT_NAME).ConfigureAwait(false);
64+
var result = await releaseNotesBuilder.BuildReleaseNotesAsync("GitTools", "GitReleaseManager", "0.12.0", ReleaseTemplates.DEFAULT_NAME).ConfigureAwait(false); // 0.12.0 contains a mix of issues and PRs
6365
Debug.WriteLine(result);
6466
ClipBoardHelper.SetClipboard(result);
6567
}

0 commit comments

Comments
 (0)