Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-39: [Python] Example without Label but assigned #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions dev/archery/archery/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, name, handler, token=None):
self.name = name
self.handler = handler
self.github = github.Github(token)
# TODO(raulcd): test

def parse_command(self, payload):
mention = '@{}'.format(self.name)
Expand Down