Skip to content

Commit ceb9011

Browse files
committed
Add new PR title check for GitHub issues and GitHub issue validation
1 parent c33bdab commit ceb9011

File tree

6 files changed

+116
-23
lines changed

6 files changed

+116
-23
lines changed

.github/workflows/dev_pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/title_check.js`);
6767
script({github, context});
6868
69-
- name: Check Jira Issue
69+
- name: Check Issue
7070
if: |
7171
(github.event.action == 'opened' ||
7272
github.event.action == 'edited')
@@ -75,7 +75,7 @@ jobs:
7575
debug: true
7676
github-token: ${{ secrets.GITHUB_TOKEN }}
7777
script: |
78-
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/jira_check.js`);
78+
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/issue_check.js`);
7979
script({github, context});
8080
8181
- name: Assign GitHub labels

.github/workflows/dev_pr/helpers.js

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
const https = require('https');
1919

2020
/**
21-
* Given the title of a PullRequest return the ID of the JIRA issue
21+
* Given the title of a PullRequest return the ID of the JIRA or GitHub issue
2222
* @param {String} title
23-
* @returns {String} the ID of the associated JIRA issue
23+
* @returns {String} the ID of the associated JIRA or GitHub issue
2424
*/
25-
function detectJIRAID(title) {
25+
function detectIssueID(title) {
2626
if (!title) {
2727
return null;
2828
}
2929
const matched = /^(WIP:?\s*)?((ARROW|PARQUET)-\d+)/.exec(title);
30-
if (!matched) {
31-
return null;
30+
const matched_gh = /^(WIP:?\s*)?(GH-)(\d+)/.exec(title);
31+
if (matched) {
32+
return matched[2];
33+
} else if (matched_gh) {
34+
return matched_gh[3]
3235
}
33-
return matched[2];
36+
return null;
3437
}
3538

3639
/**
@@ -69,8 +72,44 @@ async function getJiraInfo(jiraID) {
6972
});
7073
}
7174

75+
/**
76+
* Retrieves information about a GitHub issue.
77+
* @param {String} issueID
78+
* @returns {Object} the information about a GitHub issue.
79+
*/
80+
async function getGitHubInfo(github, context, issueID, pullRequestNumber) {
81+
try {
82+
const response = await github.issues.get({
83+
issue_number: issueID,
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
})
87+
return response.data
88+
} catch (error) {
89+
console.log(`${error.name}: ${error.code}`);
90+
return false
91+
}
92+
}
93+
94+
/**
95+
* Given the title of a PullRequest checks if it contains a GitHub issue ID
96+
* @param {String} title
97+
* @returns {Boolean} true if title starts with a GitHub ID or MINOR:
98+
*/
99+
function haveGitHubIssueID(title) {
100+
if (!title) {
101+
return false;
102+
}
103+
if (title.startsWith("MINOR: ")) {
104+
return true;
105+
}
106+
return /^(WIP:?\s*)?(GH)-\d+/.test(title);
107+
}
108+
72109
module.exports = {
73-
detectJIRAID,
110+
detectIssueID,
74111
haveJIRAID,
75-
getJiraInfo
112+
getJiraInfo,
113+
haveGitHubIssueID,
114+
getGitHubInfo
76115
};

.github/workflows/dev_pr/jira_check.js renamed to .github/workflows/dev_pr/issue_check.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,42 @@ async function commentNotStartedTicket(github, context, pullRequestNumber) {
7878
}
7979
}
8080

81+
async function verifyGitHubIssue(github, context, pullRequestNumber, issueID) {
82+
const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber);
83+
if (issueInfo) {
84+
if (!issueInfo.assignees.length) {
85+
await github.issues.createComment({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
issue_number: pullRequestNumber,
89+
body: ":warning: GitHub issue #" + issueID + " **has not been assigned in GitHub**, please assign the ticket."
90+
})
91+
}
92+
if(!issueInfo.labels.length) {
93+
await github.issues.createComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
issue_number: pullRequestNumber,
97+
body: ":warning: GitHub issue #" + issueID + " **has no labels in GitHub**, please add labels for components."
98+
})
99+
}
100+
} else {
101+
await github.issues.createComment({
102+
owner: context.repo.owner,
103+
repo: context.repo.repo,
104+
issue_number: pullRequestNumber,
105+
body: ":warning: GitHub issue #" + issueID + " could not be retrieved."
106+
})
107+
}
108+
}
109+
81110
module.exports = async ({github, context}) => {
82111
const pullRequestNumber = context.payload.number;
83112
const title = context.payload.pull_request.title;
84-
const jiraID = helpers.detectJIRAID(title);
85-
if (jiraID) {
86-
await verifyJIRAIssue(github, context, pullRequestNumber, jiraID);
113+
const issueID = helpers.detectIssueID(title)
114+
if (helpers.haveJIRAID(title)) {
115+
await verifyJIRAIssue(github, context, pullRequestNumber, issueID);
116+
} else if(helpers.haveGitHubIssueID(title)) {
117+
await verifyGitHubIssue(github, context, pullRequestNumber, issueID);
87118
}
88119
};

.github/workflows/dev_pr/link.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,30 @@ async function commentJIRAURL(github, context, pullRequestNumber, jiraID) {
5151
});
5252
}
5353

54+
async function commentGitHubURL(github, context, pullRequestNumber, issueID) {
55+
// Make the call to ensure issue exists before adding comment
56+
const issueInfo = await helpers.getGitHubInfo(github, context, issueID, pullRequestNumber);
57+
// TODO: Check if comment is already there
58+
//if (await haveComment(github, context, pullRequestNumber, jiraURL)) {
59+
// return;
60+
//}
61+
if (issueInfo){
62+
await github.issues.createComment({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
issue_number: pullRequestNumber,
66+
body: "* Github Issue: #" + issueInfo.number
67+
});
68+
}
69+
}
70+
5471
module.exports = async ({github, context}) => {
5572
const pullRequestNumber = context.payload.number;
5673
const title = context.payload.pull_request.title;
57-
const jiraID = helpers.detectJIRAID(title);
58-
if (jiraID) {
59-
await commentJIRAURL(github, context, pullRequestNumber, jiraID);
74+
const issueID = helpers.detectIssueID(title);
75+
if (helpers.haveJIRAID(title)) {
76+
await commentJIRAURL(github, context, pullRequestNumber, issueID);
77+
} else if (helpers.haveGitHubIssueID(title)) {
78+
await commentGitHubURL(github, context, pullRequestNumber, issueID);
6079
}
6180
};

.github/workflows/dev_pr/title_check.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
const fs = require("fs");
1919
const helpers = require("./helpers.js");
2020

21-
async function commentOpenJIRAIssue(github, context, pullRequestNumber) {
21+
async function commentOpenGitHubIssue(github, context, pullRequestNumber) {
2222
const {data: comments} = await github.issues.listComments({
2323
owner: context.repo.owner,
2424
repo: context.repo.repo,
@@ -41,7 +41,7 @@ async function commentOpenJIRAIssue(github, context, pullRequestNumber) {
4141
module.exports = async ({github, context}) => {
4242
const pullRequestNumber = context.payload.number;
4343
const title = context.payload.pull_request.title;
44-
if (!helpers.haveJIRAID(title)) {
45-
await commentOpenJIRAIssue(github, context, pullRequestNumber);
44+
if (!helpers.haveJIRAID(title) || !helpers.haveGitHubIssueID(title)) {
45+
await commentOpenGitHubIssue(github, context, pullRequestNumber);
4646
}
4747
};

.github/workflows/dev_pr/title_check.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@
1919

2020
Thanks for opening a pull request!
2121

22-
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
22+
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
2323

24-
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.
24+
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.
2525

26-
Then could you also rename pull request title in the following format?
26+
Then could you also rename the pull request title in the following format?
2727

28-
ARROW-${JIRA_ID}: [${COMPONENT}] ${SUMMARY}
28+
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
2929

3030
or
3131

3232
MINOR: [${COMPONENT}] ${SUMMARY}
3333

34+
In the case of old issues on JIRA the title also supports:
35+
36+
ARROW-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
37+
3438
See also:
3539

3640
* [Other pull requests](https://github.com/apache/arrow/pulls/)

0 commit comments

Comments
 (0)