From cef985d0f0ac2d45a066e74f372012b487564d06 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 16 Dec 2024 15:52:25 -0800 Subject: [PATCH 1/5] Add Github action to ensure PR's have an associated issue --- .github/workflows/pr-file-check.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index be55f4ad2f3b..7b5fdfa550bb 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -42,3 +42,15 @@ jobs: .github/test_plan.md skip-label: 'skip tests' failure-message: 'TypeScript code was edited without also editing a ${file-pattern} file; see the Testing page in our wiki on testing guidelines (the ${skip-label} label can be used to pass this check)' + + - name: 'Ensure PR has an associated issue' + uses: actions/github-script@v6 + with: + script: | + const labels = context.payload.pull_request.labels.map(label => label.name); + if (!labels.includes('skip-issue-check')) { + const issueNumber = context.payload.pull_request.body.match(/#(\d+)/); + if (!issueNumber) { + core.setFailed('No associated issue found in the PR description.'); + } + } From 51341d5d3b5f53278108c47c8c92e3ca477bc1a5 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 16 Dec 2024 15:56:05 -0800 Subject: [PATCH 2/5] update regex --- .github/workflows/pr-file-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index 7b5fdfa550bb..c38d586c31d5 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -49,7 +49,7 @@ jobs: script: | const labels = context.payload.pull_request.labels.map(label => label.name); if (!labels.includes('skip-issue-check')) { - const issueNumber = context.payload.pull_request.body.match(/#(\d+)/); + const issueNumber = context.payload.pull_request.body.match(/#\d+/); if (!issueNumber) { core.setFailed('No associated issue found in the PR description.'); } From b39ca7dbf0f0ae0159e0397488f8aa0a00090edd Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 16 Dec 2024 15:57:50 -0800 Subject: [PATCH 3/5] logging --- .github/workflows/pr-file-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index c38d586c31d5..23ce4894c766 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -48,6 +48,7 @@ jobs: with: script: | const labels = context.payload.pull_request.labels.map(label => label.name); + console.log('PR Body:', context.payload.pull_request.body); if (!labels.includes('skip-issue-check')) { const issueNumber = context.payload.pull_request.body.match(/#\d+/); if (!issueNumber) { From 785293c000cbb84c4009a960b905b997c2c58660 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 16 Dec 2024 16:00:01 -0800 Subject: [PATCH 4/5] add support for link --- .github/workflows/pr-file-check.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index 23ce4894c766..79cd0b2cd957 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -3,11 +3,9 @@ name: PR files on: pull_request: types: - # On by default if you specify no types. - 'opened' - 'reopened' - 'synchronize' - # For `skip-label` only. - 'labeled' - 'unlabeled' @@ -50,8 +48,8 @@ jobs: const labels = context.payload.pull_request.labels.map(label => label.name); console.log('PR Body:', context.payload.pull_request.body); if (!labels.includes('skip-issue-check')) { - const issueNumber = context.payload.pull_request.body.match(/#\d+/); - if (!issueNumber) { + const issueLink = context.payload.pull_request.body.match(/https:\/\/github\.com\/\S+\/issues\/\d+/); + if (!issueLink) { core.setFailed('No associated issue found in the PR description.'); } } From 645bfcb2e843df7c91619abbc7283982e4ac914b Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Mon, 16 Dec 2024 16:01:23 -0800 Subject: [PATCH 5/5] remove log --- .github/workflows/pr-file-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index 79cd0b2cd957..4e32915955ea 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -46,7 +46,6 @@ jobs: with: script: | const labels = context.payload.pull_request.labels.map(label => label.name); - console.log('PR Body:', context.payload.pull_request.body); if (!labels.includes('skip-issue-check')) { const issueLink = context.payload.pull_request.body.match(/https:\/\/github\.com\/\S+\/issues\/\d+/); if (!issueLink) {