[github] Use labels for contribution kind
This commit is contained in:
parent
a5acf466a4
commit
d2feee8b14
@ -35,9 +35,9 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContribution(githubUser, date, time, amount, description, url, details) {
|
function createContribution(githubUser, date, time, amount, kind, description, url, details) {
|
||||||
return getContributorByGithubUser(githubUser).then(contributor => {
|
return getContributorByGithubUser(githubUser).then(contributor => {
|
||||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
|
robot.logger.info(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
|
||||||
|
|
||||||
const contributionAttr = {
|
const contributionAttr = {
|
||||||
contributorId: contributor.id,
|
contributorId: contributor.id,
|
||||||
@ -45,12 +45,15 @@ module.exports = async function(robot, kredits) {
|
|||||||
date,
|
date,
|
||||||
time,
|
time,
|
||||||
amount,
|
amount,
|
||||||
url,
|
kind,
|
||||||
description,
|
description,
|
||||||
details,
|
url,
|
||||||
kind: 'dev'
|
details
|
||||||
};
|
};
|
||||||
|
|
||||||
|
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
|
||||||
|
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
||||||
|
|
||||||
return Contribution.addContribution(contributionAttr).catch(error => {
|
return Contribution.addContribution(contributionAttr).catch(error => {
|
||||||
robot.logger.error(`[hubot-kredits] Error:`, error);
|
robot.logger.error(`[hubot-kredits] Error:`, error);
|
||||||
messageRoom(`I tried to add a contribution for ${githubUser} for ${url}, but I encountered an error when submitting the tx:`);
|
messageRoom(`I tried to add a contribution for ${githubUser} for ${url}, but I encountered an error when submitting the tx:`);
|
||||||
@ -82,6 +85,26 @@ module.exports = async function(robot, kredits) {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function kindFromIssueLabels(issue) {
|
||||||
|
const labels = issue.labels.map(l => l.name);
|
||||||
|
let kind = 'dev';
|
||||||
|
|
||||||
|
if (labels.find(l => l.match(/ops|operations/))) {
|
||||||
|
kind = 'ops';
|
||||||
|
}
|
||||||
|
else if (labels.find(l => l.match(/docs|documentation/))) {
|
||||||
|
kind = 'docs';
|
||||||
|
}
|
||||||
|
else if (labels.find(l => l.match(/design/))) {
|
||||||
|
kind = 'design';
|
||||||
|
}
|
||||||
|
else if (labels.find(l => l.match(/community/))) {
|
||||||
|
kind = 'community';
|
||||||
|
}
|
||||||
|
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
async function handleGitHubIssueClosed(data) {
|
async function handleGitHubIssueClosed(data) {
|
||||||
let recipients;
|
let recipients;
|
||||||
const issue = data.issue;
|
const issue = data.issue;
|
||||||
@ -90,6 +113,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
[date, time] = issue.closed_at.split('T');
|
[date, time] = issue.closed_at.split('T');
|
||||||
const amount = amountFromIssueLabels(issue);
|
const amount = amountFromIssueLabels(issue);
|
||||||
|
const kind = kindFromIssueLabels(issue);
|
||||||
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
||||||
const description = `${repoName}: ${issue.title}`;
|
const description = `${repoName}: ${issue.title}`;
|
||||||
|
|
||||||
@ -109,7 +133,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
for (const recipient of recipients) {
|
for (const recipient of recipients) {
|
||||||
try {
|
try {
|
||||||
await createContribution(recipient, date, time, amount, description, web_url, issue);
|
await createContribution(recipient, date, time, amount, kind, description, web_url, issue);
|
||||||
await sleep(60000);
|
await sleep(60000);
|
||||||
}
|
}
|
||||||
catch (err) { robot.logger.error(err); }
|
catch (err) { robot.logger.error(err); }
|
||||||
@ -142,6 +166,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
})
|
})
|
||||||
.then(async (issue) => {
|
.then(async (issue) => {
|
||||||
const amount = amountFromIssueLabels(issue);
|
const amount = amountFromIssueLabels(issue);
|
||||||
|
const kind = kindFromIssueLabels(issue);
|
||||||
const repoName = pull_request.base.repo.full_name;
|
const repoName = pull_request.base.repo.full_name;
|
||||||
const description = `${repoName}: ${pull_request.title}`;
|
const description = `${repoName}: ${pull_request.title}`;
|
||||||
|
|
||||||
@ -155,7 +180,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
for (const recipient of recipients) {
|
for (const recipient of recipients) {
|
||||||
try {
|
try {
|
||||||
await createContribution(recipient, date, time, amount, description, web_url, pull_request);
|
await createContribution(recipient, date, time, amount, kind, description, web_url, pull_request);
|
||||||
await sleep(60000);
|
await sleep(60000);
|
||||||
}
|
}
|
||||||
catch (err) { robot.logger.error(err); }
|
catch (err) { robot.logger.error(err); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user