WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e85a542

Browse files
author
Vijay Ramesh
authored
Merge pull request #40 from vijaykramesh/require_brackets
add require_brackets config
2 parents 12799fd + be20375 commit e85a542

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ check_title: true
3737
check_branch: true
3838
check_commits: true
3939
ignore_case: true
40+
require_brackets: true
4041
```
4142
4243
## Local Development
@@ -67,6 +68,8 @@ Run `yarn test` to test:
6768
✓ passes if ignore_case and lower case title/branch (6 ms)
6869
✓ passes if ignore_case and lower case commits (7 ms)
6970
✓ fails if not ignore_case and lower case title/branch (4 ms)
71+
✓ passes if require_brakcets is false and title matches without brackets (5 ms)
72+
✓ fails if require_brackets is true or default and title matches without brackets (4 ms)
7073
```
7174

7275
## Lint

fixtures/no-brackets.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
projects: ['PROJ', 'ABC']
2+
check_title: true
3+
check_branch: false
4+
ignore_case: true
5+
require_brackets: false

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const defaults = {
1010
check_branch: false,
1111
check_commits: false,
1212
ignore_case: false,
13+
require_brackets: true,
1314
};
1415

1516
function createProjectRegex(project, ignoreCase = false) {
@@ -28,8 +29,11 @@ function findFailedCommits(projects, commitsInPR, ignoreCase) {
2829
return failedCommits;
2930
}
3031

31-
function createWrappedProjectRegex(project) {
32-
return new RegExp(`\\[${project}-\\d*\\]`);
32+
function createWrappedProjectRegex(project, requireBrackets = false) {
33+
if (requireBrackets) {
34+
return new RegExp(`\\[${project}-\\d*\\]`);
35+
}
36+
return new RegExp(`${project}[-_]\\d*`);
3337
}
3438

3539
Toolkit.run(
@@ -59,7 +63,7 @@ Toolkit.run(
5963
const title_passed = (() => {
6064
if (config.check_title) {
6165
// check the title matches [PROJECT-1234] somewhere
62-
if (!projects.some((project) => title.match(createWrappedProjectRegex(project)))) {
66+
if (!projects.some((project) => title.match(createWrappedProjectRegex(project, config.require_brackets)))) {
6367
tools.log(`PR title ${title} does not contain approved project with format [PROJECT-1234]`);
6468
return false;
6569
}

index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ describe('pr-lint-action', () => {
7575
const good_title_and_bad_branch = { title: '[PROJ-1234] a good PR title', ref_name: 'fix_things' };
7676
const bad_title_and_good_branch = { title: 'no ticket in me', ref_name: 'bug/PROJ_1234/a_good_branch' };
7777
const lower_case_good_title_and_branch = { title: '[proj-1234] a lower case good title', ref_name: 'bug/proj_1234/a_good_lowercase_branch' };
78+
const no_brackets_title_and_branch = { title: 'PROJ-1234 a good no brackets PR title', ref_name: 'bug/PROJ-1234/a_good_branch' };
79+
7880
const good_commits = [
7981
{ commit: { message: 'PROJ-1234 Commit 1' } },
8082
{ commit: { message: 'PROJ-1234 Commit 2' } },
@@ -339,4 +341,30 @@ describe('pr-lint-action', () => {
339341
expect(tools.exit.failure).toHaveBeenCalledWith('PR Linting Failed');
340342
expect.assertions(1);
341343
});
344+
345+
it('passes if require_brackets is false and title matches without brackets', async () => {
346+
nock('https://api.github.com')
347+
.get(/\/repos\/vijaykramesh\/.*/)
348+
.query(true)
349+
.reply(200, configFixture('no-brackets.yml'));
350+
351+
tools.context.payload = pullRequestOpenedFixture(no_brackets_title_and_branch);
352+
353+
await action(tools);
354+
expect(tools.exit.success).toHaveBeenCalled();
355+
expect.assertions(1);
356+
});
357+
358+
it('fails if require_brackets is true or default and title matches without brackets', async () => {
359+
nock('https://api.github.com')
360+
.get(/\/repos\/vijaykramesh\/.*/)
361+
.query(true)
362+
.reply(200, configFixture('title.yml'));
363+
364+
tools.context.payload = pullRequestOpenedFixture(no_brackets_title_and_branch);
365+
366+
await action(tools);
367+
expect(tools.exit.failure).toHaveBeenCalledWith('PR Linting Failed');
368+
expect.assertions(1);
369+
});
342370
});

0 commit comments

Comments
 (0)