Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
174bc24421 | |||
bd781e1937 | |||
5fd7e50893 | |||
c93ddaebee | |||
94dd9b5ef7 | |||
82fb429f44 | |||
|
dd89f96bee | ||
|
90bb475f0d | ||
|
dabd997004 | ||
|
c196ded52c | ||
|
f74ccdc7ff | ||
|
86dd3b6979 | ||
|
948e536327 | ||
|
b6b91bef5b | ||
|
7db7a83a34 | ||
2e840bcb2b | |||
09637121be | |||
86f614ceee |
@ -1,4 +1,4 @@
|
||||
[](https://www.npmjs.com/package/hubot-kredits)
|
||||
[](https://www.npmjs.com/package/@kredits/hubot-kredits)
|
||||
|
||||
# Hubot Kredits
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
const util = require('util');
|
||||
const fetch = require('node-fetch');
|
||||
const session = require('express-session');
|
||||
const grant = require('grant-express');
|
||||
const cors = require('cors');
|
||||
const grant = require('grant').express();
|
||||
const amountFromLabels = require('./utils/amount-from-labels');
|
||||
const kindFromLabels = require('./utils/kind-from-labels');
|
||||
|
||||
@ -184,11 +184,10 @@ module.exports = async function(robot, kredits) {
|
||||
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'),
|
||||
origin: (process.env.KREDITS_GRANT_ORIGIN || 'http://localhost:8888'),
|
||||
prefix: '/kredits/signup/connect',
|
||||
transport: 'session',
|
||||
response: 'tokens',
|
||||
path: '/kredits/signup'
|
||||
},
|
||||
github: {
|
||||
key: process.env.KREDITS_GITHUB_KEY,
|
||||
@ -203,7 +202,7 @@ module.exports = async function(robot, kredits) {
|
||||
saveUninitialized: false
|
||||
}));
|
||||
|
||||
robot.router.use('/kredits/signup', grant(grantConfig));
|
||||
robot.router.use(grant(grantConfig));
|
||||
|
||||
robot.router.get('/kredits/signup/github', async (req, res) => {
|
||||
const access_token = req.session.grant.response.access_token;
|
||||
|
@ -112,14 +112,10 @@ module.exports = async function(robot, kredits) {
|
||||
}
|
||||
|
||||
async function createContributions (changes) {
|
||||
let promises = [];
|
||||
|
||||
for (const user of Object.keys(changes)) {
|
||||
await createContributionForUserChanges(user, changes[user]);
|
||||
await sleep(60000);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function pageTitlesFromChanges(changes) {
|
||||
|
3789
package-lock.json
generated
3789
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kredits/hubot-kredits",
|
||||
"version": "4.0.1",
|
||||
"version": "4.1.0",
|
||||
"description": "Kosmos Kredits functionality for chat bots",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -11,21 +11,22 @@
|
||||
"review-kredits": "scripts/review-kredits.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/experimental": "5.0.0",
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"@ethersproject/experimental": "5.7.0",
|
||||
"@kredits/contracts": "^7.3.0",
|
||||
"axios": "^1.7.9",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"eth-provider": "^0.2.2",
|
||||
"dotenv": "^16.3.1",
|
||||
"eth-provider": "^0.13.6",
|
||||
"ethers": "^5.0.5",
|
||||
"express": "^4.17.1",
|
||||
"express-session": "^1.16.2",
|
||||
"grant-express": "^4.6.1",
|
||||
"express": "^4.18.2",
|
||||
"express-session": "^1.17.3",
|
||||
"grant-express": "^5.4.8",
|
||||
"group-array": "^1.0.0",
|
||||
"kosmos-schemas": "^1.1.2",
|
||||
"kosmos-schemas": "^2.2.1",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"prompt": "^1.0.0",
|
||||
"yargs": "^16.2.0"
|
||||
"node-fetch": "^2.6.12",
|
||||
"prompt": "^1.3.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -1,29 +1,25 @@
|
||||
const fetch = require('node-fetch');
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = class GiteaReviews {
|
||||
|
||||
token = null;
|
||||
client = null;
|
||||
kreditsAmounts = null;
|
||||
pageLimit = 100;
|
||||
pageLimit = 50;
|
||||
|
||||
constructor (token, kreditsAmounts) {
|
||||
this.token = token;
|
||||
this.kreditsAmounts = kreditsAmounts;
|
||||
}
|
||||
|
||||
async request (path) {
|
||||
return fetch(
|
||||
`https://gitea.kosmos.org/api/v1${path}`,
|
||||
{
|
||||
headers: {
|
||||
'accepts': 'application/json',
|
||||
'Authorization': `token ${this.token}`
|
||||
}
|
||||
this.client = axios.create({
|
||||
baseURL: 'https://gitea.kosmos.org/api/v1',
|
||||
headers: {
|
||||
'accepts': 'application/json',
|
||||
'Authorization': `token ${token}`
|
||||
}
|
||||
).then(response => response.json());
|
||||
});
|
||||
}
|
||||
|
||||
async getReviewContributions (repos, startDate, endDate) {
|
||||
let pulls = [];
|
||||
let reviewContributions = {}
|
||||
|
||||
await Promise.all(repos.map(async (repo) => {
|
||||
@ -32,17 +28,17 @@ module.exports = class GiteaReviews {
|
||||
|
||||
do {
|
||||
try {
|
||||
result = await this.request(`/repos/${repo}/pulls?state=closed&limit=${this.pageLimit}&page=${page}`);
|
||||
result = await this.client.get(`/repos/${repo}/pulls?state=closed&limit=${this.pageLimit}&page=${page}`);
|
||||
} catch(error) {
|
||||
console.log(`failed to fetch PRs for repo ${repo}:`, error.message);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result || result.length === 0) {
|
||||
if (!result || !result.data || result.data.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let pullRequests = result.filter(pr => {
|
||||
let pullRequests = result.data.filter(pr => {
|
||||
if (!pr.merged) return false; // only interested in merged PRs
|
||||
|
||||
// check if the PR has been merged in the given timeframe
|
||||
@ -56,21 +52,23 @@ module.exports = class GiteaReviews {
|
||||
await Promise.all(pullRequests.map(async (pr) => {
|
||||
let reviews;
|
||||
try {
|
||||
reviews = await this.request(`/repos/${repo}/pulls/${pr.number}/reviews`);
|
||||
reviews = await this.client.get(`/repos/${repo}/pulls/${pr.number}/reviews`);
|
||||
} catch(error) {
|
||||
console.log(`failed to fetch reviews for repo ${repo}, PR ${pr.number}:`, error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!reviews || reviews.length === 0) {
|
||||
if (!reviews || !reviews.data || reviews.data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
reviews = reviews.filter(review => {
|
||||
reviews = reviews.data.filter(review => {
|
||||
return ['APPROVED', 'REJECTED'].includes(review.state);
|
||||
});
|
||||
|
||||
reviews.forEach(review => {
|
||||
// console.debug(`Review from /repos/${repo}/pulls/${pr.number}`);
|
||||
|
||||
if (typeof reviewContributions[review.user.login] === 'undefined') {
|
||||
reviewContributions[review.user.login] = [];
|
||||
}
|
||||
@ -88,7 +86,7 @@ module.exports = class GiteaReviews {
|
||||
}));
|
||||
|
||||
page++;
|
||||
} while (result && result.length > 0);
|
||||
} while (result && result.data && result.data.length > 0);
|
||||
}));
|
||||
|
||||
return reviewContributions;
|
||||
|
@ -1,30 +1,26 @@
|
||||
const fetch = require('node-fetch');
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = class GithubReviews {
|
||||
|
||||
token = null;
|
||||
client = null;
|
||||
kreditsAmounts = null;
|
||||
pageLimit = 100;
|
||||
|
||||
constructor (token, kreditsAmounts) {
|
||||
this.token = token;
|
||||
this.kreditsAmounts = kreditsAmounts;
|
||||
}
|
||||
|
||||
async request (path) {
|
||||
return fetch(
|
||||
`https://api.github.com${path}`,
|
||||
{
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
'User-Agent': 'Kosmos Kredits for reviews',
|
||||
'Authorization': `token ${this.token}`
|
||||
}
|
||||
this.client = axios.create({
|
||||
baseURL: 'https://api.github.com',
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
'User-Agent': 'Kosmos Kredits for reviews',
|
||||
'Authorization': `token ${token}`
|
||||
}
|
||||
).then(response => response.json());
|
||||
});
|
||||
}
|
||||
|
||||
async getReviewContributions (repos, startDate, endDate) {
|
||||
let pulls = [];
|
||||
let reviewContributions = {}
|
||||
|
||||
await Promise.all(repos.map(async (repo) => {
|
||||
@ -33,17 +29,17 @@ module.exports = class GithubReviews {
|
||||
|
||||
do {
|
||||
try {
|
||||
result = await this.request(`/repos/${repo}/pulls?state=closed&perPage=${this.pageLimit}&page=${page}`);
|
||||
result = await this.client.get(`/repos/${repo}/pulls?state=closed&perPage=${this.pageLimit}&page=${page}`);
|
||||
} catch(error) {
|
||||
console.log(`failed to fetch PRs for repo ${repo}:`, error.message);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result || result.length === 0) {
|
||||
if (!result || !result.data || result.data.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let pullRequests = result.filter(pr => {
|
||||
let pullRequests = result.data.filter(pr => {
|
||||
if (!pr.merged_at) return false; // only interested in merged PRs
|
||||
|
||||
// check if the PR has been merged in the given timeframe
|
||||
@ -57,21 +53,23 @@ module.exports = class GithubReviews {
|
||||
await Promise.all(pullRequests.map(async (pr) => {
|
||||
let reviews;
|
||||
try {
|
||||
reviews = await this.request(`/repos/${repo}/pulls/${pr.number}/reviews`);
|
||||
reviews = await this.client.get(`/repos/${repo}/pulls/${pr.number}/reviews`);
|
||||
} catch(error) {
|
||||
console.log(`failed to fetch reviews for repo ${repo}, PR ${pr.number}:`, error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!reviews || reviews.length === 0) {
|
||||
if (!reviews || !reviews.data || reviews.data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
reviews = reviews.filter(review => {
|
||||
reviews = reviews.data.filter(review => {
|
||||
return ['APPROVED', 'REJECTED'].includes(review.state);
|
||||
});
|
||||
|
||||
reviews.forEach(review => {
|
||||
// console.debug(`Review from /repos/${repo}/pulls/${pr.number}`);
|
||||
|
||||
if (typeof reviewContributions[review.user.login] === 'undefined') {
|
||||
reviewContributions[review.user.login] = [];
|
||||
}
|
||||
@ -89,7 +87,7 @@ module.exports = class GithubReviews {
|
||||
}));
|
||||
|
||||
page++;
|
||||
} while (result && result.length > 0);
|
||||
} while (result && result.data && result.data.length > 0);
|
||||
}));
|
||||
|
||||
return reviewContributions;
|
||||
|
@ -1,25 +1,25 @@
|
||||
{
|
||||
"github": [
|
||||
"67P/botka",
|
||||
"67P/hal8000",
|
||||
"67P/hubot-kredits",
|
||||
"67P/hubot-remotestorage-logger",
|
||||
"67P/hyperchannel",
|
||||
"67P/kosmos-schemas",
|
||||
"67P/kredits-contracts",
|
||||
"67P/kredits-signup",
|
||||
"67P/kredits-web",
|
||||
"67P/remotestorage-module-kosmos",
|
||||
"67P/waves",
|
||||
"sockethub/sockethub"
|
||||
],
|
||||
"gitea": [
|
||||
"kosmos/akkounts",
|
||||
"kosmos/botka",
|
||||
"kosmos/chef",
|
||||
"kosmos/gitea.kosmos.org",
|
||||
"kosmos/hal8000",
|
||||
"kosmos/ipfs-cookbook",
|
||||
"kosmos/kredits-ipfs-pinner",
|
||||
"kosmos/rs-module-kosmos",
|
||||
"kosmos/schemas",
|
||||
"kosmos/website",
|
||||
"kosmos/wormhole"
|
||||
"kosmos/wormhole",
|
||||
"kredits/contracts",
|
||||
"kredits/ipfs-pinner"
|
||||
]
|
||||
}
|
@ -1,58 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
require('dotenv').config();
|
||||
|
||||
const yargs = require('yargs/yargs');
|
||||
const { hideBin } = require('yargs/helpers');
|
||||
const util = require('util');
|
||||
const fs = require('fs');
|
||||
|
||||
const GiteaReviews = require('./lib/gitea-reviews');
|
||||
const GithubReviews = require('./lib/github-reviews');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('kredits-contracts');
|
||||
const util = require('util');
|
||||
const NonceManager = require('@ethersproject/experimental').NonceManager;
|
||||
const Kredits = require('@kredits/contracts');
|
||||
|
||||
const yargs = require('yargs/yargs')
|
||||
const { hideBin } = require('yargs/helpers')
|
||||
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||
const walletJson = fs.readFileSync(walletPath);
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL || 'http://localhost:7545';
|
||||
|
||||
const ipfsConfig = {
|
||||
host: process.env.IPFS_API_HOST || 'localhost',
|
||||
port: process.env.IPFS_API_PORT || '5001',
|
||||
protocol: process.env.IPFS_API_PROTOCOL || 'http'
|
||||
protocol: process.env.IPFS_API_PROTOCOL || 'http',
|
||||
};
|
||||
console.log('ipfsConfig:', ipfsConfig);
|
||||
|
||||
const kreditsAmounts = {
|
||||
'kredits-1': 100,
|
||||
'kredits-2': 300,
|
||||
'kredits-3': 1000
|
||||
'kredits-3': 1000,
|
||||
};
|
||||
|
||||
const repos = require('../repos.json');
|
||||
const repos = require('./repos.json');
|
||||
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.option('start', {
|
||||
alias: 's',
|
||||
description: 'Include reviews for PRs merged after this date'
|
||||
description: 'Include reviews for PRs merged after this date',
|
||||
})
|
||||
.option('end', {
|
||||
alias: 'e',
|
||||
description: 'Include reviews for PRs merged before this date'
|
||||
description: 'Include reviews for PRs merged before this date',
|
||||
})
|
||||
.option('dry', {
|
||||
alias: 'd',
|
||||
type: 'boolean',
|
||||
description: 'Only list contribution details without creating them'
|
||||
description: 'Only list contribution details without creating them',
|
||||
})
|
||||
.help()
|
||||
.version()
|
||||
.demandOption('start', 'Please provide a start date')
|
||||
.default('end', function now () {
|
||||
return (new Date()).toISOString().split('.')[0]+"Z";
|
||||
.default('end', function now() {
|
||||
return new Date().toISOString().split('.')[0] + 'Z';
|
||||
})
|
||||
.example([
|
||||
['$0 --start 2020-11-01 --end 2020-11-30T23:59:59Z', 'Create contributions for reviews of pull requests merged in November 2020'],
|
||||
['$0 --start 2021-01-01', 'Create contributions for reviews of pull requests merged from Januar 2021 until now'],
|
||||
])
|
||||
.argv
|
||||
[
|
||||
'$0 --start 2020-11-01 --end 2020-11-30T23:59:59Z',
|
||||
'Create contributions for reviews of pull requests merged in November 2020',
|
||||
],
|
||||
[
|
||||
'$0 --start 2021-01-01',
|
||||
'Create contributions for reviews of pull requests merged from Januar 2021 until now',
|
||||
],
|
||||
]).argv;
|
||||
|
||||
const startTimestamp = Date.parse(argv.start);
|
||||
const endTimestamp = Date.parse(argv.end);
|
||||
@ -67,79 +77,106 @@ if (isNaN(endTimestamp)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// check for existence of GITHUB_TOKEN and GITEA_TOKEN
|
||||
if (!process.env.GITHUB_TOKEN || !process.env.GITEA_TOKEN) {
|
||||
console.log('Please set both GITHUB_TOKEN and GITEA_TOKEN');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const startDate = new Date(startTimestamp);
|
||||
const endDate = new Date(endTimestamp);
|
||||
|
||||
async function getAllReviews(repos, startDate, endDate) {
|
||||
const githubReviews = new GithubReviews(process.env.GITHUB_TOKEN, kreditsAmounts);
|
||||
const giteaReviews = new GiteaReviews(process.env.GITEA_TOKEN, kreditsAmounts);
|
||||
const githubReviews = new GithubReviews(
|
||||
process.env.GITHUB_TOKEN,
|
||||
kreditsAmounts
|
||||
);
|
||||
const giteaReviews = new GiteaReviews(
|
||||
process.env.GITEA_TOKEN,
|
||||
kreditsAmounts
|
||||
);
|
||||
|
||||
return Promise.all([
|
||||
githubReviews.getReviewContributions(repos.github, startDate, endDate),
|
||||
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate)
|
||||
]).then(reviews => {
|
||||
// console.log(util.inspect(reviews[0], { depth: 3, colors: true }));
|
||||
return { github: reviews[0], gitea: reviews[1] }
|
||||
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate),
|
||||
]).then((reviews) => {
|
||||
return { github: reviews[0], gitea: reviews[1] };
|
||||
});
|
||||
}
|
||||
|
||||
async function initializeKredits () {
|
||||
async function initializeKredits() {
|
||||
//
|
||||
// Ethereum provider/node setup
|
||||
// Wallet setup
|
||||
//
|
||||
|
||||
let ethProvider;
|
||||
if (providerUrl) {
|
||||
ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
||||
} else {
|
||||
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||
let wallet;
|
||||
try {
|
||||
wallet = await ethers.Wallet.fromEncryptedJson(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
||||
} catch(error) {
|
||||
console.warn('Could not load wallet:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Solidity VM provider/node setup
|
||||
//
|
||||
|
||||
console.log('Using blockchain node/API at', providerUrl);
|
||||
|
||||
const ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
||||
const signer = new NonceManager(wallet.connect(ethProvider));
|
||||
|
||||
//
|
||||
// Kredits contracts setup
|
||||
//
|
||||
|
||||
const opts = { ipfsConfig };
|
||||
if (daoAddress) {
|
||||
opts.addresses = { Kernel: daoAddress };
|
||||
}
|
||||
let kredits;
|
||||
|
||||
try {
|
||||
kredits = await new Kredits(ethProvider, null, opts).init();
|
||||
kredits = await new Kredits(signer.provider, signer, opts).init();
|
||||
} catch(error) {
|
||||
console.log('Could not set up kredits:', error);
|
||||
console.warn('Could not set up kredits:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Wallet address: ' + wallet.address);
|
||||
|
||||
//
|
||||
// Check robot's wallet balance and alert when it's broke
|
||||
//
|
||||
|
||||
ethProvider.getBalance(wallet.address).then(balance => {
|
||||
console.log('Wallet balance: ' + ethers.utils.formatEther(balance) + ' RBTC');
|
||||
if (balance.lt(ethers.utils.parseEther('0.0001'))) {
|
||||
console.warn(`I\'m broke! Please send some RBTC to ${wallet.address} first.`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
return kredits;
|
||||
}
|
||||
|
||||
async function generateContributionData(reviews, Contributor, startDate, endDate) {
|
||||
const dateFormatOptions = { year: 'numeric', month: 'long', day: 'numeric' };
|
||||
async function generateContributionData(reviews, Contributor) {
|
||||
const contributors = await Contributor.all();
|
||||
const contributionData = {};
|
||||
const now = (new Date()).toISOString().split('.')[0]+"Z";
|
||||
[date, time] = now.split('T');
|
||||
|
||||
const nextDay = new Date(endDate);
|
||||
nextDay.setUTCDate(nextDay.getUTCDate() + 1);
|
||||
nextDay.setUTCHours(0, 0, 0, 0);
|
||||
const nextDayStr = nextDay.toISOString().split('.')[0] + 'Z';
|
||||
[date, time] = nextDayStr.split('T');
|
||||
|
||||
function addContributionDataForPlatform(platform) {
|
||||
for (const [username, platformReviews] of Object.entries(reviews[platform])) {
|
||||
const contributor = contributors.find(c => {
|
||||
for (const [username, platformReviews] of Object.entries(
|
||||
reviews[platform]
|
||||
)) {
|
||||
const contributor = contributors.find((c) => {
|
||||
return c[`${platform}_username`] === username;
|
||||
});
|
||||
|
||||
if (!contributor) {
|
||||
console.log(`Could not find contributor for ${platform} user "${username}"`);
|
||||
console.log(
|
||||
`Could not find contributor for ${platform} user "${username}"`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const urls = platformReviews.map(review => review.pr.html_url);
|
||||
const urls = platformReviews.map((review) => review.pr.html_url);
|
||||
const kreditsAmount = platformReviews.reduce((amount, review) => {
|
||||
return review.kredits + amount;
|
||||
}, 0);
|
||||
@ -148,9 +185,6 @@ async function generateContributionData(reviews, Contributor, startDate, endDate
|
||||
contributionData[contributor.name].amount += kreditsAmount;
|
||||
contributionData[contributor.name].details.pullRequests.push(...urls);
|
||||
} else {
|
||||
const formattedStartDate = startDate.toLocaleString('en-us', dateFormatOptions);
|
||||
const formattedEndDate = endDate.toLocaleString('en-us', dateFormatOptions);
|
||||
|
||||
contributionData[contributor.name] = {
|
||||
contributorId: contributor.id,
|
||||
contributorIpfsHash: contributor.ipfsHash,
|
||||
@ -158,11 +192,11 @@ async function generateContributionData(reviews, Contributor, startDate, endDate
|
||||
time,
|
||||
amount: kreditsAmount,
|
||||
kind: 'dev',
|
||||
description: `PR reviews from ${formattedStartDate} to ${formattedEndDate}`,
|
||||
details: {
|
||||
'pullRequests': urls
|
||||
}
|
||||
}
|
||||
kind: 'review',
|
||||
pullRequests: urls,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,17 +207,40 @@ async function generateContributionData(reviews, Contributor, startDate, endDate
|
||||
return contributionData;
|
||||
}
|
||||
|
||||
Promise.all([initializeKredits(), getAllReviews(repos, startDate, endDate)]).then((values) => {
|
||||
Promise.all([
|
||||
initializeKredits(),
|
||||
getAllReviews(repos, startDate, endDate),
|
||||
]).then((values) => {
|
||||
const kredits = values[0];
|
||||
const reviews = values[1];
|
||||
const Contributor = kredits.Contributor;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
generateContributionData(reviews, kredits.Contributor, startDate, endDate).then(contributionData => {
|
||||
if (argv.dry) {
|
||||
console.log('contributions:');
|
||||
console.log(util.inspect(contributionData, { depth: 3, colors: true }));
|
||||
async function createContribution(nickname, attrs) {
|
||||
console.log(`Creating review contribution for ${nickname}...`);
|
||||
console.log(util.inspect(attrs, { depth: 1, colors: true }));
|
||||
|
||||
return Contribution.add(attrs)
|
||||
.catch(error => {
|
||||
console.error(`Error:`, error.message);
|
||||
});
|
||||
}
|
||||
|
||||
generateContributionData(reviews, Contributor).then(
|
||||
async (contributionData) => {
|
||||
if (argv.dry) {
|
||||
console.log('Contributions:');
|
||||
console.log(util.inspect(contributionData, { depth: 3, colors: true }));
|
||||
return;
|
||||
} else {
|
||||
for (const nickname of Object.keys(contributionData)) {
|
||||
const description = `Reviewed ${contributionData[nickname].details.pullRequests.length} pull requests (from ${startDate.toISOString().split('T')[0]} to ${endDate.toISOString().split('T')[0]})`;
|
||||
await createContribution(nickname, {
|
||||
...contributionData[nickname],
|
||||
description,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO create contributions
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user