From a9fcc1eebdf68758ed741a0828e1c822a3b3177e Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 2 Oct 2024 15:09:33 -0600 Subject: [PATCH 1/5] chore: rollback mutliple projectKey support --- .github/actions/jira-find-marker/action.yaml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/actions/jira-find-marker/action.yaml b/.github/actions/jira-find-marker/action.yaml index b0df2bf7..f4ddf529 100644 --- a/.github/actions/jira-find-marker/action.yaml +++ b/.github/actions/jira-find-marker/action.yaml @@ -6,7 +6,7 @@ inputs: description: The Github PR body required: true type: string - projectKeys: + projectKey: description: The Jira project keys to look for (comma delimited) required: true type: string @@ -32,21 +32,9 @@ runs: return; } - const projectKeys = `${{ inputs.projectKeys }}`.split(',').map(env => env.trim()).filter(b => b.length > 0); - - let markerMatch = null; - projectKeys.find(projectKey => { - console.log('Searching for Jira marker in PR body for project key:', projectKey); - const markerRegex = new RegExp(`[\\s\\S]+\\s+---\\s+`); - const matchResult = pullRequestBody.match(markerRegex); - if (matchResult && matchResult.length >= 2) { - markerMatch = matchResult; - return true; - } - return false; - }); - - if (!markerMatch) { + const markerRegex = new RegExp(`[\\s\\S]+\\s+---\\s+`); + const markerMatch = pullRequestBody.match(markerRegex); + if (!markerMatch || markerMatch.length < 2) { console.log('No Jira marker found in PR body'); return; } From f145524d84fe3c1b48ecbd539395647793e352f8 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 2 Oct 2024 15:13:40 -0600 Subject: [PATCH 2/5] rollback --- .../jira-validate-reference/action.yaml | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/actions/jira-validate-reference/action.yaml b/.github/actions/jira-validate-reference/action.yaml index e571bf09..29389dc9 100644 --- a/.github/actions/jira-validate-reference/action.yaml +++ b/.github/actions/jira-validate-reference/action.yaml @@ -6,7 +6,7 @@ description: | the PR body (or update the existing summary if it already exists). inputs: - projectKeys: + projectKey: description: The Jira project keys to look for (comma delimited) required: true type: string @@ -68,34 +68,26 @@ runs: script: | const prBody = ${{ steps.getPullRequest.outputs.prBody }}; const prTitle = ${{ steps.getPullRequest.outputs.prTitle }}; - const projectKeys = `${{ inputs.projectKeys }}`.split(',').map(env => env.trim()).filter(b => b.length > 0); - if (projectKeys.length === 0) { - throw new Error('No projectKeys provided'); - } - - const issueRegexes = projectKeys.map(projectKey => new RegExp(`${projectKey}-\\d+`)); let jiraIssueRef = null; + const issueRegex = new RegExp(`${{ inputs.projectKey }}-\\d+`); [ { label: 'branch', value: '${{ github.head_ref }}' }, { label: 'title', value: prTitle }, { label: 'body', value: prBody }, ].find(({label, value}) => { - const found = issueRegexes.find(issueRegex => { - const match = value.match(issueRegex); - if (match) { - jiraIssueRef = match[0]; - console.log(`Found Jira issue reference in PR ${label}: ${jiraIssueRef}`); - return true; - } - return false; - }); - return found; + const match = value.match(issueRegex); + if (match) { + jiraIssueRef = match[0]; + console.log(`Found Jira issue reference in PR ${label}: ${jiraIssueRef}`); + return true; + } + return false; }); const ownerAndRepo = '${{ github.repository }}'; const [owner, repo] = ownerAndRepo.split('/'); - const noJiraIssueBody = `No Jira issue reference found in branch, title, or body of PR.\n\nPlease add a reference to a Jira issue in the form of PROJECTKEY-#### (eg: ${projectKeys[0]}-1234) to the branch name, title, or body of your PR.`; + const noJiraIssueBody = `No Jira issue reference found in branch, title, or body of PR.\n\nPlease add a reference to a Jira issue in the form of ${{ inputs.projectKey }}-#### (eg: ${{ inputs.projectKey }}-1234) to the branch name, title, or body of your PR.`; const { data: comments } = await github.rest.issues.listComments({ owner, @@ -149,10 +141,10 @@ runs: - name: Find Jira Marker id: findJiraMarker if: steps.checkIfJobShouldRun.outputs.result == 'true' - uses: chanzuckerberg/github-actions/.github/actions/jira-find-marker@885251a38b81dbb9b6ab0b106dc31ec2f5703764 + uses: chanzuckerberg/github-actions/.github/actions/jira-find-marker@a9fcc1eebdf68758ed741a0828e1c822a3b3177e with: pullRequestBody: ${{ steps.getPullRequest.outputs.prBody }} - projectKeys: ${{ inputs.projectKeys }} + projectKey: ${{ inputs.projectKey }} - name: Update PR Body uses: actions/github-script@v7 From e4f8fa1717c69c1c5ade31c2c273616de0459fc7 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 2 Oct 2024 15:19:48 -0600 Subject: [PATCH 3/5] fix --- .github/actions/jira-validate-reference/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/jira-validate-reference/action.yaml b/.github/actions/jira-validate-reference/action.yaml index 29389dc9..3681dca2 100644 --- a/.github/actions/jira-validate-reference/action.yaml +++ b/.github/actions/jira-validate-reference/action.yaml @@ -96,7 +96,7 @@ runs: }) for (let comment of comments) { - if (comment.body === noJiraIssueBody) { + if (comment.body === noJiraIssueBody && user.type === 'Bot') { console.log('Found comment:', JSON.stringify(comment, null, 2)); await github.rest.issues.deleteComment({ owner, @@ -113,7 +113,7 @@ runs: issue_number: ${{ github.event.pull_request.number }}, body: noJiraIssueBody, }); - throw new Error(body); + throw new Error(noJiraIssueBody); } return jiraIssueRef; From 9031c48386d1421f0ea8591fb082d44c894efd15 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 2 Oct 2024 15:22:14 -0600 Subject: [PATCH 4/5] fix user --- .github/actions/jira-validate-reference/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/jira-validate-reference/action.yaml b/.github/actions/jira-validate-reference/action.yaml index 3681dca2..2a2e6fb8 100644 --- a/.github/actions/jira-validate-reference/action.yaml +++ b/.github/actions/jira-validate-reference/action.yaml @@ -96,7 +96,7 @@ runs: }) for (let comment of comments) { - if (comment.body === noJiraIssueBody && user.type === 'Bot') { + if (comment.body === noJiraIssueBody && comment.user.type === 'Bot') { console.log('Found comment:', JSON.stringify(comment, null, 2)); await github.rest.issues.deleteComment({ owner, From 510b3343bcd503f3d46321b142d7af30adeb1462 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 2 Oct 2024 15:24:18 -0600 Subject: [PATCH 5/5] comment --- .github/actions/jira-validate-reference/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/jira-validate-reference/action.yaml b/.github/actions/jira-validate-reference/action.yaml index 2a2e6fb8..958e3d94 100644 --- a/.github/actions/jira-validate-reference/action.yaml +++ b/.github/actions/jira-validate-reference/action.yaml @@ -97,7 +97,7 @@ runs: for (let comment of comments) { if (comment.body === noJiraIssueBody && comment.user.type === 'Bot') { - console.log('Found comment:', JSON.stringify(comment, null, 2)); + console.log('Found comment to delete:', JSON.stringify(comment, null, 2)); await github.rest.issues.deleteComment({ owner, repo,