Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github issues link to regex #385

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.'
a0m0rajab marked this conversation as resolved.
Show resolved Hide resolved
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
Loading