Skip to content

Commit

Permalink
fix: auto merge not running when there's no conflicts (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasmoeller authored Aug 30, 2023
1 parent 78f291e commit 02335b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ import { TargetBranchResponse } from '../github/v4/validateTargetBranch';
import * as logger from '../logger';
import * as oraModule from '../ora';
import { Commit } from '../sourceCommit/parseSourceCommit';
import * as autoMergeNowOrLater from './autoMergeNowOrLater';
import { cherrypickAndCreateTargetPullRequest } from './cherrypickAndCreateTargetPullRequest';

describe('cherrypickAndCreateTargetPullRequest', () => {
let execSpy: SpyHelper<typeof childProcess.spawnPromise>;
let addLabelsScope: ReturnType<typeof nock>;
let consoleLogSpy: SpyHelper<(typeof logger)['consoleLog']>;
let autoMergeSpy: SpyHelper<typeof autoMergeNowOrLater.autoMergeNowOrLater>;

beforeEach(() => {
jest.spyOn(os, 'homedir').mockReturnValue('/myHomeDir');

autoMergeSpy = jest.spyOn(autoMergeNowOrLater, 'autoMergeNowOrLater');

execSpy = jest
.spyOn(childProcess, 'spawnPromise')

Expand Down Expand Up @@ -53,6 +57,8 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
assignees: [] as string[],
authenticatedUsername: 'sqren_authenticated',
author: 'sqren',
autoMerge: true,
autoMergeMethod: 'squash',
fork: true,
gitAuthorEmail: '[email protected]',
gitAuthorName: 'Soren L',
Expand Down Expand Up @@ -166,6 +172,10 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
`);
});

it('calls autoMergeNowOrLater', () => {
expect(autoMergeSpy).toHaveBeenCalledWith(expect.any(Object), 1337);
});

it('returns the expected response', () => {
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
});
Expand All @@ -187,17 +197,18 @@ describe('cherrypickAndCreateTargetPullRequest', () => {

it('should start the spinner with the correct text', () => {
expect(oraSpy.mock.calls.map(([, text]) => text)).toMatchInlineSnapshot(`
[
"",
"Pulling latest changes",
"Cherry-picking: My original commit message (#1000)",
"Cherry-picking: My other commit message (#2000)",
"Pushing branch "sqren:backport/6.x/pr-1000_pr-2000"",
undefined,
"Creating pull request",
"Adding labels: backport",
]
`);
[
"",
"Pulling latest changes",
"Cherry-picking: My original commit message (#1000)",
"Cherry-picking: My other commit message (#2000)",
"Pushing branch "sqren:backport/6.x/pr-1000_pr-2000"",
undefined,
"Creating pull request",
"Adding labels: backport",
"Auto-merge: Enabling via "squash"",
]
`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function cherrypickAndCreateTargetPullRequest({
}

// make PR auto mergable
if (options.autoMerge && hasAnyCommitWithConflicts) {
if (options.autoMerge && !hasAnyCommitWithConflicts) {
await autoMergeNowOrLater(options, targetPullRequest.number);
}

Expand Down

0 comments on commit 02335b0

Please sign in to comment.