mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
feat: add comment to PRs if config validation fails
This commit is contained in:
parent
a186a4b091
commit
d237c6c670
2 changed files with 25 additions and 3 deletions
|
@ -38,7 +38,10 @@ async function validatePrs(config) {
|
|||
try {
|
||||
parsed = JSON.parse(content);
|
||||
} catch (err) {
|
||||
validations.push('Cannot parse ' + file);
|
||||
validations.push({
|
||||
file,
|
||||
message: 'Invalid JSON',
|
||||
});
|
||||
}
|
||||
if (parsed) {
|
||||
const { errors } = migrateAndValidate(
|
||||
|
@ -49,7 +52,10 @@ async function validatePrs(config) {
|
|||
);
|
||||
if (errors && errors.length) {
|
||||
validations = validations.concat(
|
||||
errors.map(error => error.message)
|
||||
errors.map(error => ({
|
||||
file,
|
||||
message: error.message,
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -57,12 +63,18 @@ async function validatePrs(config) {
|
|||
// if the PR has renovate files then we set a status no matter what
|
||||
let status;
|
||||
let description;
|
||||
const subject = 'Renovate Configuration Errors';
|
||||
if (validations.length) {
|
||||
description = validations.join(', ').substring(0, 140); // GitHub limit
|
||||
const content = validations
|
||||
.map(v => `\`${v.file}\`: ${v.message}`)
|
||||
.join('\n\n');
|
||||
await platform.ensureComment(pr.number, subject, content);
|
||||
status = 'failure';
|
||||
description = 'Renovate config validation failed'; // GitHub limit
|
||||
} else {
|
||||
description = 'Renovate config is valid';
|
||||
status = 'success';
|
||||
await platform.ensureCommentRemoval(pr.number, subject);
|
||||
}
|
||||
logger.info({ status, description }, 'Setting PR validation status');
|
||||
const context = 'renovate/validate';
|
||||
|
|
|
@ -16,6 +16,8 @@ describe('workers/repository/validate', () => {
|
|||
]);
|
||||
await validate.validatePrs({});
|
||||
expect(platform.setBranchStatus.mock.calls).toHaveLength(0);
|
||||
expect(platform.ensureComment.mock.calls).toHaveLength(0);
|
||||
expect(platform.ensureCommentRemoval.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('returns if no matching files', async () => {
|
||||
platform.getPrList.mockReturnValueOnce([
|
||||
|
@ -28,6 +30,8 @@ describe('workers/repository/validate', () => {
|
|||
platform.getPrFiles.mockReturnValueOnce(['readme.md']);
|
||||
await validate.validatePrs({});
|
||||
expect(platform.setBranchStatus.mock.calls).toHaveLength(0);
|
||||
expect(platform.ensureComment.mock.calls).toHaveLength(0);
|
||||
expect(platform.ensureCommentRemoval.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('validates failures if cannot parse', async () => {
|
||||
platform.getPrList.mockReturnValueOnce([
|
||||
|
@ -42,6 +46,8 @@ describe('workers/repository/validate', () => {
|
|||
await validate.validatePrs({});
|
||||
expect(platform.setBranchStatus.mock.calls).toHaveLength(1);
|
||||
expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('failure');
|
||||
expect(platform.ensureComment.mock.calls).toHaveLength(1);
|
||||
expect(platform.ensureCommentRemoval.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('validates failures if config validation fails', async () => {
|
||||
platform.getPrList.mockReturnValueOnce([
|
||||
|
@ -56,6 +62,8 @@ describe('workers/repository/validate', () => {
|
|||
await validate.validatePrs({});
|
||||
expect(platform.setBranchStatus.mock.calls).toHaveLength(1);
|
||||
expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('failure');
|
||||
expect(platform.ensureComment.mock.calls).toHaveLength(1);
|
||||
expect(platform.ensureCommentRemoval.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('validates successfully', async () => {
|
||||
platform.getPrList.mockReturnValueOnce([
|
||||
|
@ -70,6 +78,8 @@ describe('workers/repository/validate', () => {
|
|||
await validate.validatePrs({});
|
||||
expect(platform.setBranchStatus.mock.calls).toHaveLength(1);
|
||||
expect(platform.setBranchStatus.mock.calls[0][3]).toEqual('success');
|
||||
expect(platform.ensureComment.mock.calls).toHaveLength(0);
|
||||
expect(platform.ensureCommentRemoval.mock.calls).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue