Create utility modules for label processing
This commit is contained in:
parent
d2feee8b14
commit
d2976b312e
@ -1,5 +1,7 @@
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const amountFromLabels = require('./utils/amount-from-labels');
|
||||||
|
const kindFromLabels = require('./utils/kind-from-labels');
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
@ -62,49 +64,6 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function amountFromIssueLabels(issue) {
|
|
||||||
const kreditsLabel = issue.labels.map(l => l.name)
|
|
||||||
.filter(n => n.match(/^kredits/))[0];
|
|
||||||
// No label, no kredits
|
|
||||||
if (typeof kreditsLabel === 'undefined') { return 0; }
|
|
||||||
|
|
||||||
// TODO move to config maybe?
|
|
||||||
let amount;
|
|
||||||
switch(kreditsLabel) {
|
|
||||||
case 'kredits-1':
|
|
||||||
amount = 500;
|
|
||||||
break;
|
|
||||||
case 'kredits-2':
|
|
||||||
amount = 1500;
|
|
||||||
break;
|
|
||||||
case 'kredits-3':
|
|
||||||
amount = 5000;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
@ -112,8 +71,9 @@ module.exports = async function(robot, kredits) {
|
|||||||
const web_url = issue.html_url;
|
const web_url = issue.html_url;
|
||||||
|
|
||||||
[date, time] = issue.closed_at.split('T');
|
[date, time] = issue.closed_at.split('T');
|
||||||
const amount = amountFromIssueLabels(issue);
|
const labels = issue.labels.map(l => l.name);
|
||||||
const kind = kindFromIssueLabels(issue);
|
const amount = amountFromLabels(labels);
|
||||||
|
const kind = kindFromLabels(labels);
|
||||||
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
||||||
const description = `${repoName}: ${issue.title}`;
|
const description = `${repoName}: ${issue.title}`;
|
||||||
|
|
||||||
@ -165,8 +125,9 @@ module.exports = async function(robot, kredits) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(async (issue) => {
|
.then(async (issue) => {
|
||||||
const amount = amountFromIssueLabels(issue);
|
const labels = issue.labels.map(l => l.name);
|
||||||
const kind = kindFromIssueLabels(issue);
|
const amount = amountFromLabels(labels);
|
||||||
|
const kind = kindFromLabels(labels);
|
||||||
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}`;
|
||||||
|
|
||||||
|
21
integrations/utils/amount-from-labels.js
Normal file
21
integrations/utils/amount-from-labels.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module.exports = function (labels) {
|
||||||
|
const kreditsLabel = labels.filter(n => n.match(/^kredits/))[0];
|
||||||
|
// No label, no kredits
|
||||||
|
if (typeof kreditsLabel === 'undefined') { return 0; }
|
||||||
|
|
||||||
|
// TODO move amounts to config?
|
||||||
|
let amount;
|
||||||
|
switch(kreditsLabel) {
|
||||||
|
case 'kredits-1':
|
||||||
|
amount = 500;
|
||||||
|
break;
|
||||||
|
case 'kredits-2':
|
||||||
|
amount = 1500;
|
||||||
|
break;
|
||||||
|
case 'kredits-3':
|
||||||
|
amount = 5000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
};
|
18
integrations/utils/kind-from-labels.js
Normal file
18
integrations/utils/kind-from-labels.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module.exports = function (labels) {
|
||||||
|
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;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user