Skip to content

Commit

Permalink
feat: PrResult enum (#5664)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Mar 10, 2020
1 parent ab94f91 commit 34496d3
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 63 deletions.
44 changes: 35 additions & 9 deletions lib/workers/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
PR_STATE_OPEN,
} from '../../constants/pull-requests';
import { StatusResult } from '../../platform/git/storage';
import { PrResult } from '../pr';

jest.mock('./get-updated');
jest.mock('./schedule');
Expand Down Expand Up @@ -291,7 +292,9 @@ describe('workers/branch', () => {
platform.branchExists.mockResolvedValueOnce(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce('needs-pr-approval');
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.AwaitingApproval,
});
expect(await branchWorker.processBranch(config)).toEqual(
'needs-pr-approval'
);
Expand All @@ -308,7 +311,9 @@ describe('workers/branch', () => {
platform.branchExists.mockResolvedValueOnce(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce('pending');
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.AwaitingNotPending,
});
expect(await branchWorker.processBranch(config)).toEqual('pending');
});
it('returns if branch exists but updated', async () => {
Expand Down Expand Up @@ -341,7 +346,10 @@ describe('workers/branch', () => {
} as never);
platform.branchExists.mockResolvedValueOnce(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
await branchWorker.processBranch(config);
Expand All @@ -359,7 +367,10 @@ describe('workers/branch', () => {
} as never);
platform.branchExists.mockResolvedValueOnce(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
await branchWorker.processBranch(config);
Expand All @@ -378,7 +389,10 @@ describe('workers/branch', () => {
} as never);
platform.branchExists.mockResolvedValueOnce(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
config.releaseTimestamp = '2018-04-26T05:15:51.877Z';
commit.commitFilesToBranch.mockResolvedValueOnce(null);
Expand All @@ -398,7 +412,10 @@ describe('workers/branch', () => {
} as never);
platform.branchExists.mockResolvedValueOnce(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
config.releaseTimestamp = new Date().toISOString();
commit.commitFilesToBranch.mockResolvedValueOnce(null);
Expand All @@ -418,7 +435,10 @@ describe('workers/branch', () => {
} as never);
platform.branchExists.mockResolvedValueOnce(false);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
config.releaseTimestamp = new Date().toISOString();
await expect(branchWorker.processBranch(config)).rejects.toThrow(
Expand All @@ -436,7 +456,10 @@ describe('workers/branch', () => {
config.recreateClosed = true;
platform.branchExists.mockResolvedValueOnce(true);
automerge.tryBranchAutomerge.mockResolvedValueOnce('failed');
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
prWorker.checkAutoMerge.mockResolvedValueOnce(true);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
await branchWorker.processBranch(config);
Expand Down Expand Up @@ -547,7 +570,10 @@ describe('workers/branch', () => {
} as never);

schedule.isScheduledNow.mockReturnValueOnce(false);
prWorker.ensurePr.mockResolvedValueOnce({} as never);
prWorker.ensurePr.mockResolvedValueOnce({
result: PrResult.Created,
pr: {},
} as never);
commit.commitFilesToBranch.mockResolvedValueOnce(null);
expect(
await branchWorker.processBranch({
Expand Down
11 changes: 7 additions & 4 deletions lib/workers/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getParentBranch } from './parent';
import { tryBranchAutomerge } from './automerge';
import { setStability, setUnpublishable } from './status-checks';
import { prAlreadyExisted } from './check-existing';
import { ensurePr, checkAutoMerge } from '../pr';
import { ensurePr, checkAutoMerge, PrResult } from '../pr';
import { RenovateConfig } from '../../config';
import { platform } from '../../platform';
import { emojify } from '../../util/emoji';
Expand Down Expand Up @@ -546,12 +546,15 @@ export async function processBranch(
logger.debug(
`There are ${config.errors.length} errors and ${config.warnings.length} warnings`
);
const pr = await ensurePr(config);
const { result, pr } = await ensurePr(config);
// TODO: ensurePr should check for automerge itself
if (pr === 'needs-pr-approval') {
if (result === PrResult.AwaitingApproval) {
return 'needs-pr-approval';
}
if (pr === 'pending') {
if (
result === PrResult.AwaitingGreenBranch ||
result === PrResult.AwaitingNotPending
) {
return 'pending';
}
if (pr) {
Expand Down
Loading

0 comments on commit 34496d3

Please sign in to comment.