Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 67fd9ff031 | |||
| 800950ebc5 | |||
| 98ccae96f0 | |||
| e6730802f6 | |||
| d2976b312e | |||
| d2feee8b14 | |||
| a5acf466a4 | |||
|
|
f1bb5b391d | ||
| 840fcf9d25 | |||
| c390fc9ce7 | |||
| 23033b3813 | |||
| fb1b10d2a3 | |||
| d3b97d9129 | |||
| d2f487b379 | |||
| ca9732c333 | |||
| c03da5659f | |||
| 5a9edda1cd | |||
| 2a3077d733 | |||
| 1255d7ce19 | |||
| d9e09ce041 | |||
| a0f982432e | |||
| 4550a911f0 | |||
| d1580560b5 | |||
| 92c50ac69e | |||
| fca991c685 | |||
| 626712356a | |||
| 65e34ee4e1 |
20
README.md
20
README.md
@@ -24,7 +24,6 @@ As usual in Hubot, you can add all config as environment variables.
|
|||||||
| `KREDITS_WALLET_PATH` | Path to an Etherum wallet JSON file (default: `./wallet.json`) |
|
| `KREDITS_WALLET_PATH` | Path to an Etherum wallet JSON file (default: `./wallet.json`) |
|
||||||
| `KREDITS_WALLET_PASSWORD` | Wallet password |
|
| `KREDITS_WALLET_PASSWORD` | Wallet password |
|
||||||
| `KREDITS_PROVIDER_URL` | Ethereum JSON-RPC URL (default: `http://localhost:7545`) |
|
| `KREDITS_PROVIDER_URL` | Ethereum JSON-RPC URL (default: `http://localhost:7545`) |
|
||||||
| `KREDITS_NETWORK_ID` | The ethereum network ID to use (default: 100 = local) |
|
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
@@ -47,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` |
|
| `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
|
### MediaWiki
|
||||||
|
|
||||||
The MediaWiki integration will periodically check for wiki page creations and
|
The MediaWiki integration will periodically check for wiki page creations and
|
||||||
|
|||||||
3
index.js
3
index.js
@@ -7,7 +7,6 @@ const Kredits = require('kredits-contracts');
|
|||||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||||
const walletJson = fs.readFileSync(walletPath);
|
const walletJson = fs.readFileSync(walletPath);
|
||||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||||
const networkId = parseInt(process.env.KREDITS_NETWORK_ID || 100);
|
|
||||||
|
|
||||||
const ipfsConfig = {
|
const ipfsConfig = {
|
||||||
host: process.env.IPFS_API_HOST || 'localhost',
|
host: process.env.IPFS_API_HOST || 'localhost',
|
||||||
@@ -54,6 +53,7 @@ module.exports = async function(robot) {
|
|||||||
kredits = await new Kredits(signer.provider, signer, {
|
kredits = await new Kredits(signer.provider, signer, {
|
||||||
// TODO support local devchain custom address
|
// TODO support local devchain custom address
|
||||||
apm: 'open.aragonpm.eth',
|
apm: 'open.aragonpm.eth',
|
||||||
|
// addresses: { Kernel: '0x93aa4531329e4bf3efcd1ec0b74adb6f66d9d10e' }
|
||||||
ipfsConfig
|
ipfsConfig
|
||||||
}).init();
|
}).init();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
@@ -149,6 +149,7 @@ module.exports = async function(robot) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
require('./integrations/github')(robot, kredits);
|
require('./integrations/github')(robot, kredits);
|
||||||
|
require('./integrations/gitea')(robot, kredits);
|
||||||
|
|
||||||
if (typeof process.env.KREDITS_MEDIAWIKI_URL !== 'undefined') {
|
if (typeof process.env.KREDITS_MEDIAWIKI_URL !== 'undefined') {
|
||||||
require('./integrations/mediawiki')(robot, kredits);
|
require('./integrations/mediawiki')(robot, kredits);
|
||||||
|
|||||||
166
integrations/gitea.js
Normal file
166
integrations/gitea.js
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async function(robot, kredits) {
|
||||||
|
|
||||||
|
function messageRoom(message) {
|
||||||
|
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
robot.logger.debug('[hubot-kredits] Loading Gitea integration...');
|
||||||
|
|
||||||
|
let repoBlackList = [];
|
||||||
|
if (process.env.KREDITS_GITEA_REPO_BLACKLIST) {
|
||||||
|
repoBlackList = process.env.KREDITS_GITEA_REPO_BLACKLIST.split(',');
|
||||||
|
robot.logger.debug('[hubot-kredits] Ignoring Gitea actions from ', util.inspect(repoBlackList));
|
||||||
|
}
|
||||||
|
|
||||||
|
const Contributor = kredits.Contributor;
|
||||||
|
const Contribution = kredits.Contribution;
|
||||||
|
|
||||||
|
function getContributorByGiteaUser(username) {
|
||||||
|
return Contributor.all().then(contributors => {
|
||||||
|
const contrib = contributors.find(c => {
|
||||||
|
return c.gitea_username === username;
|
||||||
|
});
|
||||||
|
if (!contrib) {
|
||||||
|
throw new Error(`No contributor found for ${username}`);
|
||||||
|
} else {
|
||||||
|
return contrib;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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}...`);
|
||||||
|
|
||||||
|
const contributionAttr = {
|
||||||
|
contributorId: contributor.id,
|
||||||
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
|
date,
|
||||||
|
time,
|
||||||
|
amount,
|
||||||
|
kind,
|
||||||
|
description,
|
||||||
|
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:`);
|
||||||
|
messageRoom(error.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 description = `${repoName}: ${issue.title}`;
|
||||||
|
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');
|
||||||
|
|
||||||
|
if (amount === 0) {
|
||||||
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
|
return Promise.resolve();
|
||||||
|
} else if (repoBlackList.includes(repoName)) {
|
||||||
|
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
let recipients;
|
||||||
|
if (assignees.length > 0) {
|
||||||
|
recipients = assignees;
|
||||||
|
} else {
|
||||||
|
recipients = [issue.user.login];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const recipient of recipients) {
|
||||||
|
try {
|
||||||
|
await createContribution(recipient, date, time, amount,
|
||||||
|
kind, description, web_url,
|
||||||
|
{ issue, repository: data.repository });
|
||||||
|
await sleep(60000);
|
||||||
|
}
|
||||||
|
catch (err) { robot.logger.error(err); }
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleGiteaPullRequestClosed(data) {
|
||||||
|
const pull_request = data.pull_request;
|
||||||
|
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 assignees = pull_request.assignees ? pull_request.assignees.map(a => a.login) : [];
|
||||||
|
[ date, time ] = pull_request.merged_at.split('T');
|
||||||
|
|
||||||
|
if (amount === 0) {
|
||||||
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
|
return Promise.resolve();
|
||||||
|
} else if (repoBlackList.includes(repoName)) {
|
||||||
|
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
let recipients;
|
||||||
|
if (assignees.length > 0) {
|
||||||
|
recipients = assignees;
|
||||||
|
} else {
|
||||||
|
recipients = [pull_request.user.login];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const recipient of recipients) {
|
||||||
|
try {
|
||||||
|
await createContribution(recipient, date, time, amount,
|
||||||
|
kind, description, web_url,
|
||||||
|
{ pull_request, repository: data.repository });
|
||||||
|
await sleep(60000);
|
||||||
|
}
|
||||||
|
catch (err) { robot.logger.error(err); }
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
robot.router.post('/incoming/kredits/gitea/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
||||||
|
const evt = req.header('X-Gitea-Event');
|
||||||
|
let data = req.body;
|
||||||
|
// For some reason data is contained in a payload property on one
|
||||||
|
// machine, but directly in the root of the object on others
|
||||||
|
if (data.payload) { data = JSON.parse(data.payload); }
|
||||||
|
|
||||||
|
robot.logger.info(`Received Gitea hook. Event: ${evt}, action: ${data.action}`);
|
||||||
|
|
||||||
|
if (evt === 'pull_request' && data.action === 'closed' && data.pull_request.merged) {
|
||||||
|
handleGiteaPullRequestClosed(data);
|
||||||
|
res.sendStatus(200);
|
||||||
|
}
|
||||||
|
else if (evt === 'issues' && data.action === 'closed') {
|
||||||
|
handleGiteaIssueClosed(data);
|
||||||
|
res.sendStatus(200);
|
||||||
|
} else {
|
||||||
|
res.sendStatus(200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
@@ -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));
|
||||||
@@ -24,7 +26,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
function getContributorByGithubUser(username) {
|
function getContributorByGithubUser(username) {
|
||||||
return Contributor.all().then(contributors => {
|
return Contributor.all().then(contributors => {
|
||||||
let contrib = contributors.find(c => {
|
const contrib = contributors.find(c => {
|
||||||
return c.github_username === username;
|
return c.github_username === username;
|
||||||
});
|
});
|
||||||
if (!contrib) {
|
if (!contrib) {
|
||||||
@@ -35,20 +37,25 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContribution(githubUser, 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}...`);
|
||||||
|
|
||||||
let contributionAttr = {
|
const contributionAttr = {
|
||||||
contributorId: contributor.id,
|
contributorId: contributor.id,
|
||||||
amount: amount,
|
|
||||||
contributorIpfsHash: contributor.ipfsHash,
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
url,
|
date,
|
||||||
|
time,
|
||||||
|
amount,
|
||||||
|
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:`);
|
||||||
@@ -57,38 +64,18 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function amountFromIssueLabels(issue) {
|
|
||||||
let 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) {
|
async function handleGitHubIssueClosed(data) {
|
||||||
let recipients;
|
let recipients;
|
||||||
let issue = data.issue;
|
const issue = data.issue;
|
||||||
let assignees = issue.assignees.map(a => a.login);
|
const assignees = issue.assignees.map(a => a.login);
|
||||||
let web_url = issue.html_url;
|
const web_url = issue.html_url;
|
||||||
|
|
||||||
let amount = amountFromIssueLabels(issue);
|
[date, time] = issue.closed_at.split('T');
|
||||||
let repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
const labels = issue.labels.map(l => l.name);
|
||||||
let description = `${repoName}: ${issue.title}`;
|
const amount = amountFromLabels(labels);
|
||||||
|
const kind = kindFromLabels(labels);
|
||||||
|
const repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
|
||||||
|
const description = `${repoName}: ${issue.title}`;
|
||||||
|
|
||||||
if (amount === 0) {
|
if (amount === 0) {
|
||||||
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
@@ -106,7 +93,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
for (const recipient of recipients) {
|
for (const recipient of recipients) {
|
||||||
try {
|
try {
|
||||||
await createContribution(recipient, 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); }
|
||||||
@@ -117,10 +104,12 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
function handleGitHubPullRequestClosed(data) {
|
function handleGitHubPullRequestClosed(data) {
|
||||||
let recipients;
|
let recipients;
|
||||||
let pull_request = data.pull_request;
|
const pull_request = data.pull_request;
|
||||||
let assignees = pull_request.assignees.map(a => a.login);
|
const assignees = pull_request.assignees.map(a => a.login);
|
||||||
let web_url = pull_request._links.html.href;
|
const web_url = pull_request._links.html.href;
|
||||||
let pr_issue_url = pull_request.issue_url;
|
const pr_issue_url = pull_request.issue_url;
|
||||||
|
|
||||||
|
[date, time] = pull_request.merged_at.split('T');
|
||||||
|
|
||||||
if (assignees.length > 0) {
|
if (assignees.length > 0) {
|
||||||
recipients = assignees;
|
recipients = assignees;
|
||||||
@@ -136,9 +125,11 @@ module.exports = async function(robot, kredits) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(async (issue) => {
|
.then(async (issue) => {
|
||||||
let amount = amountFromIssueLabels(issue);
|
const labels = issue.labels.map(l => l.name);
|
||||||
let repoName = pull_request.base.repo.full_name;
|
const amount = amountFromLabels(labels);
|
||||||
let description = `${repoName}: ${pull_request.title}`;
|
const kind = kindFromLabels(labels);
|
||||||
|
const repoName = pull_request.base.repo.full_name;
|
||||||
|
const description = `${repoName}: ${pull_request.title}`;
|
||||||
|
|
||||||
if (amount === 0) {
|
if (amount === 0) {
|
||||||
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
@@ -150,7 +141,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
for (const recipient of recipients) {
|
for (const recipient of recipients) {
|
||||||
try {
|
try {
|
||||||
await createContribution(recipient, 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); }
|
||||||
@@ -161,7 +152,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
||||||
let evt = req.header('X-GitHub-Event');
|
const evt = req.header('X-GitHub-Event');
|
||||||
let data = req.body;
|
let data = req.body;
|
||||||
// For some reason data is contained in a payload property on one
|
// For some reason data is contained in a payload property on one
|
||||||
// machine, but directly in the root of the object on others
|
// machine, but directly in the root of the object on others
|
||||||
@@ -169,15 +160,15 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
robot.logger.info(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
robot.logger.info(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
||||||
|
|
||||||
if (evt === 'pull_request' && data.action === 'closed') {
|
if (evt === 'pull_request' && data.action === 'closed' && data.pull_request.merged) {
|
||||||
handleGitHubPullRequestClosed(data);
|
handleGitHubPullRequestClosed(data);
|
||||||
res.send(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
else if (evt === 'issues' && data.action === 'closed') {
|
else if (evt === 'issues' && data.action === 'closed') {
|
||||||
handleGitHubIssueClosed(data);
|
handleGitHubIssueClosed(data);
|
||||||
res.send(200);
|
res.sendStatus(200);
|
||||||
} else {
|
} else {
|
||||||
res.send(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,15 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContribution(username, amount, description, url, details={}) {
|
function createContribution(username, date, amount, description, url, details={}) {
|
||||||
return getContributorByWikiUser(username).then(contributor => {
|
return getContributorByWikiUser(username).then(contributor => {
|
||||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${contributor.name} for ${url}...`);
|
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${contributor.name} for ${url}...`);
|
||||||
|
|
||||||
let contribution = {
|
let contribution = {
|
||||||
contributorId: contributor.id,
|
contributorId: contributor.id,
|
||||||
amount: amount,
|
|
||||||
contributorIpfsHash: contributor.ipfsHash,
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
|
date,
|
||||||
|
amount: amount,
|
||||||
url,
|
url,
|
||||||
description,
|
description,
|
||||||
details,
|
details,
|
||||||
@@ -141,6 +142,10 @@ module.exports = async function(robot, kredits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createContributionForUserChanges (user, changes) {
|
function createContributionForUserChanges (user, changes) {
|
||||||
|
const dateNow = new Date();
|
||||||
|
const dateYesterday = dateNow.setDate(dateNow.getDate() - 1);
|
||||||
|
const date = (new Date(dateYesterday)).toISOString().split('T')[0];
|
||||||
|
|
||||||
const details = analyzeUserChanges(user, changes);
|
const details = analyzeUserChanges(user, changes);
|
||||||
const amount = calculateAmountForChanges(details);
|
const amount = calculateAmountForChanges(details);
|
||||||
|
|
||||||
@@ -161,7 +166,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
url = `${wikiURL}index.php?title=${rc.title}&diff=${rc.revid}&oldid=${rc.old_revid}`;
|
url = `${wikiURL}index.php?title=${rc.title}&diff=${rc.revid}&oldid=${rc.old_revid}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return createContribution(user, amount, desc, url, details);
|
return createContribution(user, date, amount, desc, url, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTimestampForNextFetch () {
|
function updateTimestampForNextFetch () {
|
||||||
|
|||||||
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;
|
||||||
|
};
|
||||||
60
package-lock.json
generated
60
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "3.0.0",
|
"version": "3.3.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -255,6 +255,11 @@
|
|||||||
"safe-buffer": "^5.0.1"
|
"safe-buffer": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"base64-js": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
|
||||||
|
},
|
||||||
"bignumber.js": {
|
"bignumber.js": {
|
||||||
"version": "8.1.1",
|
"version": "8.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz",
|
||||||
@@ -371,6 +376,15 @@
|
|||||||
"base-x": "^3.0.2"
|
"base-x": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"buffer": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==",
|
||||||
|
"requires": {
|
||||||
|
"base64-js": "^1.0.2",
|
||||||
|
"ieee754": "^1.1.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"buffer-xor": {
|
"buffer-xor": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
|
||||||
@@ -841,14 +855,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ipfs-http-client": {
|
"ipfs-http-client": {
|
||||||
"version": "30.1.1",
|
"version": "30.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/ipfs-http-client/-/ipfs-http-client-30.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/ipfs-http-client/-/ipfs-http-client-30.1.3.tgz",
|
||||||
"integrity": "sha512-tMqSwEhW57VnjHDBLjKKlgtAvlhkqVSR3oIFC0IiGnaM1nzcw7pbFBoHaFzl0PKIuXm40a5bJt85Rm2trYx+Ag==",
|
"integrity": "sha512-NQ7WTLKUZeoKaKXrTSLAtjASRYCR0bPdsolZf16Y7Gt7o3RfiPpFF+AqvP0xbekOV3/zhFj2Qyf6ShEV4CCtsQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async": "^2.6.1",
|
"async": "^2.6.1",
|
||||||
"bignumber.js": "^8.0.2",
|
"bignumber.js": "^8.0.2",
|
||||||
"bl": "^3.0.0",
|
"bl": "^3.0.0",
|
||||||
"bs58": "^4.0.1",
|
"bs58": "^4.0.1",
|
||||||
|
"buffer": "^5.2.1",
|
||||||
"cids": "~0.5.5",
|
"cids": "~0.5.5",
|
||||||
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
|
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
|
||||||
"debug": "^4.1.0",
|
"debug": "^4.1.0",
|
||||||
@@ -863,7 +878,7 @@
|
|||||||
"is-ipfs": "~0.6.0",
|
"is-ipfs": "~0.6.0",
|
||||||
"is-pull-stream": "0.0.0",
|
"is-pull-stream": "0.0.0",
|
||||||
"is-stream": "^1.1.0",
|
"is-stream": "^1.1.0",
|
||||||
"iso-stream-http": "~0.1.1",
|
"iso-stream-http": "~0.1.2",
|
||||||
"iso-url": "~0.4.6",
|
"iso-url": "~0.4.6",
|
||||||
"just-kebab-case": "^1.1.0",
|
"just-kebab-case": "^1.1.0",
|
||||||
"just-map-keys": "^1.1.0",
|
"just-map-keys": "^1.1.0",
|
||||||
@@ -1160,13 +1175,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"kredits-contracts": {
|
"kredits-contracts": {
|
||||||
"version": "4.0.0",
|
"version": "5.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz",
|
||||||
"integrity": "sha512-N7D1PPrfINXqm7f6SRU3+8eb7EyKjnR7xnBUwfEUUWvocr5xOmpkhekn3gMR6+jLJNvi8XTh0ao0jRWakRSFkw==",
|
"integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ethers": "^4.0.27",
|
"ethers": "^4.0.27",
|
||||||
"ipfs-http-client": "^30.1.1",
|
"ipfs-http-client": "^30.1.1",
|
||||||
"rsvp": "^4.8.2"
|
"kosmos-schemas": "^2.0.0",
|
||||||
|
"tv4": "^1.3.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"kosmos-schemas": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/kosmos-schemas/-/kosmos-schemas-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-zIjWcDxaN94m1vPgUaI5LRX6y07Ihw9ScPoGKf1NkZ0sLgD/CRV8YIKRyDafH5mThe3uBN2+F6H6Gp5qhNhALg==",
|
||||||
|
"requires": {
|
||||||
|
"brfs-babel": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libp2p-crypto": {
|
"libp2p-crypto": {
|
||||||
@@ -1337,9 +1363,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"multicodec": {
|
"multicodec": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/multicodec/-/multicodec-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/multicodec/-/multicodec-0.5.1.tgz",
|
||||||
"integrity": "sha512-lKsJeT4cKeSq0rVEWhO3oSBgDN4sMY1sNZKlvl68g/ZAahjPS1KIVyF4IqhuYmCdtOyKs4Q4hQ6M0C3iqRnuqQ==",
|
"integrity": "sha512-Q5glyZLdXVbbBxvRYHLQHpu8ydVf1422Z+v9fU47v2JCkiue7n+JcFS7uRv0cQW8hbVtgdtIDgYWPWaIKEXuXA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"varint": "^5.0.0"
|
"varint": "^5.0.0"
|
||||||
}
|
}
|
||||||
@@ -1705,11 +1731,6 @@
|
|||||||
"optimist": "~0.3.5"
|
"optimist": "~0.3.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rsvp": {
|
|
||||||
"version": "4.8.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.4.tgz",
|
|
||||||
"integrity": "sha512-6FomvYPfs+Jy9TfXmBpBuMWNH94SgCsZmJKcanySzgNNP6LjWxBvyLTa9KaMfDDM5oxRfrKDB0r/qeRsLwnBfA=="
|
|
||||||
},
|
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
||||||
@@ -1928,6 +1949,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
|
||||||
"integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM="
|
"integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM="
|
||||||
},
|
},
|
||||||
|
"tv4": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tv4/-/tv4-1.3.0.tgz",
|
||||||
|
"integrity": "sha1-0CDIRvrdUMhVq7JeuuzGj8EPeWM="
|
||||||
|
},
|
||||||
"tweetnacl": {
|
"tweetnacl": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "3.0.0",
|
"version": "3.3.0",
|
||||||
"description": "Kosmos Kredits functionality for chat bots",
|
"description": "Kosmos Kredits functionality for chat bots",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"ethers": "^4.0.27",
|
"ethers": "^4.0.27",
|
||||||
"group-array": "^0.3.3",
|
"group-array": "^0.3.3",
|
||||||
"kosmos-schemas": "^1.1.2",
|
"kosmos-schemas": "^1.1.2",
|
||||||
"kredits-contracts": "4.x",
|
"kredits-contracts": "^5.3.0",
|
||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"prompt": "^1.0.0"
|
"prompt": "^1.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user