@@ -62,7 +62,7 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
6262 const commits = await this . getPullRequestCommits ( pullRequest ) ;
6363 const { squashCount, fixupCount, normalCommitsCount} = await this . getCommitsInfo ( pullRequest ) ;
6464 const method = this . getMergeActionFromPullRequest ( pullRequest ) ;
65-
65+ let pullRequestCommitCount = pullRequest . commitCount ;
6666 const mergeOptions : OctokitMergeParams = {
6767 pull_number : prNumber ,
6868 merge_method : method === 'auto' ? 'rebase' : method ,
@@ -90,14 +90,19 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
9090 // The commit message from the single normal commit is used.
9191 if ( hasOnlyFixUpForOneCommit ) {
9292 mergeOptions . merge_method = 'squash' ;
93+ pullRequestCommitCount = 1 ;
94+
9395 const [ title , message = '' ] = commits [ 0 ] . message . split ( COMMIT_HEADER_SEPARATOR ) ;
9496
9597 mergeOptions . commit_title = title ;
9698 mergeOptions . commit_message = message ;
99+
97100 // If the PR has only one normal commit and more than one squash commit, the PR is
98101 // squashed and the user is prompted to edit the commit message.
99102 } else if ( hasOnlySquashForOneCommit ) {
100103 mergeOptions . merge_method = 'squash' ;
104+ pullRequestCommitCount = 1 ;
105+
101106 await this . _promptCommitMessageEdit ( pullRequest , mergeOptions ) ;
102107 }
103108 }
@@ -148,6 +153,11 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
148153 ) ;
149154 }
150155
156+ // Refresh the target branch the PR has been merged into through the API. We need
157+ // to re-fetch as otherwise we cannot cherry-pick the new commits into the remaining
158+ // target branches. Also, this is needed fo the merge comment to get the correct commit SHA.
159+ this . fetchTargetBranches ( [ githubTargetBranch ] ) ;
160+
151161 // If the PR does not need to be merged into any other target branches,
152162 // we exit here as we already completed the merge.
153163 if ( ! cherryPickTargetBranches . length ) {
@@ -156,18 +166,11 @@ export class GithubApiMergeStrategy extends AutosquashMergeStrategy {
156166 return ;
157167 }
158168
159- // Refresh the target branch the PR has been merged into through the API. We need
160- // to re-fetch as otherwise we cannot cherry-pick the new commits into the remaining
161- // target branches.
162- this . fetchTargetBranches ( [ githubTargetBranch ] ) ;
163-
164- // Number of commits that have landed in the target branch. This could vary from
165- // the count of commits in the PR due to squashing.
166- const targetCommitsCount = method === 'squash' ? 1 : pullRequest . commitCount ;
167-
168169 // Cherry pick the merged commits into the remaining target branches.
169170 const failedBranches = await this . cherryPickIntoTargetBranches (
170- `${ targetSha } ~${ targetCommitsCount } ..${ targetSha } ` ,
171+ // Number of commits that have landed in the target branch. This could vary from
172+ // the count of commits in the PR due to squashing.
173+ `${ targetSha } ~${ pullRequestCommitCount } ..${ targetSha } ` ,
171174 cherryPickTargetBranches ,
172175 {
173176 // Commits that have been created by the Github API do not necessarily contain
0 commit comments