diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml index f3c59ad54f8..cdafa085cab 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 d5f275d27f1..6f0df01e2a7 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 = /^(WIP:?\s*)?((ARROW|PARQUET|GH)-\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] } - return matched[2]; + return null; } /** @@ -69,8 +72,38 @@ 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, issueID, context) { + // TODO + return github.rest.issues.get({ + issue_number: issueID, + owner: context.repo.owner, + repo: context.repo.repo, + }) +} + +/** + * 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 }; \ 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 73% rename from .github/workflows/dev_pr/jira_check.js rename to .github/workflows/dev_pr/issue_check.js index 3c294f8c7a0..7df6a8f32ed 100644 --- a/.github/workflows/dev_pr/jira_check.js +++ b/.github/workflows/dev_pr/issue_check.js @@ -78,11 +78,36 @@ async function commentNotStartedTicket(github, context, pullRequestNumber) { } } +async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) { + const issue = await github.issues.get({ + issue_number: issueID, + owner: context.repo.owner, + repo: context.repo.repo, + }) + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: ":warning: Ticket **has not been started in JIRA**, please click 'Start Progress'." + issue + }) + //if(!ticketInfo["fields"]["components"].length) { + // await commentMissingComponents(github, context, pullRequestNumber); + //} + + //if(ticketInfo["fields"]["status"]["id"] == 1) { + // // "status": {"name":"Open","id":"1" + // // "description":"The issue is open and ready for the assignee to start work on it.", + // await commentNotStartedTicket(github, context, pullRequestNumber); + //} +} + 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 404ff46436f..5434a492fac 100644 --- a/.github/workflows/dev_pr/link.js +++ b/.github/workflows/dev_pr/link.js @@ -51,11 +51,28 @@ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) { }); } +async function commentGitHubURL(github, context, pullRequestNumber, issueID) { + // TODO: Change url and probably use the issues endpoint to retrieve it + const issueURL = `https://github.com/raulcd/arrow/issues/${issueID}`; + // TODO: Check if comment is already there + //if (await haveComment(github, context, pullRequestNumber, jiraURL)) { + // return; + //} + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pullRequestNumber, + body: issueURL + }); +} + 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 392108269d8..1261e9906fc 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 1db9fcf637b..81dbe4819bb 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: + + JIRA-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY} + See also: * [Other pull requests](https://github.com/apache/arrow/pulls/)