Skip to content

Commit

Permalink
feat: add github issues link to regex (#385)
Browse files Browse the repository at this point in the history
* feat: add github issues link to regex. fixes #384.
  • Loading branch information
a0m0rajab committed Sep 25, 2023
1 parent b40d80a commit 11b664f
Show file tree
Hide file tree
Showing 6 changed files with 4,088 additions and 27,405 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repo-token | `secrets.GITHUB_TOKEN` | Access token for which this action will ru
ignore-authors | dependabot<br/>dependabot[bot] | If the action detects that the PR author is one of these logins, it will skip checks and set all outputs to `true`.
base-comment | (see [action.yml](./action.yml)) | Preamble to any comment the action leaves on the PR.
ignore-team-members | true | Whether to ignore in the case that the PR author is a) the owner of repository, or b) has a public membership[^1] in the org that owns the repository.
body-regex | `(fix(es\|ed)?\|((resolve\|close)(s\|d)?)) #\d*[1-9]\d*` | Regular expression to identify whether the PR body refers to an issue[^2][^3].
body-regex | (see [action.yml](./action.yml)) | Regular expression to identify whether the PR body refers to an issue[^2][^3].
body-fail | false | Whether to trigger a failing check when the body-regex is not matched in the PR body. Triggers a warning by default.
body-auto-close | true | Whether or not to auto-close on failed check of PR Body
body-comment | (see [action.yml](./action.yml)) | Comment to leave on PR on failed check of PR Body
Expand Down
17 changes: 17 additions & 0 deletions __tests__/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ No issue, just passing thru.
`
const goodBody =
'# Fix for lint error\n\nThis PR fixes #123\n\nNo post-deploy tasks.'
const goodBodyWithLink =
'# Fix for lint error\n\nThis PR fixes https://github.com/mtfoley/pr-compliance-action/issues/384\n\nNo post-deploy tasks.'
const badBodyWithLink =
'# Fix for lint error\n\nThis PR fixes https://opensauced.pizza/bdougie/oven/issues/384\n\nanother fun project!.'

test('checkBody false on empty', () => {
const regexString = '(fixes|closes) #d+'
const check = checkBody('', regexString)
Expand All @@ -34,6 +39,18 @@ test('checkBody true on valid message with multiline', () => {
const check = checkBody(goodBody, regexString)
expect(check).toBeTruthy()
})
test('checkBody true on valid message with issue link', () => {
const regexString =
'(fix(es|ed)?|((resolve|close)(s|d)?)) ((https://github.com/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/issues/d*[1-9]d*?)|(#d*[1-9]d*?))'
const check = checkBody(goodBodyWithLink, regexString)
expect(check).toBeTruthy()
})
test('checkBody false on flase positive with link', () => {
const regexString =
'(fix(es|ed)?|((resolve|close)(s|d)?)) ((https://github.com/[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+/issues/d*[1-9]d*?)|(#d*[1-9]d*?))'
const check = checkBody(badBodyWithLink, regexString)
expect(check).toBeFalsy()
})
test('checkTitle false on empty', async () => {
const {valid, errors} = await checkTitle('')
expect(valid).toBeFalsy()
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inputs:
body-regex:
required: true
description: 'PR Body Regex'
default: '(fix(es|ed)?|((resolve|close)(s|d)?)) #\d*[1-9]\d*'
default: '(fix(es|ed)?|((resolve|close)(s|d)?)) ((https:\/\/github.com\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+\/issues\/d*[1-9]d*?)|(#d*[1-9]d*?))'
body-fail:
required: true
description: >
Expand Down
Loading

0 comments on commit 11b664f

Please sign in to comment.