16 Commits

Author SHA1 Message Date
67fd9ff031 3.3.0 2019-05-08 16:45:55 +02:00
800950ebc5 Merge pull request #39 from 67P/feature/38-label_mappings
Map issue/PR labels to contribution kind
2019-05-08 16:42:05 +02:00
98ccae96f0 [gitea] Use labels for contribution kind 2019-05-08 16:16:40 +02:00
e6730802f6 Use proper syntax for sending HTTP status
Fixes deprecation warnings for the old syntax.
2019-05-08 16:14:41 +02:00
d2976b312e Create utility modules for label processing 2019-05-08 16:14:41 +02:00
d2feee8b14 [github] Use labels for contribution kind 2019-05-08 16:14:24 +02:00
a5acf466a4 3.2.1 2019-04-30 10:41:50 +01:00
Greg Karékinian
f1bb5b391d Merge pull request #35 from 67P/bugfix/33-gitea_issue_id
Fix wrong Gitea issue IDs/URLs
2019-04-30 10:26:21 +02:00
840fcf9d25 Add commented setting for custom local DAO address 2019-04-28 13:01:33 +01:00
c390fc9ce7 Fix Gitea issue ID/URL being wrong
Internal issue IDs are different from the public ones in Gitea. The one
used in URLs etc. is called "number" instead of "id" in hook payloads.

fixes #33
2019-04-28 13:01:09 +01:00
23033b3813 3.2.0 2019-04-24 14:25:51 +01:00
fb1b10d2a3 Merge pull request #31 from 67P/feature/24-gitea
Add Gitea integration
2019-04-24 14:25:06 +01:00
d3b97d9129 Update kredits-contracts
Includes the Gitea accounts in profiles
2019-04-24 14:24:21 +01:00
d2f487b379 Merge pull request #32 from 67P/chore/remove_network_id_config
Remove network ID setting
2019-04-24 13:06:39 +00:00
ca9732c333 Add Gitea info to README 2019-04-24 13:38:16 +01:00
c03da5659f Remove network ID setting
Not needed anymore.
2019-04-24 13:34:00 +01:00
8 changed files with 112 additions and 79 deletions

View File

@@ -46,6 +46,25 @@ Point a GitHub organization webhook to the following URL:
| --- | --- |
| `KREDITS_GITHUB_REPO_BLACKLIST` | Repos which you do not want to issue kredits for. Format: `orgname/reponame`, e.g. `67P/test-one-two` |
### Gitea
The Gitea integration will watch for closed issues and merged pull requests,
which carry a kredits label: `kredits-1`, `kredits-2`, `kredits-3` for small,
medium and large contributions. If there are multiple people assigned, it will
issue contribution tokens for all of them.
#### Setup
Point a Gitea organization webhook to the following URL:
https://your-hubot.example.com/incoming/kredits/gitea/{webhook_token}
#### Config
| Key | Description |
| --- | --- |
| `KREDITS_GITEA_REPO_BLACKLIST` | Repos which you do not want to issue kredits for. Format: `orgname/reponame`, e.g. `kosmos/test-one-two` |
### MediaWiki
The MediaWiki integration will periodically check for wiki page creations and

View File

