Skip to content

Commit

Permalink
Review comments 1
Browse files Browse the repository at this point in the history
  • Loading branch information
raulcd committed Nov 25, 2022
1 parent 99c2cc2 commit bc4a07a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 57 deletions.
61 changes: 20 additions & 41 deletions .github/workflows/dev_pr/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
};
15 changes: 8 additions & 7 deletions .github/workflows/dev_pr/issue_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ 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, issueID);
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."
body: ":warning: GitHub issue #" + issueID + " **has been automatically assigned in GitHub** to PR creator."
})
}
if(!issueInfo.labels.length) {
Expand All @@ -102,18 +103,18 @@ 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."
})
}
}

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.kind == "jira") {
await verifyJIRAIssue(github, context, pullRequestNumber, issue.id);
} else if(issue.kind == "github") {
await verifyGitHubIssue(github, context, pullRequestNumber, issue.id);
}
};
45 changes: 37 additions & 8 deletions .github/workflows/dev_pr/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 || "")) {
Expand All @@ -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)) {
Expand All @@ -51,10 +68,18 @@ 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);
const message = "* Github Issue: #" + issueInfo.number
const message = "Closes #" + issueInfo.number
if (await haveComment(github, context, pullRequestNumber, message)) {
return;
}
Expand All @@ -70,11 +95,15 @@ async function commentGitHubURL(github, context, pullRequestNumber, issueID) {

module.exports = async ({github, context}) => {
const pullRequestNumber = context.payload.number;
console.log("Payload")
console.log(context.payload)
console.log("Pull Request")
console.log(context.payload.pull_request)
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.kind == "jira") {
await commentJIRAURL(github, context, pullRequestNumber, issue.id);
} else if (issue.kind == "github") {
await commentGitHubURL(github, context, pullRequestNumber, issue.id);
}
};
3 changes: 2 additions & 1 deletion .github/workflows/dev_pr/title_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
1 change: 1 addition & 0 deletions .github/workflows/dev_pr/title_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit bc4a07a

Please sign in to comment.