Skip to content

Commit

Permalink
Add new PR title check for GitHub issues and GitHub issue validation
Browse files Browse the repository at this point in the history
  • Loading branch information
raulcd committed Nov 24, 2022
1 parent c33bdab commit ceb9011
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dev_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
55 changes: 47 additions & 8 deletions .github/workflows/dev_pr/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
25 changes: 22 additions & 3 deletions .github/workflows/dev_pr/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
6 changes: 3 additions & 3 deletions .github/workflows/dev_pr/title_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
};
12 changes: 8 additions & 4 deletions .github/workflows/dev_pr/title_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down

0 comments on commit ceb9011

Please sign in to comment.