Skip to content

Commit 93ac7cb

Browse files
committed
feat(ng-dev): include commit SHA in branch merge messages
This commit adds the unique commit SHA next to each branch listed in the pull request merge message. This provides a more specific reference to the exact commit that was merged. Example: angular/angular-cli#30959 (comment)
1 parent 93f120f commit 93ac7cb

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

ng-dev/pr/merge/strategies/api-merge.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,24 @@ export class GithubApiMergeStrategy extends MergeStrategy {
143143

144144
this.pushTargetBranchesUpstream(cherryPickTargetBranches);
145145

146+
/** The local branch names of the github targeted branches. */
147+
const banchesAndSha = targetBranches.map((targetBranch) => {
148+
const localBranch = this.getLocalTargetBranchName(targetBranch);
149+
150+
/** The SHA of the commit pushed to github which represents closing the PR. */
151+
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
152+
return [targetBranch, sha];
153+
});
154+
146155
// Because our process brings changes into multiple branchces, we include a comment which
147156
// expresses all of the branches the changes were merged into.
148157
await this.git.github.issues.createComment({
149158
...this.git.remoteParams,
150159
issue_number: pullRequest.prNumber,
151-
body: `The changes were merged into the following branches: ${targetBranches.join(', ')}`,
160+
body:
161+
'This PR was merged into the repository. ' +
162+
'The changes were merged into the following branches:\n\n' +
163+
`${banchesAndSha.map(([branch, sha]) => `- ${branch}: ${sha}`).join('\n')}`,
152164
});
153165
}
154166

ng-dev/pr/merge/strategies/autosquash-merge.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ export class AutosquashMergeStrategy extends MergeStrategy {
8383
// Push the cherry picked branches upstream.
8484
this.pushTargetBranchesUpstream(targetBranches);
8585

86-
/** The local branch name of the github targeted branch. */
87-
const localBranch = this.getLocalTargetBranchName(githubTargetBranch);
88-
/** The SHA of the commit pushed to github which represents closing the PR. */
89-
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
86+
/** The local branch names of the github targeted branches. */
87+
const banchesAndSha = targetBranches.map((targetBranch) => {
88+
const localBranch = this.getLocalTargetBranchName(targetBranch);
89+
90+
/** The SHA of the commit pushed to github which represents closing the PR. */
91+
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
92+
return [targetBranch, sha];
93+
});
94+
9095
// Allow user to set an amount of time to wait to account for rate limiting of the token usage
9196
// during merge otherwise just waits 0 seconds.
9297
await new Promise((resolve) =>
@@ -100,8 +105,9 @@ export class AutosquashMergeStrategy extends MergeStrategy {
100105
...this.git.remoteParams,
101106
issue_number: pullRequest.prNumber,
102107
body:
103-
`This PR was merged into the repository by commit ${sha}.\n\n` +
104-
`The changes were merged into the following branches: ${targetBranches.join(', ')}`,
108+
'This PR was merged into the repository. ' +
109+
'The changes were merged into the following branches:\n\n' +
110+
`${banchesAndSha.map(([branch, sha]) => `- ${branch}: ${sha}`).join('\n')}`,
105111
});
106112

107113
// For PRs which do not target the `main` branch on Github, Github does not automatically

0 commit comments

Comments
 (0)