From ffc409f454caa108ba0f345529a0bb93264e3df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Thu, 24 Nov 2022 15:30:48 +0100 Subject: [PATCH 1/7] Add new PR title check for GitHub issues and GitHub issue validation --- .github/workflows/dev_pr.yml | 4 +- .github/workflows/dev_pr/helpers.js | 55 ++++++++++++++++--- .../dev_pr/{jira_check.js => issue_check.js} | 37 ++++++++++++- .github/workflows/dev_pr/link.js | 25 ++++++++- .github/workflows/dev_pr/title_check.js | 6 +- .github/workflows/dev_pr/title_check.md | 12 ++-- 6 files changed, 116 insertions(+), 23 deletions(-) rename .github/workflows/dev_pr/{jira_check.js => issue_check.js} (68%) diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml index f3c59ad54f8f..cdafa085cab9 100644 --- a/.github/workflows/dev_pr.yml +++ b/.github/workflows/dev_pr.yml @@ -66,7 +66,7 @@ jobs: const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/title_check.js`); script({github, context}); - - name: Check Jira Issue + - name: Check Issue if: | (github.event.action == 'opened' || github.event.action == 'edited') @@ -75,7 +75,7 @@ jobs: debug: true github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/jira_check.js`); + const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/issue_check.js`); script({github, context}); - name: Assign GitHub labels diff --git a/.github/workflows/dev_pr/helpers.js b/.github/workflows/dev_pr/helpers.js index d5f275d27f19..39d164f31923 100644 --- a/.github/workflows/dev_pr/helpers.js +++ b/.github/workflows/dev_pr/helpers.js @@ -18,19 +18,22 @@ const https = require('https'); /** - * Given the title of a PullRequest return the ID of the JIRA issue + * Given the title of a PullRequest return the ID of the JIRA or GitHub issue * @param {String} title - * @returns {String} the ID of the associated JIRA issue + * @returns {String} the ID of the associated JIRA or GitHub issue */ -function detectJIRAID(title) { +function detectIssueID(title) { if (!title) { return null; } const matched = /^(WIP:?\s*)?((ARROW|PARQUET)-\d+)/.exec(title); - if (!matched) { - return null; + const matched_gh = /^(WIP:?\s*)?(GH-)(\d+)/.exec(title); + if (matched) { + return matched[2]; + } else if (matched_gh) { + return matched_gh[3] } - return matched[2]; + return null; } /** @@ -69,8 +72,44 @@ async function getJiraInfo(jiraID) { }); } +/** + * Retrieves information about a GitHub issue. + * @param {String} issueID + * @returns {Object} the information about a GitHub issue. + */ + async function getGitHubInfo(github, context, issueID, pullRequestNumber) { + try { + const response = await github.issues.get({ + issue_number: issueID, + owner: context.repo.owner, + repo: context.repo.repo, + }) + return response.data + } catch (error) { + console.log(`${error.name}: ${error.code}`); + return false + } +} + +/** + * Given the title of a PullRequest checks if it contains a GitHub issue ID + * @param {String} title + * @returns {Boolean} true if title starts with a GitHub ID or MINOR: + */ + function haveGitHubIssueID(title) { + if (!title) { + return false; + } + if (title.startsWith("MINOR: ")) { + return true; + } + return /^(WIP:?\s*)?(GH)-\d+/.test(title); +} + module.exports = { - detectJIRAID, + detectIssueID, haveJIRAID, - getJiraInfo + getJiraInfo, + haveGitHubIssueID, + getGitHubInfo }; \ No newline at end of file diff --git a/.github/workflows/dev_pr/jira_check.js b/.github/workflows/dev_pr/issue_check.js similarity index 68% rename from .github/workflows/dev_pr/jira_check.js rename to .github/workflows/dev_pr/issue_check.js index 3c294f8c7a0f..0bdd6428d1a8 100644 --- a/.github/workflows/dev_pr/jira_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -78,11 +78,42 @@ async function commentNotStartedTicket(github, context, pullRequestNumber) { } } +async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { + const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); + if (issueInfo) { + if (!issueInfo.assignees.length) { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: GitHub issue #" + issueID + " **has not been assigned in GitHub**, please assign the ticket." + }) + } + if(!issueInfo.labels.length) { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: GitHub issue #" + issueID + " **has no labels in GitHub**, please add labels for components." + }) + } + } else { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: GitHub issue #" + issueID + " could not be retrieved." + }) + } +} + module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - const jiraID = helpers.detectJIRAID(title); - if (jiraID) { - await verifyJIRAIssue(github, context, pullRequestNumber, jiraID); + const issueID = helpers.detectIssueID(title) + if (helpers.haveJIRAID(title)) { + await verifyJIRAIssue(github, context, pullRequestNumber, issueID); + } else if(helpers.haveGitHubIssueID(title)) { + await verifyGitHubIssue(github, context, pullRequestNumber, issueID); } }; diff --git a/.github/workflows/dev_pr/link.js b/.github/workflows/dev_pr/link.js index 404ff46436f5..520eac0ee4df 100644 --- a/.github/workflows/dev_pr/link.js +++ b/.github/workflows/dev_pr/link.js @@ -51,11 +51,30 @@ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { }); } +async function commentGitHubURL(github, context, pullRequestNumber, issueID) { + // Make the call to ensure issue exists before adding comment + const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); + // TODO: Check if comment is already there + //if (await haveComment(github, context, pullRequestNumber, jiraURL)) { + // return; + //} + if (issueInfo){ + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: "* Github Issue: #" + issueInfo.number + }); + } +} + module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - const jiraID = helpers.detectJIRAID(title); - if (jiraID) { - await commentJIRAURL(github, context, pullRequestNumber, jiraID); + const issueID = helpers.detectIssueID(title); + if (helpers.haveJIRAID(title)) { + await commentJIRAURL(github, context, pullRequestNumber, issueID); + } else if (helpers.haveGitHubIssueID(title)) { + await commentGitHubURL(github, context, pullRequestNumber, issueID); } }; diff --git a/.github/workflows/dev_pr/title_check.js b/.github/workflows/dev_pr/title_check.js index 392108269d8c..1261e9906fc1 100644 --- a/.github/workflows/dev_pr/title_check.js +++ b/.github/workflows/dev_pr/title_check.js @@ -18,7 +18,7 @@ const fs = require("fs"); const helpers = require("./helpers.js"); -async function commentOpenJIRAIssue(github, context, pullRequestNumber) { +async function commentOpenGitHubIssue(github, context, pullRequestNumber) { const {data: comments} = await github.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, @@ -41,7 +41,7 @@ async function commentOpenJIRAIssue(github, context, pullRequestNumber) { module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - if (!helpers.haveJIRAID(title)) { - await commentOpenJIRAIssue(github, context, pullRequestNumber); + if (!helpers.haveJIRAID(title) || !helpers.haveGitHubIssueID(title)) { + await commentOpenGitHubIssue(github, context, pullRequestNumber); } }; diff --git a/.github/workflows/dev_pr/title_check.md b/.github/workflows/dev_pr/title_check.md index 1db9fcf637bb..05501eb1300b 100644 --- a/.github/workflows/dev_pr/title_check.md +++ b/.github/workflows/dev_pr/title_check.md @@ -19,18 +19,22 @@ Thanks for opening a pull request! -If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on JIRA? https://issues.apache.org/jira/browse/ARROW +If this is not a [minor PR](https://github.com/apache/arrow/blob/master/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose -Opening JIRAs ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project. +Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project. -Then could you also rename pull request title in the following format? +Then could you also rename the pull request title in the following format? - ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY} + GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} or MINOR: [${COMPONENT}] ${SUMMARY} +In the case of old issues on JIRA the title also supports: + + ARROW-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} + See also: * [Other pull requests](https://github.com/apache/arrow/pulls/) From a0ef0317418faa2d8218fbed979971253c24eb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Thu, 24 Nov 2022 21:58:14 +0100 Subject: [PATCH 2/7] Add check for existing message --- .github/workflows/dev_pr/link.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dev_pr/link.js b/.github/workflows/dev_pr/link.js index 520eac0ee4df..30f93134aa99 100644 --- a/.github/workflows/dev_pr/link.js +++ b/.github/workflows/dev_pr/link.js @@ -54,16 +54,16 @@ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { async function commentGitHubURL(github, context, pullRequestNumber, issueID) { // Make the call to ensure issue exists before adding comment const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); - // TODO: Check if comment is already there - //if (await haveComment(github, context, pullRequestNumber, jiraURL)) { - // return; - //} + const message = "* Github Issue: #" + issueInfo.number + if (await haveComment(github, context, pullRequestNumber, message)) { + return; + } if (issueInfo){ await github.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pullRequestNumber, - body: "* Github Issue: #" + issueInfo.number + body: message }); } } From 8c27c9df9bce4de1c2d0b79b36db1973ac5a9e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 25 Nov 2022 15:50:28 +0100 Subject: [PATCH 3/7] Add comments to modules, refactor detect issue and autoassign issue on GitHub --- .github/workflows/dev_pr.yml | 1 + .github/workflows/dev_pr/helpers.js | 61 ++++++++----------------- .github/workflows/dev_pr/issue_check.js | 36 ++++++++++----- .github/workflows/dev_pr/link.js | 41 ++++++++++++++--- .github/workflows/dev_pr/title_check.js | 3 +- .github/workflows/dev_pr/title_check.md | 1 + 6 files changed, 82 insertions(+), 61 deletions(-) diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml index cdafa085cab9..1de6cf1b0174 100644 --- a/.github/workflows/dev_pr.yml +++ b/.github/workflows/dev_pr.yml @@ -36,6 +36,7 @@ concurrency: permissions: contents: read pull-requests: write + issues: write jobs: process: diff --git a/.github/workflows/dev_pr/helpers.js b/.github/workflows/dev_pr/helpers.js index 39d164f31923..520ff353291d 100644 --- a/.github/workflows/dev_pr/helpers.js +++ b/.github/workflows/dev_pr/helpers.js @@ -18,37 +18,33 @@ const https = require('https'); /** - * Given the title of a PullRequest return the ID of the JIRA or GitHub issue + * Given the title of a PullRequest return the Issue + * * @param {String} title - * @returns {String} the ID of the associated JIRA or GitHub issue + * @returns {Issue} or null if no issue detected. + * + * @typedef {Object} Issue + * @property {string} kind - The kind of issue: minor, jira or github + * @property {string} id - The id of the issue: + * ARROW-XXXX, PARQUET-XXXX for jira + * The numeric issue id for github */ -function detectIssueID(title) { +function detectIssue(title) { if (!title) { return null; } - const matched = /^(WIP:?\s*)?((ARROW|PARQUET)-\d+)/.exec(title); - const matched_gh = /^(WIP:?\s*)?(GH-)(\d+)/.exec(title); - if (matched) { - return matched[2]; - } else if (matched_gh) { - return matched_gh[3] + if (title.startsWith("MINOR: ")) { + return {"kind": "minor"}; } - return null; -} - -/** - * Given the title of a PullRequest checks if it contains a JIRA issue ID - * @param {String} title - * @returns {Boolean} true if it starts with a JIRA ID or MINOR: - */ -function haveJIRAID(title) { - if (!title) { - return false; + const matched_jira = /^(WIP:?\s*)?((ARROW|PARQUET)-\d+)/.exec(title); + if (matched_jira) { + return {"kind": "jira", "id": matched_jira[2]}; } - if (title.startsWith("MINOR: ")) { - return true; + const matched_gh = /^(WIP:?\s*)?(GH-)(\d+)/.exec(title); + if (matched_gh) { + return {"kind": "github", "id": matched_gh[3]}; } - return /^(WIP:?\s*)?(ARROW|PARQUET)-\d+/.test(title); + return null; } /** @@ -91,25 +87,8 @@ async function getJiraInfo(jiraID) { } } -/** - * Given the title of a PullRequest checks if it contains a GitHub issue ID - * @param {String} title - * @returns {Boolean} true if title starts with a GitHub ID or MINOR: - */ - function haveGitHubIssueID(title) { - if (!title) { - return false; - } - if (title.startsWith("MINOR: ")) { - return true; - } - return /^(WIP:?\s*)?(GH)-\d+/.test(title); -} - module.exports = { - detectIssueID, - haveJIRAID, + detectIssue, getJiraInfo, - haveGitHubIssueID, getGitHubInfo }; \ No newline at end of file diff --git a/.github/workflows/dev_pr/issue_check.js b/.github/workflows/dev_pr/issue_check.js index 0bdd6428d1a8..aae98aaefdf4 100644 --- a/.github/workflows/dev_pr/issue_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -78,16 +78,26 @@ async function commentNotStartedTicket(github, context, pullRequestNumber) { } } +async function assignGitHubIssue(github, context, pullRequestNumber, issueInfo) { + await github.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueInfo.number, + assignees: context.payload.pull_request.user.login + }); + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: GitHub issue #" + issueInfo.number + " **has been automatically assigned in GitHub** to PR creator." + }); +} + async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); if (issueInfo) { if (!issueInfo.assignees.length) { - await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pullRequestNumber, - body: ":warning: GitHub issue #" + issueID + " **has not been assigned in GitHub**, please assign the ticket." - }) + await assignGitHubIssue(github, context, pullRequestNumber, issueInfo); } if(!issueInfo.labels.length) { await github.issues.createComment({ @@ -102,7 +112,7 @@ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { owner: context.repo.owner, repo: context.repo.repo, issue_number: pullRequestNumber, - body: ":warning: GitHub issue #" + issueID + " could not be retrieved." + body: ":x: GitHub issue #" + issueID + " could not be retrieved." }) } } @@ -110,10 +120,12 @@ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - const issueID = helpers.detectIssueID(title) - if (helpers.haveJIRAID(title)) { - await verifyJIRAIssue(github, context, pullRequestNumber, issueID); - } else if(helpers.haveGitHubIssueID(title)) { - await verifyGitHubIssue(github, context, pullRequestNumber, issueID); + const issue = helpers.detectIssue(title) + if (issue){ + if (issue.kind == "jira") { + await verifyJIRAIssue(github, context, pullRequestNumber, issue.id); + } else if(issue.kind == "github") { + await verifyGitHubIssue(github, context, pullRequestNumber, issue.id); + } } }; diff --git a/.github/workflows/dev_pr/link.js b/.github/workflows/dev_pr/link.js index 30f93134aa99..fb58208f7a3a 100644 --- a/.github/workflows/dev_pr/link.js +++ b/.github/workflows/dev_pr/link.js @@ -18,7 +18,16 @@ const helpers = require("./helpers.js"); -async function haveComment(github, context, pullRequestNumber, body) { +/** + * Checks whether message is present on Pull Request list of comments. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + * @param {String} message + * @returns {Boolean} true if message was found. + */ +async function haveComment(github, context, pullRequestNumber, message) { const options = { owner: context.repo.owner, repo: context.repo.repo, @@ -27,7 +36,7 @@ async function haveComment(github, context, pullRequestNumber, body) { }; while (true) { const response = await github.issues.listComments(options); - if (response.data.some(comment => comment.body === body)) { + if (response.data.some(comment => comment.body === message)) { return true; } if (!/;\s*rel="next"/.test(response.headers.link || "")) { @@ -38,6 +47,14 @@ async function haveComment(github, context, pullRequestNumber, body) { return false; } +/** + * Adds a comment on the Pull Request linking the JIRA issue. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + * @param {String} jiraID + */ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { const jiraURL = `https://issues.apache.org/jira/browse/${jiraID}`; if (await haveComment(github, context, pullRequestNumber, jiraURL)) { @@ -51,6 +68,14 @@ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { }); } +/** + * Adds a comment on the Pull Request linking the GitHub issue. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber - String containing numeric id of PR + * @param {String} issueID - String containing numeric id of the github issue + */ async function commentGitHubURL(github, context, pullRequestNumber, issueID) { // Make the call to ensure issue exists before adding comment const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); @@ -71,10 +96,12 @@ async function commentGitHubURL(github, context, pullRequestNumber, issueID) { module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - const issueID = helpers.detectIssueID(title); - if (helpers.haveJIRAID(title)) { - await commentJIRAURL(github, context, pullRequestNumber, issueID); - } else if (helpers.haveGitHubIssueID(title)) { - await commentGitHubURL(github, context, pullRequestNumber, issueID); + const issue = helpers.detectIssue(title); + if (issue){ + if (issue.kind == "jira") { + await commentJIRAURL(github, context, pullRequestNumber, issue.id); + } else if (issue.kind == "github") { + await commentGitHubURL(github, context, pullRequestNumber, issue.id); + } } }; diff --git a/.github/workflows/dev_pr/title_check.js b/.github/workflows/dev_pr/title_check.js index 1261e9906fc1..1b7a6c5c8885 100644 --- a/.github/workflows/dev_pr/title_check.js +++ b/.github/workflows/dev_pr/title_check.js @@ -41,7 +41,8 @@ async function commentOpenGitHubIssue(github, context, pullRequestNumber) { module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; - if (!helpers.haveJIRAID(title) || !helpers.haveGitHubIssueID(title)) { + const issue = helpers.detectIssue(title) + if (!issue) { await commentOpenGitHubIssue(github, context, pullRequestNumber); } }; diff --git a/.github/workflows/dev_pr/title_check.md b/.github/workflows/dev_pr/title_check.md index 05501eb1300b..589a73aaa8ef 100644 --- a/.github/workflows/dev_pr/title_check.md +++ b/.github/workflows/dev_pr/title_check.md @@ -34,6 +34,7 @@ or In the case of old issues on JIRA the title also supports: ARROW-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} + PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} See also: From 6d7dadbf60119397b95e0e47924899d8f0f6ad96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 25 Nov 2022 16:58:58 +0100 Subject: [PATCH 4/7] Add some more comments to issue_check functions --- .github/workflows/dev_pr/issue_check.js | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/dev_pr/issue_check.js b/.github/workflows/dev_pr/issue_check.js index aae98aaefdf4..4328757f6f0e 100644 --- a/.github/workflows/dev_pr/issue_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -17,6 +17,16 @@ const helpers = require("./helpers.js"); +/** + * Performs checks on the JIRA Issue: + * - The issue is started in JIRA. + * - The issue contains components. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + * @param {String} jiraID + */ async function verifyJIRAIssue(github, context, pullRequestNumber, jiraID) { const ticketInfo = await helpers.getJiraInfo(jiraID); if(!ticketInfo["fields"]["components"].length) { @@ -30,6 +40,13 @@ async function verifyJIRAIssue(github, context, pullRequestNumber, jiraID) { } } +/** + * Adds a comment to add components ticket in JIRA. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + */ async function commentMissingComponents(github, context, pullRequestNumber) { const {data: comments} = await github.issues.listComments({ owner: context.repo.owner, @@ -54,6 +71,13 @@ async function commentMissingComponents(github, context, pullRequestNumber) { } } +/** + * Adds a comment to start ticket in JIRA. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + */ async function commentNotStartedTicket(github, context, pullRequestNumber) { const {data: comments} = await github.issues.listComments({ owner: context.repo.owner, @@ -78,6 +102,14 @@ async function commentNotStartedTicket(github, context, pullRequestNumber) { } } +/** + * Assigns the Github Issue to the PR creator. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + * @param {Object} issueInfo + */ async function assignGitHubIssue(github, context, pullRequestNumber, issueInfo) { await github.issues.addAssignees({ owner: context.repo.owner, @@ -93,6 +125,17 @@ async function assignGitHubIssue(github, context, pullRequestNumber, issueInfo) }); } +/** + * Performs checks on the GitHub Issue: + * - The issue is assigned to someone. If not assign it gets automatically + * assigned to the PR creator. + * - The issue contains any label. + * + * @param {Object} github + * @param {Object} context + * @param {String} pullRequestNumber + * @param {String} issueID + */ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); if (issueInfo) { From 4cc26ebf8d594259d1854b7dd8f7c55fad8d7fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Fri, 25 Nov 2022 17:03:00 +0100 Subject: [PATCH 5/7] Fix grammar on comment --- .github/workflows/dev_pr/issue_check.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev_pr/issue_check.js b/.github/workflows/dev_pr/issue_check.js index 4328757f6f0e..9431fa7c9ecc 100644 --- a/.github/workflows/dev_pr/issue_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -41,7 +41,7 @@ async function verifyJIRAIssue(github, context, pullRequestNumber, jiraID) { } /** - * Adds a comment to add components ticket in JIRA. + * Adds a comment to add components on the JIRA ticket. * * @param {Object} github * @param {Object} context @@ -72,7 +72,7 @@ async function commentMissingComponents(github, context, pullRequestNumber) { } /** - * Adds a comment to start ticket in JIRA. + * Adds a comment to start the ticket in JIRA. * * @param {Object} github * @param {Object} context From fe9eb51e4a0aba3282a29f853267f0dec49cdcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 29 Nov 2022 09:44:54 +0100 Subject: [PATCH 6/7] Review comments: check labels are component labels and other minor changes --- .github/workflows/dev_pr/helpers.js | 4 ++-- .github/workflows/dev_pr/issue_check.js | 25 ++++++++++++------------- .github/workflows/dev_pr/link.js | 15 +++++++++------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dev_pr/helpers.js b/.github/workflows/dev_pr/helpers.js index 520ff353291d..282567f95663 100644 --- a/.github/workflows/dev_pr/helpers.js +++ b/.github/workflows/dev_pr/helpers.js @@ -40,9 +40,9 @@ function detectIssue(title) { if (matched_jira) { return {"kind": "jira", "id": matched_jira[2]}; } - const matched_gh = /^(WIP:?\s*)?(GH-)(\d+)/.exec(title); + const matched_gh = /^(WIP:?\s*)?GH-(\d+)/.exec(title); if (matched_gh) { - return {"kind": "github", "id": matched_gh[3]}; + return {"kind": "github", "id": matched_gh[2]}; } return null; } diff --git a/.github/workflows/dev_pr/issue_check.js b/.github/workflows/dev_pr/issue_check.js index 9431fa7c9ecc..87914f733f37 100644 --- a/.github/workflows/dev_pr/issue_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -138,19 +138,7 @@ async function assignGitHubIssue(github, context, pullRequestNumber, issueInfo) */ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber); - if (issueInfo) { - if (!issueInfo.assignees.length) { - await assignGitHubIssue(github, context, pullRequestNumber, issueInfo); - } - if(!issueInfo.labels.length) { - await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pullRequestNumber, - body: ":warning: GitHub issue #" + issueID + " **has no labels in GitHub**, please add labels for components." - }) - } - } else { + if (!issueInfo) { await github.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, @@ -158,6 +146,17 @@ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { body: ":x: GitHub issue #" + issueID + " could not be retrieved." }) } + if (!issueInfo.assignees.length) { + await assignGitHubIssue(github, context, pullRequestNumber, issueInfo); + } + if(!issueInfo.labels.filter((label) => label.startsWith("Component:")).length) { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: GitHub issue #" + issueID + " **has no components**, please add labels for components." + }) + } } module.exports = async ({github, context}) => { diff --git a/.github/workflows/dev_pr/link.js b/.github/workflows/dev_pr/link.js index fb58208f7a3a..7d99ca105312 100644 --- a/.github/workflows/dev_pr/link.js +++ b/.github/workflows/dev_pr/link.js @@ -56,16 +56,19 @@ async function haveComment(github, context, pullRequestNumber, message) { * @param {String} jiraID */ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { + const issueInfo = await helpers.getJiraInfo(jiraID); const jiraURL = `https://issues.apache.org/jira/browse/${jiraID}`; if (await haveComment(github, context, pullRequestNumber, jiraURL)) { return; } - await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pullRequestNumber, - body: jiraURL - }); + if (issueInfo){ + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: jiraURL + }); + } } /** From 3a36abf8a09dad862004fa333082c458f8d925bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 29 Nov 2022 10:06:15 +0100 Subject: [PATCH 7/7] Fix check label. It is an object with name --- .github/workflows/dev_pr/issue_check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev_pr/issue_check.js b/.github/workflows/dev_pr/issue_check.js index 87914f733f37..3dff23f53edc 100644 --- a/.github/workflows/dev_pr/issue_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -149,7 +149,7 @@ async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { if (!issueInfo.assignees.length) { await assignGitHubIssue(github, context, pullRequestNumber, issueInfo); } - if(!issueInfo.labels.filter((label) => label.startsWith("Component:")).length) { + if(!issueInfo.labels.filter((label) => label.name.startsWith("Component:")).length) { await github.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo,