Create contributions instead of proposals
This commit is contained in:
parent
8cfbc222fc
commit
f39bd41098
@ -5,7 +5,7 @@
|
||||
This repository provides scripts for integrating [Kosmos
|
||||
Kredits](https://wiki.kosmos.org/Kredits) in [Hubot](http://hubot.github.com/)
|
||||
chatbots. The bot will watch for project-related things happening on the
|
||||
Internet and automatically create proposals for issuing kredits for project
|
||||
Internet and automatically create ERC721 tokens for issuing kredits for project
|
||||
contributions.
|
||||
|
||||
## Setup
|
||||
@ -33,7 +33,7 @@ As usual in Hubot, you can add all config as environment variables.
|
||||
The GitHub 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 proposals for all of them.
|
||||
issue contribution tokens for all of them.
|
||||
|
||||
#### Setup
|
||||
|
||||
@ -50,7 +50,7 @@ Point a GitHub organization webhook to the following URL:
|
||||
### MediaWiki
|
||||
|
||||
The MediaWiki integration will periodically check for wiki page creations and
|
||||
edits. It will create kredits proposals based on amount of text added.
|
||||
edits. It will create kredits contribution tokens based on amount of text added.
|
||||
|
||||
#### Setup
|
||||
|
||||
|
9
index.js
9
index.js
@ -121,6 +121,7 @@ module.exports = async function(robot) {
|
||||
ethProvider.resetEventsBlock(nextBlock);
|
||||
|
||||
Proposal.on('ProposalCreated', handleProposalCreated);
|
||||
Contribution.on('ContributionAdded', handleContributionAdded);
|
||||
});
|
||||
}
|
||||
|
||||
@ -133,6 +134,14 @@ module.exports = async function(robot) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleContributionAdded(contributionId, contributorId, amount) {
|
||||
Contributor.getById(contributorId).then((contributor) => {
|
||||
Contribution.getById(contributionId).then((contribution) => {
|
||||
robot.logger.debug(`[hubot-kredits] Contribution #${contribution.id} added (${contribution.description})`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
watchContractEvents();
|
||||
|
||||
//
|
||||
|
@ -16,7 +16,6 @@ module.exports = async function(robot, kredits) {
|
||||
}
|
||||
|
||||
const Contributor = kredits.Contributor;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
function getContributorByGithubUser(username) {
|
||||
@ -32,9 +31,9 @@ module.exports = async function(robot, kredits) {
|
||||
});
|
||||
}
|
||||
|
||||
function createProposal(githubUser, amount, description, url, details) {
|
||||
function createContribution(githubUser, amount, description, url, details) {
|
||||
return getContributorByGithubUser(githubUser).then(contributor => {
|
||||
robot.logger.debug(`[hubot-kredits] Creating proposal to issue ${amount}₭S to ${githubUser} for ${url}...`);
|
||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${githubUser} for ${url}...`);
|
||||
|
||||
let contributionAttr = {
|
||||
contributorId: contributor.id,
|
||||
@ -46,7 +45,7 @@ module.exports = async function(robot, kredits) {
|
||||
kind: 'dev'
|
||||
};
|
||||
|
||||
return Proposal.addProposal(contributionAttr).catch(error => {
|
||||
return Contribution.addContribution(contributionAttr).catch(error => {
|
||||
robot.logger.error(`[hubot-kredits] Error:`, error);
|
||||
messageRoom(`I wanted to propose giving kredits to GitHub user ${githubUser} for ${url}, but I cannot find their info. Please add them as a contributor: https://kredits.kosmos.org`);
|
||||
});
|
||||
@ -87,7 +86,7 @@ module.exports = async function(robot, kredits) {
|
||||
let description = `${repoName}: ${issue.title}`;
|
||||
|
||||
if (amount === 0) {
|
||||
robot.logger.info('[hubot-kredits] Proposal amount from issue label is zero; ignoring');
|
||||
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`);
|
||||
@ -100,15 +99,15 @@ module.exports = async function(robot, kredits) {
|
||||
recipients = [issue.user.login];
|
||||
}
|
||||
|
||||
let proposalPromises = [];
|
||||
let contributionPromises = [];
|
||||
recipients.forEach(recipient => {
|
||||
proposalPromises.push(
|
||||
createProposal(recipient, amount, description, web_url, issue)
|
||||
contributionPromises.push(
|
||||
createContribution(recipient, amount, description, web_url, issue)
|
||||
.catch(err => robot.logger.error(err))
|
||||
);
|
||||
});
|
||||
|
||||
return Promise.all(proposalPromises);
|
||||
return Promise.all(contributionPromises);
|
||||
}
|
||||
|
||||
function handleGitHubPullRequestClosed(data) {
|
||||
@ -137,23 +136,23 @@ module.exports = async function(robot, kredits) {
|
||||
let description = `${repoName}: ${pull_request.title}`;
|
||||
|
||||
if (amount === 0) {
|
||||
robot.logger.info('[hubot-kredits] Proposal amount from issue label is zero; ignoring');
|
||||
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 proposalPromises = [];
|
||||
let contributionPromises = [];
|
||||
recipients.forEach(recipient => {
|
||||
robot.logger.debug(`[hubot-kredits] Creating proposal for ${recipient}...`);
|
||||
proposalPromises.push(
|
||||
createProposal(recipient, amount, description, web_url, pull_request)
|
||||
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${recipient}...`);
|
||||
contributionPromises.push(
|
||||
createContribution(recipient, amount, description, web_url, pull_request)
|
||||
.catch(err => robot.logger.error(err))
|
||||
);
|
||||
});
|
||||
|
||||
return Promise.all(proposalPromises);
|
||||
return Promise.all(contributionPromises);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ module.exports = async function(robot, kredits) {
|
||||
robot.logger.debug('[hubot-kredits] Loading MediaWiki integration...')
|
||||
|
||||
const Contributor = kredits.Contributor;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
const wikiURL = process.env.KREDITS_MEDIAWIKI_URL;
|
||||
@ -30,9 +29,9 @@ module.exports = async function(robot, kredits) {
|
||||
});
|
||||
}
|
||||
|
||||
function createProposal(username, amount, description, url, details={}) {
|
||||
function createContribution(username, amount, description, url, details={}) {
|
||||
return getContributorByWikiUser(username).then(contributor => {
|
||||
robot.logger.debug(`[hubot-kredits] Creating proposal to issue ${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 = {
|
||||
contributorId: contributor.id,
|
||||
@ -44,8 +43,8 @@ module.exports = async function(robot, kredits) {
|
||||
kind: 'docs'
|
||||
};
|
||||
|
||||
return Proposal.addProposal(contribution).catch(error => {
|
||||
robot.logger.error(`[hubot-kredits] Adding proposal failed:`, error);
|
||||
return Contribution.addContribution(contribution).catch(error => {
|
||||
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error);
|
||||
});
|
||||
}).catch(() => {
|
||||
robot.logger.info(`[hubot-kredits] No contributor found for ${username}`);
|
||||
@ -107,11 +106,11 @@ module.exports = async function(robot, kredits) {
|
||||
return results;
|
||||
}
|
||||
|
||||
function createProposals (changes) {
|
||||
function createContributions (changes) {
|
||||
let promises = [];
|
||||
|
||||
Object.keys(changes).forEach(user => {
|
||||
promises.push(createProposalForUserChanges(user, changes[user]));
|
||||
promises.push(createContributionForUserChanges(user, changes[user]));
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
@ -136,7 +135,7 @@ module.exports = async function(robot, kredits) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
function createProposalForUserChanges (user, changes) {
|
||||
function createContributionForUserChanges (user, changes) {
|
||||
const details = analyzeUserChanges(user, changes);
|
||||
const amount = calculateAmountForChanges(details);
|
||||
|
||||
@ -157,7 +156,7 @@ module.exports = async function(robot, kredits) {
|
||||
url = `${wikiURL}index.php?title=${rc.title}&diff=${rc.revid}&oldid=${rc.old_revid}`;
|
||||
}
|
||||
|
||||
return createProposal(user, amount, desc, url, details);
|
||||
return createContribution(user, amount, desc, url, details);
|
||||
}
|
||||
|
||||
function updateTimestampForNextFetch () {
|
||||
@ -168,7 +167,7 @@ module.exports = async function(robot, kredits) {
|
||||
function processWikiChangesSinceLastRun () {
|
||||
fetchChanges()
|
||||
.then(res => groupChangesByUser(res))
|
||||
.then(res => createProposals(res))
|
||||
.then(res => createContributions(res))
|
||||
.then(() => updateTimestampForNextFetch());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user