Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 157d2dee49 | |||
| 590ca961a6 | |||
| 6476fe5c88 | |||
| 101e35622a | |||
| afa67e5ac7 | |||
| cbbc6c359e | |||
| c16ea51769 | |||
| fc49213b01 | |||
| 32dc6a7358 | |||
| 53dee63a76 | |||
| 97ec6ce9bc | |||
| 342a5cd829 | |||
| 45064df737 | |||
| d9a9ad7793 | |||
| d65e92e1fe | |||
| 0fff3b1db0 | |||
| 1f1053e289 | |||
| 84f20efff0 | |||
| cd8343516f | |||
|
|
41c5903cf5 | ||
| 9a4dc43aa5 | |||
| 082bf4848d | |||
| 41dd813eaf | |||
| b35cbcc63a | |||
| 137e9eb4ed | |||
| 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 | |||
| 63057191d6 | |||
| 768c24da8e | |||
| 0fdd7d0f1c | |||
| 1e0d637c26 | |||
| dcbce66796 | |||
| 16b62a2545 | |||
| f39bd41098 | |||
| 8cfbc222fc | |||
| 21aaf2f3bf | |||
| 7056772066 | |||
| d854b4e0fb | |||
| 321fe95a27 | |||
| b38e6faf8a | |||
| bfaf26cc9a |
62
README.md
62
README.md
@@ -5,14 +5,34 @@
|
|||||||
This repository provides scripts for integrating [Kosmos
|
This repository provides scripts for integrating [Kosmos
|
||||||
Kredits](https://wiki.kosmos.org/Kredits) in [Hubot](http://hubot.github.com/)
|
Kredits](https://wiki.kosmos.org/Kredits) in [Hubot](http://hubot.github.com/)
|
||||||
chatbots. The bot will watch for project-related things happening on the
|
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.
|
contributions.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
|
### Ethereum wallet
|
||||||
|
|
||||||
You will need an Ethereum wallet for your bot, so it can interact with the
|
You will need an Ethereum wallet for your bot, so it can interact with the
|
||||||
Ethereum smart contracts. `npm run create-wallet` will do the job for you.
|
Ethereum smart contracts. `npm run create-wallet` will do the job for you.
|
||||||
|
|
||||||
|
The wallet must be funded with enough ETH to interact with the contracts.
|
||||||
|
|
||||||
|
### Contract permissions
|
||||||
|
|
||||||
|
The bot wallet needs the following Aragon contract permissions to interact
|
||||||
|
with [kredits-contracts]:
|
||||||
|
|
||||||
|
1. `ADD_CONTRIBUTION_ROLE` on the `Contribution` contract
|
||||||
|
2. `MANAGE_CONTRIBUTORS_ROLE` on the `Contributor` contract
|
||||||
|
|
||||||
|
These permissions can be configured using the [Aragon
|
||||||
|
CLI](https://hack.aragon.org/docs/cli-intro.html) (see [kredits-contracts].
|
||||||
|
|
||||||
|
aragon dao acl grant [DAO address] [contribution app address] ADD_CONTRIBUTION_ROLE [bot wallet address]
|
||||||
|
aragon dao acl grant [DAO address] [contributor app address] MANAGE_CONTRIBUTORS_ROLE [bot wallet address]
|
||||||
|
|
||||||
|
To get the `Contribution` and `Contributor` app addresses use `aragon dao apps`.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
As usual in Hubot, you can add all config as environment variables.
|
As usual in Hubot, you can add all config as environment variables.
|
||||||
@@ -24,7 +44,11 @@ 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) |
|
| `KREDITS_WEB_URL` | URL of the Kredits Web app (default: `https://kredits.kosmos.org`) |
|
||||||
|
| `KREDITS_DAO_ADDRESS` | DAO Kernel address |
|
||||||
|
| `KREDITS_SESSION_SECRET` | Secret used by [grant](https://www.npmjs.com/package/grant) to sign the session ID |
|
||||||
|
| `KREDITS_GRANT_HOST` | Host used by [grant](https://www.npmjs.com/package/grant) to generate OAuth redirect URLs (default: `localhost:8888`) |
|
||||||
|
| `KREDITS_GRANT_PROTOCOL` | Protocol (http or https) used by [grant](https://www.npmjs.com/package/grant") to generate the OAuth redirect URLs (default: "http") |
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
@@ -33,7 +57,13 @@ As usual in Hubot, you can add all config as environment variables.
|
|||||||
The GitHub integration will watch for closed issues and merged pull requests,
|
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,
|
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
|
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.
|
||||||
|
|
||||||
|
If `KREDITS_GITHUB_KEY` and `KREDITS_GITHUB_SECRET` are set, the bot will also
|
||||||
|
expose OAuth endpoints to authenticate new contributors and register new
|
||||||
|
contributor profiles on the smart contract. For this feature, a [GitHub OAuth
|
||||||
|
app] is required and the [OAuth grant config variables](#Configuration) must be
|
||||||
|
set.
|
||||||
|
|
||||||
#### Setup
|
#### Setup
|
||||||
|
|
||||||
@@ -46,11 +76,32 @@ Point a GitHub organization webhook to the following URL:
|
|||||||
| Key | Description |
|
| Key | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `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` |
|
||||||
|
| `KREDITS_GITHUB_KEY` | Key of the [GitHub OAuth app] used to authenticate contributors |
|
||||||
|
| `KREDITS_GITHUB_SECRET` | Secret of the [GitHub OAuth app] used to authenticate contributors |
|
||||||
|
|
||||||
|
### 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
|
||||||
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
|
#### Setup
|
||||||
|
|
||||||
@@ -62,3 +113,6 @@ wiki's API on its own.
|
|||||||
| Key | Description |
|
| Key | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `KREDITS_MEDIAWIKI_URL` | Your wiki URL, e.g. `https://wiki.kosmos.org/` |
|
| `KREDITS_MEDIAWIKI_URL` | Your wiki URL, e.g. `https://wiki.kosmos.org/` |
|
||||||
|
|
||||||
|
[kredits-contracts]: https://github.com/67P/kredits-contracts
|
||||||
|
[GitHub OAuth app]: https://developer.github.com/apps/about-apps/#about-oauth-apps
|
||||||
|
|||||||
48
index.js
48
index.js
@@ -6,8 +6,8 @@ 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 || 'http://localhost:7545';
|
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||||
const networkId = parseInt(process.env.KREDITS_NETWORK_ID || 100);
|
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
||||||
|
|
||||||
const ipfsConfig = {
|
const ipfsConfig = {
|
||||||
host: process.env.IPFS_API_HOST || 'localhost',
|
host: process.env.IPFS_API_HOST || 'localhost',
|
||||||
@@ -27,9 +27,9 @@ module.exports = async function(robot) {
|
|||||||
|
|
||||||
let wallet;
|
let wallet;
|
||||||
try {
|
try {
|
||||||
wallet = await ethers.Wallet.fromEncryptedWallet(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
wallet = await ethers.Wallet.fromEncryptedJson(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
robot.logger.warn('[hubot-kredits] Could not load wallet:', error);
|
robot.logger.warning('[hubot-kredits] Could not load wallet:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,23 +37,33 @@ module.exports = async function(robot) {
|
|||||||
// Ethereum provider/node setup
|
// Ethereum provider/node setup
|
||||||
//
|
//
|
||||||
|
|
||||||
const ethProvider = new ethers.providers.JsonRpcProvider(providerUrl, {chainId: networkId});
|
let ethProvider;
|
||||||
ethProvider.signer = wallet;
|
if (providerUrl) {
|
||||||
wallet.provider = ethProvider;
|
ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
||||||
|
} else {
|
||||||
|
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||||
|
}
|
||||||
|
const signer = wallet.connect(ethProvider);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Kredits contracts setup
|
// Kredits contracts setup
|
||||||
//
|
//
|
||||||
|
|
||||||
|
const opts = { ipfsConfig };
|
||||||
|
if (daoAddress) {
|
||||||
|
opts.addresses = { Kernel: daoAddress };
|
||||||
|
}
|
||||||
let kredits;
|
let kredits;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
kredits = await Kredits.setup(ethProvider, wallet, ipfsConfig);
|
kredits = await new Kredits(signer.provider, signer, opts).init();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
robot.logger.warn('[hubot-kredits] Could not set up kredits:', error);
|
robot.logger.warning('[hubot-kredits] Could not set up kredits:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const Contributor = kredits.Contributor;
|
const Contributor = kredits.Contributor;
|
||||||
const Operator = kredits.Operator;
|
const Proposal = kredits.Proposal;
|
||||||
|
const Contribution = kredits.Contribution;
|
||||||
|
|
||||||
robot.logger.info('[hubot-kredits] Wallet address: ' + wallet.address);
|
robot.logger.info('[hubot-kredits] Wallet address: ' + wallet.address);
|
||||||
|
|
||||||
@@ -74,7 +84,7 @@ module.exports = async function(robot) {
|
|||||||
|
|
||||||
robot.respond(/got ETH\??/i, res => {
|
robot.respond(/got ETH\??/i, res => {
|
||||||
ethProvider.getBalance(wallet.address).then((balance) => {
|
ethProvider.getBalance(wallet.address).then((balance) => {
|
||||||
res.send(`my wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
res.send(`My wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,7 +97,7 @@ module.exports = async function(robot) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
robot.respond(/list open proposals/i, res => {
|
robot.respond(/list open proposals/i, res => {
|
||||||
Operator.all().then((proposals) => {
|
Proposal.all().then((proposals) => {
|
||||||
proposals.forEach((proposal) => {
|
proposals.forEach((proposal) => {
|
||||||
if (!proposal.executed) {
|
if (!proposal.executed) {
|
||||||
Contributor.getById(proposal.contributorId).then((contributor) => {
|
Contributor.getById(proposal.contributorId).then((contributor) => {
|
||||||
@@ -111,19 +121,28 @@ module.exports = async function(robot) {
|
|||||||
robot.logger.debug(`[hubot-kredits] Watching events from block ${nextBlock} onward`);
|
robot.logger.debug(`[hubot-kredits] Watching events from block ${nextBlock} onward`);
|
||||||
ethProvider.resetEventsBlock(nextBlock);
|
ethProvider.resetEventsBlock(nextBlock);
|
||||||
|
|
||||||
Operator.on('ProposalCreated', handleProposalCreated);
|
Proposal.on('ProposalCreated', handleProposalCreated);
|
||||||
|
Contribution.on('ContributionAdded', handleContributionAdded);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) {
|
function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) {
|
||||||
Contributor.getById(contributorId).then((contributor) => {
|
Contributor.getById(contributorId).then((contributor) => {
|
||||||
Operator.getById(proposalId).then((proposal) => {
|
Proposal.getById(proposalId).then((proposal) => {
|
||||||
robot.logger.debug(`[hubot-kredits] Proposal created (${proposal.description})`);
|
robot.logger.debug(`[hubot-kredits] Proposal created (${proposal.description})`);
|
||||||
// messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`);
|
// messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
watchContractEvents();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -131,6 +150,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,14 @@
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const session = require('express-session');
|
||||||
|
const grant = require('grant-express');
|
||||||
|
const cors = require('cors');
|
||||||
|
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) {
|
module.exports = async function(robot, kredits) {
|
||||||
|
|
||||||
@@ -15,12 +24,14 @@ module.exports = async function(robot, kredits) {
|
|||||||
robot.logger.debug('[hubot-kredits] Ignoring GitHub actions from ', util.inspect(repoBlackList));
|
robot.logger.debug('[hubot-kredits] Ignoring GitHub actions from ', util.inspect(repoBlackList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kreditsWebUrl = process.env.KREDITS_WEB_URL || 'https://kredits.kosmos.org';
|
||||||
|
|
||||||
const Contributor = kredits.Contributor;
|
const Contributor = kredits.Contributor;
|
||||||
const Operator = kredits.Operator;
|
const Contribution = kredits.Contribution;
|
||||||
|
|
||||||
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) {
|
||||||
@@ -31,62 +42,48 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProposal(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 proposal to issue ${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
|
||||||
};
|
};
|
||||||
|
|
||||||
return Operator.addProposal(contributionAttr).catch(error => {
|
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);
|
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`);
|
messageRoom(`I tried to add a contribution for ${githubUser} for ${url}, but I encountered an error when submitting the tx:`);
|
||||||
|
messageRoom(error.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function amountFromIssueLabels(issue) {
|
async function handleGitHubIssueClosed(data) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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] Proposal amount from issue label is zero; ignoring');
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else if (repoBlackList.includes(repoName)) {
|
} else if (repoBlackList.includes(repoName)) {
|
||||||
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
||||||
@@ -99,23 +96,25 @@ module.exports = async function(robot, kredits) {
|
|||||||
recipients = [issue.user.login];
|
recipients = [issue.user.login];
|
||||||
}
|
}
|
||||||
|
|
||||||
let proposalPromises = [];
|
for (const recipient of recipients) {
|
||||||
recipients.forEach(recipient => {
|
try {
|
||||||
proposalPromises.push(
|
await createContribution(recipient, date, time, amount, kind, description, web_url, issue);
|
||||||
createProposal(recipient, amount, description, web_url, issue)
|
await sleep(60000);
|
||||||
.catch(err => robot.logger.error(err))
|
}
|
||||||
);
|
catch (err) { robot.logger.error(err); }
|
||||||
});
|
}
|
||||||
|
|
||||||
return Promise.all(proposalPromises);
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -130,34 +129,35 @@ module.exports = async function(robot, kredits) {
|
|||||||
}
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(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] Proposal amount from issue label is zero; ignoring');
|
robot.logger.info('[hubot-kredits] Kredits amount from issue label is zero; ignoring');
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else if (repoBlackList.includes(repoName)) {
|
} else if (repoBlackList.includes(repoName)) {
|
||||||
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
let proposalPromises = [];
|
for (const recipient of recipients) {
|
||||||
recipients.forEach(recipient => {
|
try {
|
||||||
console.debug(`[hubot-kredits] Creating proposal for ${recipient}...`);
|
await createContribution(recipient, date, time, amount, kind, description, web_url, pull_request);
|
||||||
proposalPromises.push(
|
await sleep(60000);
|
||||||
createProposal(recipient, amount, description, web_url, pull_request)
|
}
|
||||||
.catch(err => robot.logger.error(err))
|
catch (err) { robot.logger.error(err); }
|
||||||
);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(proposalPromises);
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -165,14 +165,107 @@ 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).then(() => res.send(200));
|
handleGitHubPullRequestClosed(data);
|
||||||
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
else if (evt === 'issues' && data.action === 'closed') {
|
else if (evt === 'issues' && data.action === 'closed') {
|
||||||
handleGitHubIssueClosed(data).then(() => res.send(200));
|
handleGitHubIssueClosed(data);
|
||||||
|
res.sendStatus(200);
|
||||||
} else {
|
} else {
|
||||||
res.send(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// GitHub signup
|
||||||
|
//
|
||||||
|
|
||||||
|
if (process.env.KREDITS_GITHUB_KEY && process.env.KREDITS_GITHUB_SECRET) {
|
||||||
|
const grantConfig = {
|
||||||
|
defaults: {
|
||||||
|
protocol: (process.env.KREDITS_GRANT_PROTOCOL || "http"),
|
||||||
|
host: (process.env.KREDITS_GRANT_HOST || 'localhost:8888'),
|
||||||
|
transport: 'session',
|
||||||
|
response: 'tokens',
|
||||||
|
path: '/kredits/signup'
|
||||||
|
},
|
||||||
|
github: {
|
||||||
|
key: process.env.KREDITS_GITHUB_KEY,
|
||||||
|
secret: process.env.KREDITS_GITHUB_SECRET,
|
||||||
|
callback: '/kredits/signup/github'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
robot.router.use(session({ secret: process.env.KREDITS_SESSION_SECRET || 'grant' }));
|
||||||
|
robot.router.use('/kredits/signup', grant(grantConfig));
|
||||||
|
|
||||||
|
robot.router.get('/kredits/signup/github', async (req, res) => {
|
||||||
|
const access_token = req.session.grant.response.access_token;
|
||||||
|
|
||||||
|
res.redirect(`${kreditsWebUrl}/signup/github#access_token=${access_token}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
robot.router.options('/kredits/signup/github', cors());
|
||||||
|
|
||||||
|
robot.router.post('/kredits/signup/github', cors(), async (req, res) => {
|
||||||
|
const accessToken = req.body.accessToken;
|
||||||
|
if (!accessToken) {
|
||||||
|
res.status(400).json({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const githubResponse = await fetch('https://api.github.com/user', {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/vnd.github.v3+json',
|
||||||
|
'Authorization': `token ${accessToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
robot.logger.error('[hubot-kredits] Fetching user data from GitHub failed:', error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (githubResponse.status >= 300) {
|
||||||
|
res.status(githubResponse.status).json({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const user = await githubResponse.json();
|
||||||
|
|
||||||
|
const contributor = await kredits.Contributor.findByAccount({
|
||||||
|
site: 'github.com',
|
||||||
|
username: user.login
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!contributor) {
|
||||||
|
let contributorAttr = {};
|
||||||
|
contributorAttr.account = req.body.account;
|
||||||
|
contributorAttr.name = user.name || user.login;
|
||||||
|
contributorAttr.kind = "person";
|
||||||
|
contributorAttr.url = user.blog;
|
||||||
|
contributorAttr.github_username = user.login;
|
||||||
|
contributorAttr.github_uid = user.id;
|
||||||
|
|
||||||
|
kredits.Contributor.add(contributorAttr, { gasLimit: 350000 })
|
||||||
|
.then(transaction => {
|
||||||
|
robot.logger.info('[hubot-kredits] Contributor added from GitHub signup', transaction.hash);
|
||||||
|
res.status(201);
|
||||||
|
res.json({
|
||||||
|
transactionHash: transaction.hash,
|
||||||
|
github_username: user.login
|
||||||
|
});
|
||||||
|
}, error => {
|
||||||
|
robot.logger.error(`[hubot-kredits] Adding contributor failed: ${error}`);
|
||||||
|
res.status(422);
|
||||||
|
res.json({ error })
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.json({
|
||||||
|
github_username: user.login
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
robot.logger.warning('[hubot-kredits] No KREDITS_GITHUB_KEY and KREDITS_GITHUB_SECRET configured for OAuth signup');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ const fetch = require('node-fetch');
|
|||||||
const groupArray = require('group-array');
|
const groupArray = require('group-array');
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron');
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = async function(robot, kredits) {
|
module.exports = async function(robot, kredits) {
|
||||||
|
|
||||||
function messageRoom(message) {
|
function messageRoom(message) {
|
||||||
@@ -13,7 +17,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
robot.logger.debug('[hubot-kredits] Loading MediaWiki integration...')
|
robot.logger.debug('[hubot-kredits] Loading MediaWiki integration...')
|
||||||
|
|
||||||
const Contributor = kredits.Contributor;
|
const Contributor = kredits.Contributor;
|
||||||
const Operator = kredits.Operator;
|
const Contribution = kredits.Contribution;
|
||||||
|
|
||||||
const wikiURL = process.env.KREDITS_MEDIAWIKI_URL;
|
const wikiURL = process.env.KREDITS_MEDIAWIKI_URL;
|
||||||
const apiURL = wikiURL + 'api.php';
|
const apiURL = wikiURL + 'api.php';
|
||||||
@@ -29,22 +33,23 @@ module.exports = async function(robot, kredits) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProposal(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 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 = {
|
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,
|
||||||
kind: 'docs'
|
kind: 'docs'
|
||||||
};
|
};
|
||||||
|
|
||||||
return Operator.addProposal(contribution).catch(error => {
|
return Contribution.addContribution(contribution).catch(error => {
|
||||||
robot.logger.error(`[hubot-kredits] Adding proposal failed:`, error);
|
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error);
|
||||||
});
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
robot.logger.info(`[hubot-kredits] No contributor found for ${username}`);
|
robot.logger.info(`[hubot-kredits] No contributor found for ${username}`);
|
||||||
@@ -106,14 +111,15 @@ module.exports = async function(robot, kredits) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProposals (changes) {
|
async function createContributions (changes) {
|
||||||
let promises = [];
|
let promises = [];
|
||||||
|
|
||||||
Object.keys(changes).forEach(user => {
|
for (const user of Object.keys(changes)) {
|
||||||
promises.push(createProposalForUserChanges(user, changes[user]));
|
await createContributionForUserChanges(user, changes[user]);
|
||||||
});
|
await sleep(60000);
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageTitlesFromChanges(changes) {
|
function pageTitlesFromChanges(changes) {
|
||||||
@@ -123,8 +129,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
function calculateAmountForChanges(details) {
|
function calculateAmountForChanges(details) {
|
||||||
let amount;
|
let amount;
|
||||||
|
|
||||||
if (details.charsAdded < 280) {
|
if (details.charsAdded < 500) {
|
||||||
// less than a tweet
|
|
||||||
amount = 500;
|
amount = 500;
|
||||||
} else if (details.charsAdded < 2000) {
|
} else if (details.charsAdded < 2000) {
|
||||||
amount = 1500;
|
amount = 1500;
|
||||||
@@ -135,7 +140,11 @@ module.exports = async function(robot, kredits) {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProposalForUserChanges (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);
|
||||||
|
|
||||||
@@ -156,7 +165,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 createProposal(user, amount, desc, url, details);
|
return createContribution(user, date, amount, desc, url, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTimestampForNextFetch () {
|
function updateTimestampForNextFetch () {
|
||||||
@@ -167,7 +176,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
function processWikiChangesSinceLastRun () {
|
function processWikiChangesSinceLastRun () {
|
||||||
fetchChanges()
|
fetchChanges()
|
||||||
.then(res => groupChangesByUser(res))
|
.then(res => groupChangesByUser(res))
|
||||||
.then(res => createProposals(res))
|
.then(res => createContributions(res))
|
||||||
.then(() => updateTimestampForNextFetch());
|
.then(() => 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;
|
||||||
|
};
|
||||||
2314
package-lock.json
generated
2314
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "2.1.3",
|
"version": "3.4.0",
|
||||||
"description": "Kosmos Kredits functionality for chat bots",
|
"description": "Kosmos Kredits functionality for chat bots",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -10,13 +10,18 @@
|
|||||||
"create-wallet": "scripts/create-wallet.js"
|
"create-wallet": "scripts/create-wallet.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ethers": "^3.0.15",
|
"cors": "^2.8.5",
|
||||||
"group-array": "^0.3.3",
|
"eth-provider": "^0.2.2",
|
||||||
|
"ethers": "^4.0.27",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"express-session": "^1.16.2",
|
||||||
|
"grant-express": "^4.6.1",
|
||||||
|
"group-array": "^1.0.0",
|
||||||
"kosmos-schemas": "^1.1.2",
|
"kosmos-schemas": "^1.1.2",
|
||||||
"node-cron": "^1.2.1",
|
"kredits-contracts": "^5.4.0",
|
||||||
"node-fetch": "^1.6.3",
|
"node-cron": "^2.0.3",
|
||||||
"prompt": "^1.0.0",
|
"node-fetch": "^2.3.0",
|
||||||
"kredits-contracts": "3.x"
|
"prompt": "^1.0.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user