From eed5505bc8cb89dc6c6c7ea12d3653a8ee579069 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 13 Apr 2024 12:10:56 -0500 Subject: [PATCH 1/7] ci(pr-name-check): integrates pr naming convention into workflow --- .github/workflows/pr-naming-check.yml | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/pr-naming-check.yml diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml new file mode 100644 index 0000000000..31e2f1bba5 --- /dev/null +++ b/.github/workflows/pr-naming-check.yml @@ -0,0 +1,40 @@ +name: Pull Request Title Validation + +on: + pull_request: + types: [opened, reopened, edited] + +jobs: + pull-request-title-validation: + runs-on: ubuntu-latest + + steps: + - name: Check PR title format + id: check_title + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const titleRegex = /^(Revert \")?(feat|build|chore|style|fix|update|ci)\((\w|\/|-)+\)\:.+/g; + const title = context.payload.pull_request.title; + const isValid = titleRegex.test(title); + if (!isValid) { + console.error(`PR title "${title}" doesn't match the required format.`); + } + return isValid; + + - name: Leave comment for OP + if: steps.check_title.outputs.result == 'false' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.payload.pull_request.number; + const author = context.payload.pull_request.user.login; + const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(): "`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: message + }); From f128cf6b1920bfcf06b887949c3ebc1c59cbbeb4 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 13 Apr 2024 13:29:58 -0500 Subject: [PATCH 2/7] fix(workflow): adds synchronize for additional commit to fail --- .github/workflows/pr-naming-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 31e2f1bba5..b42d7d6cc9 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -2,7 +2,7 @@ name: Pull Request Title Validation on: pull_request: - types: [opened, reopened, edited] + types: [opened, reopened, edited, synchronize] jobs: pull-request-title-validation: From bb656cdaffe2b08fa58cf50650b721ef077a55e0 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 13 Apr 2024 13:56:40 -0500 Subject: [PATCH 3/7] add(leave-comment): does not comment on commits Co-Authored-By: nuxen <47067662+nuxencs@users.noreply.github.com> --- .github/workflows/pr-naming-check.yml | 32 +++++++++++---------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index b42d7d6cc9..96976067f9 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check PR title format + - name: Validate Pull Request Title id: check_title uses: actions/github-script@v7 with: @@ -19,22 +19,16 @@ jobs: const title = context.payload.pull_request.title; const isValid = titleRegex.test(title); if (!isValid) { - console.error(`PR title "${title}" doesn't match the required format.`); + if ((context.payload.action === 'opened') || (context.payload.action === 'reopened')) { + const prNumber = context.payload.pull_request.number; + const author = context.payload.pull_request.user.login; + const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(): "`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: message + }); + } + core.setFailed(`PR title "${title}" doesn't match the required format.`) } - return isValid; - - - name: Leave comment for OP - if: steps.check_title.outputs.result == 'false' - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const prNumber = context.payload.pull_request.number; - const author = context.payload.pull_request.user.login; - const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(): "`; - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: message - }); From ba7fc82042ac63acea06fc652262e8b8becbfc16 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 13 Apr 2024 16:09:24 -0500 Subject: [PATCH 4/7] update(regex): adds keywords and cleanup Co-Authored-By: nuxen <47067662+nuxencs@users.noreply.github.com> --- .github/workflows/pr-naming-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 96976067f9..0a5759dfcf 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -15,7 +15,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const titleRegex = /^(Revert \")?(feat|build|chore|style|fix|update|ci)\((\w|\/|-)+\)\:.+/g; + const titleRegex = /^(Revert \")?(feat|fix|docs|style|refactor|perf|test|update|build|ci|chore)(\([\w\/-]+\))?:\s.+$/g; const title = context.payload.pull_request.title; const isValid = titleRegex.test(title); if (!isValid) { From 6f1844a2d75ad73753f96e573035be6578b44fbb Mon Sep 17 00:00:00 2001 From: zakary Date: Sun, 14 Apr 2024 08:47:58 -0500 Subject: [PATCH 5/7] fix(perms): adds write access for pr and issues Co-Authored-By: nuxen <47067662+nuxencs@users.noreply.github.com> --- .github/workflows/pr-naming-check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 0a5759dfcf..7573af5f8d 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -4,6 +4,10 @@ on: pull_request: types: [opened, reopened, edited, synchronize] +permissions: + issues: write + pull-requests: write + jobs: pull-request-title-validation: runs-on: ubuntu-latest From 2698336649144d33654274c0802fe9e2a28bcc55 Mon Sep 17 00:00:00 2001 From: zakary Date: Sun, 14 Apr 2024 08:54:07 -0500 Subject: [PATCH 6/7] update(formatting): link and escaped chars Co-Authored-By: nuxen <47067662+nuxencs@users.noreply.github.com> --- .github/workflows/pr-naming-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 7573af5f8d..344a2e9376 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -26,7 +26,7 @@ jobs: if ((context.payload.action === 'opened') || (context.payload.action === 'reopened')) { const prNumber = context.payload.pull_request.number; const author = context.payload.pull_request.user.login; - const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(): "`; + const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our [naming conventions](https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(\\): \\"`; github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, From e00de28a15a0b4d134096aae1804e6d2beb83de3 Mon Sep 17 00:00:00 2001 From: zakary Date: Sun, 14 Apr 2024 09:31:04 -0500 Subject: [PATCH 7/7] add(regex101): adds test link for convention we accept Co-Authored-By: nuxen <47067662+nuxencs@users.noreply.github.com> --- .github/workflows/pr-naming-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml index 344a2e9376..219d64c116 100644 --- a/.github/workflows/pr-naming-check.yml +++ b/.github/workflows/pr-naming-check.yml @@ -26,7 +26,7 @@ jobs: if ((context.payload.action === 'opened') || (context.payload.action === 'reopened')) { const prNumber = context.payload.pull_request.number; const author = context.payload.pull_request.user.login; - const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our [naming conventions](https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(\\): \\"`; + const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our [naming conventions](https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(\\): \\\n\nYou can check your title at this [regex101 link](https://regex101.com/r/jOZ6kU/1)."`; github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo,