8 Commits

Author SHA1 Message Date
d9e09ce041 3.1.1 2019-04-17 09:38:19 +01:00
a0f982432e Fix syntax error (variable re-assignment) 2019-04-17 09:38:00 +01:00
4550a911f0 3.1.0 2019-04-16 12:52:54 +01:00
d1580560b5 Update kredits-contracts 2019-04-16 12:51:49 +01:00
92c50ac69e Merge pull request #30 from 67P/feature/29-date_time
Add contribution date
2019-04-13 16:07:46 +00:00
fca991c685 Add date to mediawiki edits
Use the day before, as we collect them at 7am every day.
2019-04-13 14:18:47 +01:00
626712356a Add date and time for GitHub issues and PRs 2019-04-13 14:04:41 +01:00
65e34ee4e1 Update kredits-contracts 2019-04-13 12:44:10 +01:00
4 changed files with 80 additions and 38 deletions

View File

@@ -24,7 +24,7 @@ module.exports = async function(robot, kredits) {
function getContributorByGithubUser(username) {
return Contributor.all().then(contributors => {
let contrib = contributors.find(c => {
const contrib = contributors.find(c => {
return c.github_username === username;
});
if (!contrib) {
@@ -35,14 +35,16 @@ module.exports = async function(robot, kredits) {
});
}
function createContribution(githubUser, amount, description, url, details) {
function createContribution(githubUser, date, time, amount, description, url, details) {
return getContributorByGithubUser(githubUser).then(contributor => {
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
let contributionAttr = {
const contributionAttr = {
contributorId: contributor.id,
amount: amount,
contributorIpfsHash: contributor.ipfsHash,
date,
time,
amount,
url,
description,
details,
@@ -58,8 +60,8 @@ module.exports = async function(robot, kredits) {
}
function amountFromIssueLabels(issue) {
let kreditsLabel = issue.labels.map(l => l.name)
.filter(n => n.match(/^kredits/))[0];
const kreditsLabel = issue.labels.map(l => l.name)
.filter(n => n.match(/^kredits/))[0];
// No label, no kredits
if (typeof kreditsLabel === 'undefined') { return 0; }
@@ -82,13 +84,14 @@ module.exports = async function(robot, kredits) {
async function handleGitHubIssueClosed(data) {
let recipients;
let issue = data.issue;
let assignees = issue.assignees.map(a => a.login);
let web_url = issue.html_url;
const issue = data.issue;
const assignees = issue.assignees.map(a => a.login);
const web_url = issue.html_url;
let amount = amountFromIssueLabels(issue);
let repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1];
let description = `${repoName}: ${issue.title}`;
[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) {
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
@@ -106,7 +109,7 @@ module.exports = async function(robot, kredits) {
for (const recipient of recipients) {
try {
await createContribution(recipient, amount, description, web_url, issue);
await createContribution(recipient, date, time, amount, description, web_url, issue);
await sleep(60000);
}
catch (err) { robot.logger.error(err); }
@@ -117,10 +120,12 @@ module.exports = async function(robot, kredits) {
function handleGitHubPullRequestClosed(data) {
let recipients;
let pull_request = data.pull_request;
let assignees = pull_request.assignees.map(a => a.login);
let web_url = pull_request._links.html.href;
let pr_issue_url = pull_request.issue_url;
const pull_request = data.pull_request;
const assignees = pull_request.assignees.map(a => a.login);
const web_url = pull_request._links.html.href;
const pr_issue_url = pull_request.issue_url;
[date, time] = pull_request.merged_at.split('T');
if (assignees.length > 0) {
recipients = assignees;
@@ -136,9 +141,9 @@ module.exports = async function(robot, kredits) {
return response.json();
})
.then(async (issue) => {
let amount = amountFromIssueLabels(issue);
let repoName = pull_request.base.repo.full_name;
let description = `${repoName}: ${pull_request.title}`;
const amount = amountFromIssueLabels(issue);
const repoName = pull_request.base.repo.full_name;
const description = `${repoName}: ${pull_request.title}`;
if (amount === 0) {
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
@@ -150,7 +155,7 @@ module.exports = async function(robot, kredits) {
for (const recipient of recipients) {
try {
await createContribution(recipient, amount, 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); }
@@ -161,15 +166,15 @@ module.exports = async function(robot, kredits) {
}
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
let evt = req.header('X-GitHub-Event');
let data = req.body;
const evt = req.header('X-GitHub-Event');
const 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 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);
res.send(200);
}

View File

@@ -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 => {
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${contributor.name} for ${url}...`);
let contribution = {
contributorId: contributor.id,
amount: amount,
contributorIpfsHash: contributor.ipfsHash,
date,
amount: amount,
url,
description,
details,
@@ -141,6 +142,10 @@ module.exports = async function(robot, kredits) {
}
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 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}`;
}
return createContribution(user, amount, desc, url, details);
return createContribution(user, date, amount, desc, url, details);
}
function updateTimestampForNextFetch () {

50
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "3.0.0",
"version": "3.1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -255,6 +255,11 @@
"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": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz",
@@ -371,6 +376,15 @@
"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": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
@@ -841,14 +855,15 @@
}
},
"ipfs-http-client": {
"version": "30.1.1",
"resolved": "https://registry.npmjs.org/ipfs-http-client/-/ipfs-http-client-30.1.1.tgz",
"integrity": "sha512-tMqSwEhW57VnjHDBLjKKlgtAvlhkqVSR3oIFC0IiGnaM1nzcw7pbFBoHaFzl0PKIuXm40a5bJt85Rm2trYx+Ag==",
"version": "30.1.3",
"resolved": "https://registry.npmjs.org/ipfs-http-client/-/ipfs-http-client-30.1.3.tgz",
"integrity": "sha512-NQ7WTLKUZeoKaKXrTSLAtjASRYCR0bPdsolZf16Y7Gt7o3RfiPpFF+AqvP0xbekOV3/zhFj2Qyf6ShEV4CCtsQ==",
"requires": {
"async": "^2.6.1",
"bignumber.js": "^8.0.2",
"bl": "^3.0.0",
"bs58": "^4.0.1",
"buffer": "^5.2.1",
"cids": "~0.5.5",
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
"debug": "^4.1.0",
@@ -863,7 +878,7 @@
"is-ipfs": "~0.6.0",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
"iso-stream-http": "~0.1.1",
"iso-stream-http": "~0.1.2",
"iso-url": "~0.4.6",
"just-kebab-case": "^1.1.0",
"just-map-keys": "^1.1.0",
@@ -1160,13 +1175,25 @@
}
},
"kredits-contracts": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-4.0.0.tgz",
"integrity": "sha512-N7D1PPrfINXqm7f6SRU3+8eb7EyKjnR7xnBUwfEUUWvocr5xOmpkhekn3gMR6+jLJNvi8XTh0ao0jRWakRSFkw==",
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.1.1.tgz",
"integrity": "sha512-hEM/ZOcoYejOix8LMG/mMVQVoD/9q18yjQTXeQwuX2x/APP95CH8HK/UsPIqxXtMP1L3XklWnMuqTVbYUc5UYg==",
"requires": {
"ethers": "^4.0.27",
"ipfs-http-client": "^30.1.1",
"rsvp": "^4.8.2"
"kosmos-schemas": "^2.0.0",
"rsvp": "^4.8.2",
"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": {
@@ -1928,6 +1955,11 @@
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
"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": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "3.0.0",
"version": "3.1.1",
"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": "4.x",
"kredits-contracts": "^5.1.1",
"node-cron": "^2.0.3",
"node-fetch": "^2.3.0",
"prompt": "^1.0.0"