Skip to content

Commit 85f6a40

Browse files
CopilotMalcolmnixon
andcommitted
Simplify commitHashToPr dictionary building with ternary operator
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent e9a596e commit 85f6a40

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,10 @@ public override async Task<BuildInformation> GetBuildInformationAsync(Version? v
8080

8181
// Build a mapping from commit SHA to pull request.
8282
// This is used to associate commits with their pull requests for change tracking.
83-
// Include both merged PRs (via MergeCommitSha) and open PRs (via head SHA).
84-
var commitHashToPr = new Dictionary<string, PullRequest>();
85-
foreach (var pr in pullRequests)
86-
{
87-
if (pr.Merged && pr.MergeCommitSha != null)
88-
{
89-
// Add merged PR by its merge commit SHA
90-
commitHashToPr.TryAdd(pr.MergeCommitSha, pr);
91-
}
92-
else if (pr.State == ItemState.Open && pr.Head?.Sha != null)
93-
{
94-
// Add open PR by its head commit SHA
95-
commitHashToPr.TryAdd(pr.Head.Sha, pr);
96-
}
97-
}
83+
// For merged PRs, use MergeCommitSha; for open PRs, use head SHA.
84+
var commitHashToPr = pullRequests
85+
.Where(p => (p.Merged && p.MergeCommitSha != null) || (!p.Merged && p.Head?.Sha != null))
86+
.ToDictionary(p => p.Merged ? p.MergeCommitSha! : p.Head.Sha, p => p);
9887

9988
// Build a set of commit SHAs in the current branch.
10089
// This is used for efficient filtering of branch-related tags.

0 commit comments

Comments
 (0)