Skip to content

Commit 43cd9ca

Browse files
committed
refactor(ng-dev): centralize commit count logic in API merge strategy
The `pullRequestCommitCount` was being conditionally reassigned in multiple places within the GithubApiMergeStrategy. This duplicated logic and made it harder to follow. This change refactors the logic to determine the commit count in a single location using a ternary operator, improving readability and maintainability.
1 parent e0c87a9 commit 43cd9ca

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
6363
const commits = await this.getPullRequestCommits(pullRequest);
6464
const {squashCount, fixupCount, normalCommitsCount} = await this.getCommitsInfo(pullRequest);
6565
const method = this.getMergeActionFromPullRequest(pullRequest);
66-
let pullRequestCommitCount = pullRequest.commitCount;
6766
const mergeOptions: OctokitMergeParams = {
6867
pull_number: prNumber,
6968
merge_method: method === 'auto' ? 'rebase' : method,
@@ -91,7 +90,6 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
9190
// The commit message from the single normal commit is used.
9291
if (hasOnlyFixUpForOneCommit) {
9392
mergeOptions.merge_method = 'squash';
94-
pullRequestCommitCount = 1;
9593

9694
// The first commit is the correct one, whatever follows are fixups.
9795
const [title, message = ''] = commits[0].message.split(COMMIT_HEADER_SEPARATOR);
@@ -103,7 +101,6 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
103101
// squashed and the user is prompted to edit the commit message.
104102
} else if (hasOnlySquashForOneCommit) {
105103
mergeOptions.merge_method = 'squash';
106-
pullRequestCommitCount = 1;
107104

108105
await this._promptCommitMessageEdit(pullRequest, mergeOptions);
109106
}
@@ -173,6 +170,10 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
173170
return;
174171
}
175172

173+
// Merge and Squash will merge the PR with a single commit.
174+
const pullRequestCommitCount =
175+
mergeOptions.merge_method === 'rebase' ? pullRequest.commitCount : 1;
176+
176177
// Cherry pick the merged commits into the remaining target branches.
177178
const failedBranches = await this.cherryPickIntoTargetBranches(
178179
// Number of commits that have landed in the target branch. This could vary from

0 commit comments

Comments
 (0)