Compare commits
1 Commits
v3.3.0
...
chore/remo
| Author | SHA1 | Date | |
|---|---|---|---|
| e9987b4d39 |
19
README.md
19
README.md
@@ -46,25 +46,6 @@ 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
|
||||
|
||||
1
index.js
1
index.js
@@ -53,7 +53,6 @@ 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) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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));
|
||||
@@ -37,7 +35,7 @@ module.exports = async function(robot, kredits) {
|
||||
});
|
||||
}
|
||||
|
||||
function createContribution(giteaUser, date, time, amount, kind, description, url, details) {
|
||||
function createContribution(giteaUser, date, time, amount, description, url, details) {
|
||||
return getContributorByGiteaUser(giteaUser).then(contributor => {
|
||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${giteaUser} for ${url}...`);
|
||||
|
||||
@@ -47,15 +45,12 @@ module.exports = async function(robot, kredits) {
|
||||
date,
|
||||
time,
|
||||
amount,
|
||||
kind,
|
||||
description,
|
||||
url,
|
||||
details
|
||||
description,
|
||||
details,
|
||||
kind: 'dev'
|
||||
};
|
||||
|
||||
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:`);
|
||||
@@ -64,14 +59,35 @@ 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.number}`;
|
||||
const web_url = `${data.repository.html_url}/issues/${issue.id}`;
|
||||
const description = `${repoName}: ${issue.title}`;
|
||||
const labels = issue.labels.map(l => l.name);
|
||||
const amount = amountFromLabels(labels);
|
||||
const kind = kindFromLabels(labels);
|
||||
const amount = amountFromLabels(issue.labels);
|
||||
const assignees = issue.assignees ? issue.assignees.map(a => a.login) : [];
|
||||
[ date, time ] = issue.closed_at.split('T');
|
||||
|
||||
@@ -92,8 +108,7 @@ module.exports = async function(robot, kredits) {
|
||||
|
||||
for (const recipient of recipients) {
|
||||
try {
|
||||
await createContribution(recipient, date, time, amount,
|
||||
kind, description, web_url,
|
||||
await createContribution(recipient, date, time, amount, description, web_url,
|
||||
{ issue, repository: data.repository });
|
||||
await sleep(60000);
|
||||
}
|
||||
@@ -108,9 +123,7 @@ 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 labels = pull_request.labels.map(l => l.name);
|
||||
const amount = amountFromLabels(labels);
|
||||
const kind = kindFromLabels(labels);
|
||||
const amount = amountFromLabels(pull_request.labels);
|
||||
const assignees = pull_request.assignees ? pull_request.assignees.map(a => a.login) : [];
|
||||
[ date, time ] = pull_request.merged_at.split('T');
|
||||
|
||||
@@ -129,10 +142,10 @@ module.exports = async function(robot, kredits) {
|
||||
recipients = [pull_request.user.login];
|
||||
}
|
||||
|
||||
|
||||
for (const recipient of recipients) {
|
||||
try {
|
||||
await createContribution(recipient, date, time, amount,
|
||||
kind, description, web_url,
|
||||
await createContribution(recipient, date, time, amount, description, web_url,
|
||||
{ pull_request, repository: data.repository });
|
||||
await sleep(60000);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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));
|
||||
@@ -37,9 +35,9 @@ module.exports = async function(robot, kredits) {
|
||||
});
|
||||
}
|
||||
|
||||
function createContribution(githubUser, date, time, amount, kind, description, url, details) {
|
||||
function createContribution(githubUser, date, time, amount, description, url, details) {
|
||||
return getContributorByGithubUser(githubUser).then(contributor => {
|
||||
robot.logger.info(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
|
||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
|
||||
|
||||
const contributionAttr = {
|
||||
contributorId: contributor.id,
|
||||
@@ -47,15 +45,12 @@ module.exports = async function(robot, kredits) {
|
||||
date,
|
||||
time,
|
||||
amount,
|
||||
kind,
|
||||
description,
|
||||
url,
|
||||
details
|
||||
description,
|
||||
details,
|
||||
kind: 'dev'
|
||||
};
|
||||
|
||||
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:`);
|
||||
@@ -64,17 +59,38 @@ 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 labels = issue.labels.map(l => l.name);
|
||||
const amount = amountFromLabels(labels);
|
||||
const kind = kindFromLabels(labels);
|
||||
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
||||
[date, time] = issue.closed_at.split('T');
|
||||
const amount = amountFromIssueLabels(issue);
|
||||
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
||||
const description = `${repoName}: ${issue.title}`;
|
||||
|
||||
if (amount === 0) {
|
||||
@@ -93,7 +109,7 @@ module.exports = async function(robot, kredits) {
|
||||
|
||||
for (const recipient of recipients) {
|
||||
try {
|
||||
await createContribution(recipient, date, time, amount, kind, description, web_url, issue);
|
||||
await createContribution(recipient, date, time, amount, description, web_url, issue);
|
||||
await sleep(60000);
|
||||
}
|
||||
catch (err) { robot.logger.error(err); }
|
||||
@@ -125,10 +141,8 @@ module.exports = async function(robot, kredits) {
|
||||
return response.json();
|
||||
})
|
||||
.then(async (issue) => {
|
||||
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 amount = amountFromIssueLabels(issue);
|
||||
const repoName = pull_request.base.repo.full_name;
|
||||
const description = `${repoName}: ${pull_request.title}`;
|
||||
|
||||
if (amount === 0) {
|
||||
@@ -141,7 +155,7 @@ module.exports = async function(robot, kredits) {
|
||||
|
||||
for (const recipient of recipients) {
|
||||
try {
|
||||
await createContribution(recipient, date, time, amount, kind, description, web_url, pull_request);
|
||||
await createContribution(recipient, date, time, amount, description, web_url, pull_request);
|
||||
await sleep(60000);
|
||||
}
|
||||
catch (err) { robot.logger.error(err); }
|
||||
@@ -162,13 +176,13 @@ module.exports = async function(robot, kredits) {
|
||||
|
||||
if (evt === 'pull_request' && data.action === 'closed' && data.pull_request.merged) {
|
||||
handleGitHubPullRequestClosed(data);
|
||||
res.sendStatus(200);
|
||||
res.send(200);
|
||||
}
|
||||
else if (evt === 'issues' && data.action === 'closed') {
|
||||
handleGitHubIssueClosed(data);
|
||||
res.sendStatus(200);
|
||||
res.send(200);
|
||||
} else {
|
||||
res.sendStatus(200);
|
||||
res.send(200);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
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
7
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hubot-kredits",
|
||||
"version": "3.3.0",
|
||||
"version": "3.1.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -1175,9 +1175,8 @@
|
||||
}
|
||||
},
|
||||
"kredits-contracts": {
|
||||
"version": "5.3.0",
|
||||
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz",
|
||||
"integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==",
|
||||
"version": "github:67P/kredits-contracts#09b78e1e8f0e9a458324e95dcdf1e7eb1d662eee",
|
||||
"from": "github:67P/kredits-contracts#feature/gitea_site",
|
||||
"requires": {
|
||||
"ethers": "^4.0.27",
|
||||
"ipfs-http-client": "^30.1.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hubot-kredits",
|
||||
"version": "3.3.0",
|
||||
"version": "3.1.2",
|
||||
"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": "^5.3.0",
|
||||
"kredits-contracts": "github:67P/kredits-contracts#feature/gitea_site",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"prompt": "^1.0.0"
|
||||
|
||||
Reference in New Issue
Block a user