Skip to content

Commit

Permalink
fix(internal): respect dry-run (#6071)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Apr 28, 2020
1 parent 993f411 commit 29b701a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
16 changes: 16 additions & 0 deletions lib/workers/repository/finalise/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,21 @@ describe('workers/repository/validate', () => {
expect(platform.ensureComment).toHaveBeenCalledTimes(0);
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(1);
});

it('validates successfully (dry-run)', async () => {
platform.getPrList.mockResolvedValueOnce([
{
state: PR_STATE_OPEN,
branchName: 'some/branch',
title: 'Update Renovate',
},
]);
platform.getPrFiles.mockResolvedValueOnce(['renovate.json']);
platform.getFile.mockResolvedValue('{}');
await validate.validatePrs({ dryRun: true });
expect(platform.setBranchStatus).toHaveBeenCalledTimes(0);
expect(platform.ensureComment).toHaveBeenCalledTimes(0);
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
});
});
});
25 changes: 18 additions & 7 deletions lib/workers/repository/finalise/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export async function validatePrs(config: RenovateConfig): Promise<void> {
? /* istanbul ignore next */ parsed.renovate ||
parsed['renovate-config']
: parsed;
// istanbul ignore else
if (toValidate) {
logger.debug({ config: toValidate }, 'Validating config');
const { errors } = await migrateAndValidate(config, toValidate);
Expand Down Expand Up @@ -105,18 +106,28 @@ export async function validatePrs(config: RenovateConfig): Promise<void> {
} else {
description = `Renovate config is valid`;
status = BranchStatus.green;
await platform.ensureCommentRemoval(pr.number, topic);
if (config.dryRun) {
logger.info(
`DRY-RUN: Would ensure validation comment removal in PR #${pr.number}`
);
} else {
await platform.ensureCommentRemoval(pr.number, topic);
}
}
// istanbul ignore else
if (pr.sourceRepo === config.repository) {
logger.debug({ status, description }, 'Setting PR validation status');
const context = `renovate/validate`;
await platform.setBranchStatus({
branchName: pr.branchName,
context,
description,
state: status,
});
if (config.dryRun) {
logger.info(`DRY-RUN: Would set branch status in PR #${pr.number}`);
} else {
await platform.setBranchStatus({
branchName: pr.branchName,
context,
description,
state: status,
});
}
} else {
logger.debug('Skipping branch status for forked PR');
}
Expand Down

0 comments on commit 29b701a

Please sign in to comment.