Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PrResult enum #5664

Merged
merged 9 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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