|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
const url = require('url');
|
|
|
|
|
const util = require('util');
|
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
const groupArray = require('group-array');
|
|
|
|
|
@@ -14,21 +15,17 @@ module.exports = async function(robot, kredits) {
|
|
|
|
|
const Contributor = kredits.Contributor;
|
|
|
|
|
const Operator = kredits.Operator;
|
|
|
|
|
|
|
|
|
|
const apiURL = process.env.KREDITS_MEDIAWIKI_URL + 'api.php';
|
|
|
|
|
const wikiURL = process.env.KREDITS_MEDIAWIKI_URL;
|
|
|
|
|
const apiURL = wikiURL + 'api.php';
|
|
|
|
|
|
|
|
|
|
function getContributorByWikiUser(username) {
|
|
|
|
|
return Contributor.all().then(contributors => {
|
|
|
|
|
let contrib = contributors.find(c => {
|
|
|
|
|
if (typeof c.accounts !== 'object') { return false; }
|
|
|
|
|
return c.accounts.find(a => {
|
|
|
|
|
a.url === `${process.env.KREDITS_MEDIAWIKI_URL}User:${username}`;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
if (!contrib) {
|
|
|
|
|
throw new Error();
|
|
|
|
|
} else {
|
|
|
|
|
return contrib;
|
|
|
|
|
}
|
|
|
|
|
let account = {
|
|
|
|
|
site: url.parse(process.env.KREDITS_MEDIAWIKI_URL).hostname,
|
|
|
|
|
username: username
|
|
|
|
|
}
|
|
|
|
|
return Contributor.findByAccount(account).then(contributor => {
|
|
|
|
|
robot.logger.debug('CONTRIBUTOR: ', contributor)
|
|
|
|
|
if (contributor) { return contributor; } else { throw new Error(); }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -120,7 +117,7 @@ module.exports = async function(robot, kredits) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pageTitlesFromChanges(changes) {
|
|
|
|
|
return changes.map(c => `"${c.title}"`).join(', ');
|
|
|
|
|
return [...new Set(changes.map(c => `"${c.title}"`))].join(', ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function calculateAmountForChanges(details) {
|
|
|
|
|
@@ -140,7 +137,7 @@ module.exports = async function(robot, kredits) {
|
|
|
|
|
|
|
|
|
|
function createProposalForUserChanges (user, changes) {
|
|
|
|
|
const details = analyzeUserChanges(user, changes);
|
|
|
|
|
const amount = calculateAmountForChanges(changes);
|
|
|
|
|
const amount = calculateAmountForChanges(details);
|
|
|
|
|
|
|
|
|
|
let desc = `Added ${details.charsAdded} characters of text.`;
|
|
|
|
|
if (details.pagesChanged.length > 0) {
|
|
|
|
|
@@ -149,13 +146,14 @@ module.exports = async function(robot, kredits) {
|
|
|
|
|
if (details.pagesCreated.length > 0) {
|
|
|
|
|
desc = `Created ${pageTitlesFromChanges(details.pagesCreated)}. ${desc}`;
|
|
|
|
|
}
|
|
|
|
|
desc = `Wiki contributions: ${desc}`;
|
|
|
|
|
|
|
|
|
|
let url;
|
|
|
|
|
if (changes.length > 1) {
|
|
|
|
|
url = `https://wiki.kosmos.org/Special:Contributions/${user}?hideMinor=1`;
|
|
|
|
|
url = `${wikiURL}Special:Contributions/${user}?hideMinor=1`;
|
|
|
|
|
} else {
|
|
|
|
|
rc = changes[0];
|
|
|
|
|
url = `https://wiki.kosmos.org/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);
|
|
|
|
|
|