@@ -53,6 +53,7 @@ module.exports = async function(robot) {
kredits = await new Kredits(signer.provider, signer, {
// TODO support local devchain custom address
apm: 'open.aragonpm.eth',
// addresses: { Kernel: '0x93aa4531329e4bf3efcd1ec0b74adb6f66d9d10e' }
ipfsConfig
}).init();
} catch(error) {

View File

@@ -1,5 +1,7 @@
const util = require('util');
const fetch = require('node-fetch');
const amountFromLabels = require('./utils/amount-from-labels');
const kindFromLabels = require('./utils/kind-from-labels');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
@@ -35,7 +37,7 @@ module.exports = async function(robot, kredits) {
});
}
function createContribution(giteaUser, date, time, amount, description, url, details) {
function createContribution(giteaUser, date, time, amount, kind, description, url, details) {
return getContributorByGiteaUser(giteaUser).then(contributor => {
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${giteaUser} for ${url}...`);
@@ -45,12 +47,15 @@ module.exports = async function(robot, kredits) {
date,
time,
amount,
url,
kind,
description,
details,
kind: 'dev'
url,
details
};
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
return Contribution.addContribution(contributionAttr).catch(error => {
robot.logger.error(`[hubot-kredits] Error:`, error);
messageRoom(`I tried to add a contribution for ${giteaUser} for ${url}, but I encountered an error when submitting the tx:`);
@@ -59,35 +64,14 @@ module.exports = async function(robot, kredits) {
});
}
function amountFromLabels(labels) {
const kreditsLabel = 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;
}
async function handleGiteaIssueClosed(data) {
const issue = data.issue;
const repoName = data.repository.full_name;
const web_url = `${data.repository.html_url}/issues/${issue.id}`;
const web_url = `${data.repository.html_url}/issues/${issue.number}`;
const description = `${repoName}: ${issue.title}`;
const amount = amountFromLabels(issue.labels);
const labels = issue.labels.map(l => l.name);
const amount = amountFromLabels(labels);
const kind = kindFromLabels(labels);
const assignees = issue.assignees ? issue.assignees.map(a => a.login) : [];
[ date, time ] = issue.closed_at.split('T');
@@ -108,7 +92,8 @@ module.exports = async function(robot, kredits) {
for (const recipient of recipients) {
try {
await createContribution(recipient, date, time, amount, description, web_url,
await createContribution(recipient, date, time, amount,
kind, description, web_url,
{ issue, repository: data.repository });
await sleep(60000);
}
@@ -123,7 +108,9 @@ module.exports = async function(robot, kredits) {
const repoName = data.repository.full_name;
const web_url = pull_request.html_url;
const description = `${repoName}: ${pull_request.title}`;
const amount = amountFromLabels(pull_request.labels);
const labels = pull_request.labels.map(l => l.name);
const amount = amountFromLabels(labels);
const kind = kindFromLabels(labels);
const assignees = pull_request.assignees ? pull_request.assignees.map(a => a.login) : [];
[ date, time ] = pull_request.merged_at.split('T');
@@ -142,10 +129,10 @@ module.exports = async function(robot, kredits) {
recipients = [pull_request.user.login];
}
for (const recipient of recipients) {
try {
await createContribution(recipient, date, time, amount, description, web_url,
await createContribution(recipient, date, time, amount,
kind, description, web_url,
{ pull_request, repository: data.repository });
await sleep(60000);
}

View File

@@ -1,5 +1,7 @@
const util = require('util');
const fetch = require('node-fetch');
const amountFromLabels = require('./utils/amount-from-labels');
const kindFromLabels = require('./utils/kind-from-labels');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
@@ -35,9 +37,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 => {
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 = {
contributorId: contributor.id,
@@ -45,12 +47,15 @@ module.exports = async function(robot, kredits) {
date,
time,
amount,
url,
kind,
description,
details,
kind: 'dev'
url,
details
};
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
return Contribution.addContribution(contributionAttr).catch(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:`);
@@ -59,38 +64,17 @@ 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;
}
async function handleGitHubIssueClosed(data) {
let recipients;
const issue = data.issue;
const assignees = issue.assignees.map(a => a.login);
const web_url = issue.html_url;
const issue = data.issue;
const assignees = issue.assignees.map(a => a.login);
const web_url = issue.html_url;
[date, time] = issue.closed_at.split('T');
const amount = amountFromIssueLabels(issue);
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
[date, time] = issue.closed_at.split('T');
const labels = issue.labels.map(l => l.name);
const amount = amountFromLabels(labels);
const kind = kindFromLabels(labels);
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
const description = `${repoName}: ${issue.title}`;
if (amount === 0) {
@@ -109,7 +93,7 @@ module.exports = async function(robot, kredits) {
for (const recipient of recipients) {
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);
}
catch (err) { robot.logger.error(err); }
@@ -141,8 +125,10 @@ module.exports = async function(robot, kredits) {
return response.json();
})
.then(async (issue) => {
const amount = amountFromIssueLabels(issue);
const repoName = pull_request.base.repo.full_name;
const labels = issue.labels.map(l => l.name);
const amount = amountFromLabels(labels);
const kind = kindFromLabels(labels);
const repoName = pull_request.base.repo.full_name;
const description = `${repoName}: ${pull_request.title}`;
if (amount === 0) {
@@ -155,7 +141,7 @@ module.exports = async function(robot, kredits) {
for (const recipient of recipients) {
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);
}
catch (err) { robot.logger.error(err); }
@@ -176,13 +162,13 @@ module.exports = async function(robot, kredits) {
if (evt === 'pull_request' && data.action === 'closed' && data.pull_request.merged) {
handleGitHubPullRequestClosed(data);
res.send(200);
res.sendStatus(200);
}
else if (evt === 'issues' && data.action === 'closed') {
handleGitHubIssueClosed(data);
res.send(200);
res.sendStatus(200);
} else {
res.send(200);
res.sendStatus(200);
}
});

View 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;
};

View 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;
};

7
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "3.1.2",
"version": "3.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1175,8 +1175,9 @@
}
},
"kredits-contracts": {
"version": "github:67P/kredits-contracts#09b78e1e8f0e9a458324e95dcdf1e7eb1d662eee",
"from": "github:67P/kredits-contracts#feature/gitea_site",
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz",
"integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==",
"requires": {
"ethers": "^4.0.27",
"ipfs-http-client": "^30.1.1",

View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "3.1.2",
"version": "3.3.0",
"description": "Kosmos Kredits functionality for chat bots",
"main": "index.js",
"scripts": {
@@ -14,7 +14,7 @@
"ethers": "^4.0.27",
"group-array": "^0.3.3",
"kosmos-schemas": "^1.1.2",
"kredits-contracts": "github:67P/kredits-contracts#feature/gitea_site",
"kredits-contracts": "^5.3.0",
"node-cron": "^2.0.3",
"node-fetch": "^2.3.0",
"prompt": "^1.0.0"