Merge pull request #30 from 67P/feature/29-date_time
Add contribution date
This commit is contained in:
commit
92c50ac69e
@ -13,7 +13,7 @@ module.exports = async function(robot, kredits) {
|
||||
|
||||
robot.logger.debug('[hubot-kredits] Loading GitHub integration...');
|
||||
|
||||
let repoBlackList = [];
|
||||
const repoBlackList = [];
|
||||
if (process.env.KREDITS_GITHUB_REPO_BLACKLIST) {
|
||||
repoBlackList = process.env.KREDITS_GITHUB_REPO_BLACKLIST.split(',');
|
||||
robot.logger.debug('[hubot-kredits] Ignoring GitHub actions from ', util.inspect(repoBlackList));
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
47
package-lock.json
generated
47
package-lock.json
generated
@ -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,24 @@
|
||||
}
|
||||
},
|
||||
"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.0",
|
||||
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.1.0.tgz",
|
||||
"integrity": "sha512-IALPPatInkA0khvSDr1/iooUAD2wnsC56ylKqWjhqq1vdOJHx8C/vpcIaKf3KVXS1RD/JpcBkASeHSv7TIXx/g==",
|
||||
"requires": {
|
||||
"ethers": "^4.0.27",
|
||||
"ipfs-http-client": "^30.1.1",
|
||||
"rsvp": "^4.8.2"
|
||||
"kosmos-schemas": "github:67P/kosmos-schemas#feature/contribution_date_time",
|
||||
"rsvp": "^4.8.2",
|
||||
"tv4": "^1.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"kosmos-schemas": {
|
||||
"version": "github:67P/kosmos-schemas#28a5e9f1fc2e083165e4e02ce3361c3f4fafa592",
|
||||
"from": "github:67P/kosmos-schemas#feature/contribution_date_time",
|
||||
"requires": {
|
||||
"brfs-babel": "^1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libp2p-crypto": {
|
||||
@ -1928,6 +1954,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",
|
||||
|
@ -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.x",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"prompt": "^1.0.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user