Skip to content

Commit

Permalink
feat(ng-dev/pr): include comment for PR merges on all autosquashed me…
Browse files Browse the repository at this point in the history
…rges

Because our autosquash merge strategy relies on the fact that  Github automatically closes PRs whose commits
are included in the primary branch.  The commits are closed rather than merged without clear indication to
the PR author that their PR has been in fact merged, rather than just closed. Instead we will now add a
comment to the PR expressing that the PR has actually been merged.
  • Loading branch information
josephperrott authored and devversion committed Sep 16, 2021
1 parent 4ec476f commit 33c7394
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ng-dev/pr/merge/strategies/autosquash-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,25 @@ export class AutosquashMergeStrategy extends MergeStrategy {

this.pushTargetBranchesUpstream(targetBranches);

/** The local branch name of the github targeted branch. */
const localBranch = this.getLocalTargetBranchName(githubTargetBranch);
/** The SHA of the commit pushed to github which represents closing the PR. */
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
// Github automatically closes PRs whose commits are merged into the main branch on Github.
// However, it does not note them as merged using the purple merge badge as occurs when done via
// the UI. To inform users that the PR was in fact merged, add a comment expressing the fact
// that the PR is merged.
await this.git.github.issues.createComment({
...this.git.remoteParams,
issue_number: pullRequest.prNumber,
body: `This PR was merged into the repository by commit ${sha}.`,
});

// For PRs which do not target the `main` branch on Github, Github does not automatically
// close the PR when its commit is pushed into the repository. To ensure these PRs are
// correctly marked as closed, we must detect this situation and close the PR via the API after
// the upstream pushes are completed.
if (githubTargetBranch !== this.git.mainBranchName) {
/** The local branch name of the github targeted branch. */
const localBranch = this.getLocalTargetBranchName(githubTargetBranch);
/** The SHA of the commit pushed to github which represents closing the PR. */
const sha = this.git.run(['rev-parse', localBranch]).stdout.trim();
// Create a comment saying the PR was closed by the SHA.
await this.git.github.issues.createComment({
...this.git.remoteParams,
issue_number: pullRequest.prNumber,
body: `Closed by commit ${sha}`,
});
// Actually close the PR.
await this.git.github.pulls.update({
...this.git.remoteParams,
pull_number: pullRequest.prNumber,
Expand Down

0 comments on commit 33c7394

Please sign in to comment.