Skip to content

Commit

Permalink
feat: ornikar config mandatory pr body
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Sep 5, 2022
1 parent b0bf3b4 commit e8b74db
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/accountConfigs/ornikar.test.ts
Expand Up @@ -8,3 +8,80 @@ describe('ignoreRepoPattern', () => {
expect(shouldIgnoreRepo('devenv', ornikarConfig)).toBe(true);
});
});

describe('parsePR.body', () => {
it('should fail with empty description', () => {
expect(
ornikarConfig.parsePR?.body?.[0]?.createStatusInfo(
['', ''],
{} as any,
false,
),
).toEqual({
summary: 'The PR body should not be empty',
title: 'Body is empty',
type: 'failure',
});
});
it('should success with not empty description', () => {
expect(
ornikarConfig.parsePR?.body?.[0]?.createStatusInfo(
['', 'something'],
{} as any,
false,
),
).toEqual(null);
});
it('should fail on empty template description', () => {
expect(
ornikarConfig.parsePR?.body?.[0]?.createStatusInfo(
[
'',
`### Context
<!-- Explain here why this PR is needed -->
### Solution
<!-- Explain here the solution you chose for this -->
<!-- Uncomment this if you need a testing plan
### Testing plan
- [ ] Test this
- [ ] Test that
-->`,
],
{} as any,
false,
),
).toEqual({
type: 'failure',
title: 'Body has no meaningful content',
summary: 'The PR body should not contains only titles and comments',
});
});
it('should success on filled template description', () => {
expect(
ornikarConfig.parsePR?.body?.[0]?.createStatusInfo(
[
'',
`### Context
This is the context
### Solution
This is the solution
<!-- Uncomment this if you need a testing plan
### Testing plan
- [ ] Test this
- [ ] Test that
-->`,
],
{} as any,
false,
),
).toEqual(null);
});
});
35 changes: 35 additions & 0 deletions src/accountConfigs/ornikar.ts
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import type { Config } from './types';

const config: Config<'dev' | 'design', 'ops' | 'frontends' | 'backends'> = {
Expand Down Expand Up @@ -74,6 +75,40 @@ const config: Config<'dev' | 'design', 'ops' | 'frontends' | 'backends'> = {
},
},
],
body: [
{
bot: false,
regExp: /^(.*)$/s,
createStatusInfo: (match) => {
const description = match?.[1];
if (!description || !description.trim()) {
return {
type: 'failure',
title: 'Body is empty',
summary: 'The PR body should not be empty',
};
}
const descriptionStripTitlesAndComments =
description &&
description
.replace(/^\s*#+\s+.*/gm, '')
.replace(/(<!--.*?-->)|(<!--[\S\s]+?-->)|(<!--[\S\s]*?$)/gs, '');

if (
!descriptionStripTitlesAndComments ||
!descriptionStripTitlesAndComments.trim()
) {
return {
type: 'failure',
title: 'Body has no meaningful content',
summary:
'The PR body should not contains only titles and comments',
};
}
return null;
},
},
],
head: [
{
bot: false,
Expand Down
1 change: 1 addition & 0 deletions src/accountConfigs/types.ts
Expand Up @@ -35,6 +35,7 @@ export interface ParsePRRule {

export interface ParsePR {
title?: ParsePRRule[];
body?: ParsePRRule[];
head?: ParsePRRule[];
base?: ParsePRRule[];
}
Expand Down
1 change: 1 addition & 0 deletions src/events/pr-handlers/actions/editOpenedPR.ts
Expand Up @@ -54,6 +54,7 @@ export const editOpenedPR = async <Name extends EventsWithRepository>({

const parsePRValue = {
title,
body: pullRequest.body || '',
head: pullRequest.head.ref,
base: pullRequest.base.ref,
};
Expand Down

0 comments on commit e8b74db

Please sign in to comment.