Implement assigning issue to `Status SOB Swarm` project when tagged `bounty-awaiting-approval`
This commit is contained in:
parent
7a9c6e3e9e
commit
2f79f7fc4d
|
@ -9,7 +9,7 @@ new-pull-requests:
|
||||||
bounty-awaiting-approval:
|
bounty-awaiting-approval:
|
||||||
project-board:
|
project-board:
|
||||||
name: 'Status SOB Swarm'
|
name: 'Status SOB Swarm'
|
||||||
review-column-name: 'bounty-awaiting-approval'
|
approval-column-name: 'bounty-awaiting-approval'
|
||||||
|
|
||||||
slack:
|
slack:
|
||||||
notification:
|
notification:
|
||||||
|
|
|
@ -7,10 +7,6 @@
|
||||||
// hubot-github-webhook-listener: "^0.9.1"
|
// hubot-github-webhook-listener: "^0.9.1"
|
||||||
// hubot-slack: "^4.4.0"
|
// hubot-slack: "^4.4.0"
|
||||||
//
|
//
|
||||||
// Notes:
|
|
||||||
// The hard-coded names for the project board and review column are just below.
|
|
||||||
// These could be read from a config file (e.g. YAML)
|
|
||||||
//
|
|
||||||
// Author:
|
// Author:
|
||||||
// PombeirP
|
// PombeirP
|
||||||
|
|
||||||
|
@ -89,7 +85,7 @@ async function assignPullRequestToReview(gitHubContext, githubPayload, robot) {
|
||||||
robot.logger.debug(`Created card: ${ghcard.data.url}`, ghcard.data.id);
|
robot.logger.debug(`Created card: ${ghcard.data.url}`, ghcard.data.id);
|
||||||
|
|
||||||
// Send message to Slack
|
// Send message to Slack
|
||||||
robot.messageRoom(githubConfig.slack.notification.room, `Moved PR to ${reviewColumnName} in ${projectBoardName} project\n${githubPayload.pull_request.html_url}`);
|
robot.messageRoom(githubConfig.slack.notification.room, `Assigned PR to ``${reviewColumnName}`` in ``${projectBoardName}`` project\n${githubPayload.pull_request.html_url}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
robot.logger.error(`Couldn't create project card for the PR: ${err}`, column.id, githubPayload.pull_request.id);
|
robot.logger.error(`Couldn't create project card for the PR: ${err}`, column.id, githubPayload.pull_request.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
// Description:
|
||||||
|
// Script that listens to new labels on GitHub issues
|
||||||
|
// and assigns the issues to the bounty-awaiting-approval column on the "Status SOB Swarm" project
|
||||||
|
//
|
||||||
|
// Dependencies:
|
||||||
|
// github: "^13.1.0"
|
||||||
|
// hubot-github-webhook-listener: "^0.9.1"
|
||||||
|
// hubot-slack: "^4.4.0"
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// PombeirP
|
||||||
|
|
||||||
|
module.exports = function(robot) {
|
||||||
|
|
||||||
|
const gitHubContext = require('./github-context.js')();
|
||||||
|
|
||||||
|
return robot.on("github-repo-event", function(repo_event) {
|
||||||
|
const githubPayload = repo_event.payload;
|
||||||
|
|
||||||
|
switch(repo_event.eventType) {
|
||||||
|
case "issues":
|
||||||
|
// Make sure we don't listen to our own messages
|
||||||
|
if (gitHubContext.equalsRobotName(robot, githubPayload.issue.user.login)) { return; }
|
||||||
|
|
||||||
|
var { action } = githubPayload;
|
||||||
|
if (action === "labeled") {
|
||||||
|
// A new issue was labeled
|
||||||
|
return assignIssueToBountyAwaitingForApproval(gitHubContext, githubPayload, robot);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
async function assignIssueToBountyAwaitingForApproval(gitHubContext, githubPayload, robot) {
|
||||||
|
const github = gitHubContext.api();
|
||||||
|
const githubConfig = gitHubContext.config();
|
||||||
|
const ownerName = githubPayload.repository.owner.login;
|
||||||
|
const repoName = githubPayload.repository.name;
|
||||||
|
const issueNumber = githubPayload.issue.number;
|
||||||
|
|
||||||
|
robot.logger.info(`assignIssueToBountyAwaitingForApproval - Handling Issue #${issueNumber} on repo ${ownerName}/${repoName}`);
|
||||||
|
|
||||||
|
// Fetch org projects
|
||||||
|
// TODO: The org project and project column info should be cached
|
||||||
|
// in order to improve performance and reduce roundtrips
|
||||||
|
try {
|
||||||
|
const orgName = 'status-im';
|
||||||
|
|
||||||
|
ghprojects = await github.projects.getOrgProjects({
|
||||||
|
org: orgName,
|
||||||
|
state: "open"
|
||||||
|
});
|
||||||
|
|
||||||
|
// Find "Status SOB Swarm" project
|
||||||
|
const projectBoardName = githubConfig['bounty-awaiting-approval']['project-board'].name;
|
||||||
|
const project = ghprojects.data.find(function(p) { return p.name === projectBoardName });
|
||||||
|
if (!project) {
|
||||||
|
robot.logger.error(`Couldn't find project ${projectBoardName} in ${orgName} org`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
robot.logger.debug(`Fetched ${project.name} project (${project.id})`);
|
||||||
|
|
||||||
|
// Fetch bounty-awaiting-approval column ID
|
||||||
|
try {
|
||||||
|
ghcolumns = await github.projects.getProjectColumns({ project_id: project.id });
|
||||||
|
|
||||||
|
const approvalColumnName = githubConfig['bounty-awaiting-approval']['project-board']['approval-column-name'];
|
||||||
|
const column = ghcolumns.data.find(function(c) { return c.name === approvalColumnName });
|
||||||
|
if (!column) {
|
||||||
|
robot.logger.error(`Couldn't find ${approvalColumnName} column in project ${project.name}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
robot.logger.debug(`Fetched ${column.name} column (${column.id})`);
|
||||||
|
|
||||||
|
// Create project card for the issue in the bounty-awaiting-approval column
|
||||||
|
try {
|
||||||
|
ghcard = await github.projects.createProjectCard({
|
||||||
|
column_id: column.id,
|
||||||
|
content_type: 'Issue',
|
||||||
|
content_id: githubPayload.issue.id
|
||||||
|
});
|
||||||
|
|
||||||
|
robot.logger.debug(`Created card: ${ghcard.data.url}`, ghcard.data.id);
|
||||||
|
|
||||||
|
// Send message to Slack
|
||||||
|
robot.messageRoom(githubConfig.slack.notification.room, `Assigned issue to ``${approvalColumnName}`` in ``${projectBoardName}`` project\n${githubPayload.issue.html_url}`);
|
||||||
|
} catch (err) {
|
||||||
|
robot.logger.error(`Couldn't create project card for the issue: ${err}`, column.id, githubPayload.issue.id);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
robot.logger.error(`Couldn't fetch the github columns for project: ${err}`, ownerName, repoName, project.id);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
robot.logger.error(`Couldn't fetch the github projects for repo: ${err}`, ownerName, repoName);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue