Skip to content

Commit

Permalink
feat(semantic-pr-footer): allow omission of colon in footer prefixes (#…
Browse files Browse the repository at this point in the history
…196)

Closes #195
  • Loading branch information
dbjorge authored Aug 19, 2024
1 parent 8c96b10 commit c24bef3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/actions/semantic-pr-footer-v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
## Allowable footers
The footer of a PR will fail unless it [_starts with_ one of the following strings (case insensitive)](https://github.com/dequelabs/axe-api-team-public/blob/main/.github/actions/semantic-pr-footer-v1/src/isValidFooter.ts#L1):
The footer of a PR will fail unless it [_starts with_ one of the following strings (case insensitive, and the colon may be omitted)](https://github.com/dequelabs/axe-api-team-public/blob/main/.github/actions/semantic-pr-footer-v1/src/isValidFooter.ts#L1):
- "close: "
- "closes: "
Expand Down
34 changes: 17 additions & 17 deletions .github/actions/semantic-pr-footer-v1/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29235,25 +29235,25 @@ const run_1 = __importDefault(__nccwpck_require__(1738));

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports["default"] = isValidFooter;
const validFooters = [
'close: ',
'closes: ',
'closed: ',
'fix: ',
'fixes: ',
'fixed: ',
'resolve: ',
'resolves: ',
'resolved: ',
'ref: ',
'refs: ',
'qa notes: ',
'no qa required',
'no qa needed'
const validFooterPrefixes = [
'close',
'closes',
'closed',
'fix',
'fixes',
'fixed',
'resolve',
'resolves',
'resolved',
'ref',
'refs',
'qa notes'
];
const validFooters = ['no qa needed', 'no qa required'];
const validFooterPrefixRegex = new RegExp(`^(${validFooterPrefixes.join('|')}):? `, 'i');
const validFooterRegex = new RegExp(`^(${validFooters.join('|')})`, 'i');
function isValidFooter(footer) {
footer = footer.toLowerCase();
return validFooters.some(term => footer.startsWith(term));
return validFooterRegex.test(footer) || validFooterPrefixRegex.test(footer);
}


Expand Down
91 changes: 36 additions & 55 deletions .github/actions/semantic-pr-footer-v1/src/isValidFooter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,42 @@ import { assert } from 'chai'
import isValidFooter from './isValidFooter'

describe('isValidFooter', () => {
it('returns true for "Close: "', () => {
assert.isTrue(isValidFooter('Closes: '))
})

it('returns true for "Closes: "', () => {
assert.isTrue(isValidFooter('Closes: '))
})

it('returns true for "Closed: "', () => {
assert.isTrue(isValidFooter('Closes: '))
})

it('returns true for "Fix: "', () => {
assert.isTrue(isValidFooter('Fix: '))
})

it('returns true for "Fixes: "', () => {
assert.isTrue(isValidFooter('Fixes: '))
})

it('returns true for "Fixed: "', () => {
assert.isTrue(isValidFooter('Fixed: '))
})

it('returns true for "resolve: "', () => {
assert.isTrue(isValidFooter('resolves: '))
})

it('returns true for "resolves: "', () => {
assert.isTrue(isValidFooter('resolves: '))
})

it('returns true for "resolved: "', () => {
assert.isTrue(isValidFooter('resolved: '))
})

it('returns true for "Ref: "', () => {
assert.isTrue(isValidFooter('Ref: '))
})

it('returns true for "Refs: "', () => {
assert.isTrue(isValidFooter('Refs: '))
})

it('returns true for "QA Notes: "', () => {
assert.isTrue(isValidFooter('QA Notes: '))
})

it('returns true for "No QA required"', () => {
assert.isTrue(isValidFooter('No QA required'))
})

it('returns true for "No QA needed"', () => {
assert.isTrue(isValidFooter('No QA needed'))
})
const validCases = [
'Close ',
'Close: ',
'Closes ',
'Closes: ',
'Closed ',
'Closed: ',
'fix ',
'Fix: ',
'Fixes ',
'Fixes: ',
'Fixed ',
'Fixed: ',
'Resolve ',
'Resolve: ',
'Resolves ',
'Resolves: ',
'Resolved ',
'Resolved: ',
'Ref ',
'Ref: ',
'Refs ',
'Refs: ',
'QA Notes ',
'QA Notes: ',
'No QA required',
'No QA needed',
'No QA required (test only)',
'No QA needed: validate as part of separate ticket'
]

for (const validCase of validCases) {
it(`returns true for "${validCase}"`, () => {
assert.isTrue(isValidFooter(validCase))
})
}

it('returns false for empty footer', () => {
assert.isFalse(isValidFooter(''))
Expand Down
46 changes: 25 additions & 21 deletions .github/actions/semantic-pr-footer-v1/src/isValidFooter.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
const validFooters = [
// github terms that link an issue
// These must appear with a suffix (eg, "fix #123" or "QA Notes: test X, Y, and Z")
const validFooterPrefixes = [
// Should accept all github terms that link an issue
// @see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
'close: ',
'closes: ',
'closed: ',
'fix: ',
'fixes: ',
'fixed: ',
'resolve: ',
'resolves: ',
'resolved: ',

// additional allowed terms
'ref: ',
'refs: ',
'qa notes: ',
'no qa required',
'no qa needed'
'close',
'closes',
'closed',
'fix',
'fixes',
'fixed',
'resolve',
'resolves',
'resolved',
// Additional allowed terms
'ref',
'refs',
'qa notes'
]

export default function isValidFooter(footer: string): boolean {
footer = footer.toLowerCase()
// These may appear alone or with a suffix (eg, "no qa needed" or "no qa needed (test only)")
const validFooters = ['no qa needed', 'no qa required']

return validFooters.some(term => footer.startsWith(term))
const validFooterPrefixRegex = new RegExp(
`^(${validFooterPrefixes.join('|')}):? `,
'i'
)
const validFooterRegex = new RegExp(`^(${validFooters.join('|')})`, 'i')
export default function isValidFooter(footer: string): boolean {
return validFooterRegex.test(footer) || validFooterPrefixRegex.test(footer)
}

0 comments on commit c24bef3

Please sign in to comment.