Skip to content
Snippets Groups Projects
Commit 8fc61e35 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

feat: add assignees and reviewers whenever status checks fail (#928)

This feature means that you can configure branches/PRs to automerge, but if status checks fail (preventing automerge) then you can still get assigneed the PR to take action. Previously such PRs remained unassigned because we do not assign automerging PRs by default, to reduce noise.

Closes #722
parent 1a174226
Branches
No related tags found
No related merge requests found
......@@ -143,6 +143,10 @@ async function ensurePr(prConfig) {
// Check if existing PR exists
const existingPr = await config.api.getBranchPr(branchName);
if (existingPr) {
if (config.automerge && branchStatus === 'failure') {
logger.debug(`Setting assignees and reviewers as status checks failed`);
await addAssigneesReviewers(config, existingPr);
}
// Check if existing PR needs updating
if (existingPr.title === prTitle && existingPr.body === prBody) {
logger.info(`${existingPr.displayNumber} does not need updating`);
......@@ -166,19 +170,33 @@ async function ensurePr(prConfig) {
await config.api.addLabels(pr.number, config.labels);
}
// Skip assign and review if automerging PR
if (config.automerge && config.automergeType === 'pr') {
if (
config.automerge &&
config.automergeType === 'pr' &&
branchStatus !== 'failure'
) {
logger.debug(
`Skipping assignees and reviewers as automerge=${config.automerge}`
);
} else {
await addAssigneesReviewers(config, pr);
}
logger.info(`Created ${pr.displayNumber}`);
return pr;
} catch (err) {
logger.error({ err }, 'Failed to ensure PR:', err);
}
return null;
}
async function addAssigneesReviewers(config, pr) {
const { logger } = config;
if (config.assignees.length > 0) {
logger.debug({ assignees: config.assignees }, 'Adding assignees');
try {
const assignees = config.assignees.map(
assignee =>
assignee.length && assignee[0] === '@'
? assignee.slice(1)
: assignee
assignee.length && assignee[0] === '@' ? assignee.slice(1) : assignee
);
await config.api.addAssignees(pr.number, assignees);
} catch (err) {
......@@ -190,9 +208,7 @@ async function ensurePr(prConfig) {
try {
const reviewers = config.reviewers.map(
reviewer =>
reviewer.length && reviewer[0] === '@'
? reviewer.slice(1)
: reviewer
reviewer.length && reviewer[0] === '@' ? reviewer.slice(1) : reviewer
);
await config.api.addReviewers(pr.number, reviewers);
} catch (err) {
......@@ -200,13 +216,6 @@ async function ensurePr(prConfig) {
}
}
}
logger.info(`Created ${pr.displayNumber}`);
return pr;
} catch (err) {
logger.error({ err }, 'Failed to ensure PR:', err);
}
return null;
}
async function checkAutoMerge(pr, config) {
const { logger } = config;
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`workers/pr ensurePr should add assignees and reviewers to existing PR 1`] = `Array []`;
exports[`workers/pr ensurePr should add assignees and reviewers to new PR 1`] = `
Array [
Array [
......
......@@ -95,6 +95,8 @@ describe('workers/pr', () => {
config = {
...defaultConfig,
api: {
addAssignees: jest.fn(),
addReviewers: jest.fn(),
createPr: jest.fn(() => ({ displayNumber: 'New Pull Request' })),
getBranchStatus: jest.fn(),
},
......@@ -266,6 +268,27 @@ describe('workers/pr', () => {
expect(config.api.addAssignees.mock.calls.length).toBe(0);
expect(config.api.addReviewers.mock.calls.length).toBe(0);
});
it('should add assignees and reviewers to existing PR', async () => {
config.depName = 'dummy';
config.automerge = true;
config.assignees = ['bar'];
config.reviewers = ['baz'];
config.isGitHub = true;
config.privateRepo = true;
config.currentVersion = '1.0.0';
config.newVersion = '1.1.0';
config.repositoryUrl = 'https://github.com/renovateapp/dummy';
config.api.getBranchPr = jest.fn(() => existingPr);
config.api.getBranchStatus.mockReturnValueOnce('failure');
config.api.updatePr = jest.fn();
config.semanticPrefix = '';
const pr = await prWorker.ensurePr(config);
expect(config.api.updatePr.mock.calls).toMatchSnapshot();
expect(config.api.updatePr.mock.calls.length).toBe(0);
expect(config.api.addAssignees.mock.calls.length).toBe(1);
expect(config.api.addReviewers.mock.calls.length).toBe(1);
expect(pr).toMatchObject(existingPr);
});
it('should return unmodified existing PR', async () => {
config.depName = 'dummy';
config.isGitHub = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment