Skip to content

Commit b2f3a85

Browse files
alan-agius4josephperrott
authored andcommitted
feat(ng-dev): include commit SHA in branch merge messages (#2979)
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) PR Close #2979
1 parent 60d9b74 commit b2f3a85

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 8 additions & 5 deletions
Large diffs are not rendered by default.

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

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

144144
this.pushTargetBranchesUpstream(cherryPickTargetBranches);
145145

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

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@ 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: [branchName: string, commitSha: string][] = targetBranches.map(
88+
(targetBranch) => {
89+
const localBranch = this.getLocalTargetBranchName(targetBranch);
90+
91+
/** The SHA of the commit pushed to github which represents closing the PR. */
92+
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
93+
return [targetBranch, sha];
94+
},
95+
);
96+
9097
// Allow user to set an amount of time to wait to account for rate limiting of the token usage
9198
// during merge otherwise just waits 0 seconds.
9299
await new Promise((resolve) =>
@@ -100,8 +107,9 @@ export class AutosquashMergeStrategy extends MergeStrategy {
100107
...this.git.remoteParams,
101108
issue_number: pullRequest.prNumber,
102109
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(', ')}`,
110+
'This PR was merged into the repository. ' +
111+
'The changes were merged into the following branches:\n\n' +
112+
`${banchesAndSha.map(([branch, sha]) => `- ${branch}: ${sha}`).join('\n')}`,
105113
});
106114

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

0 commit comments

Comments
 (0)