Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ac2774c4f | |||
| 83990a36dc | |||
| c427d7c313 | |||
| 8b1977b53e | |||
| 189f7fe4ee | |||
| a95bf0141e | |||
| b4f6fb7ef7 | |||
| 98f4516217 | |||
| 149bc0c052 | |||
| c190490d9b | |||
| eb767a90f2 | |||
| 156ea44f0d | |||
| ec7f4a4d33 | |||
| 5f9e237f36 |
@@ -1,3 +1,4 @@
|
|||||||
|
const url = require('url');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const groupArray = require('group-array');
|
const groupArray = require('group-array');
|
||||||
@@ -14,21 +15,17 @@ module.exports = async function(robot, kredits) {
|
|||||||
const Contributor = kredits.Contributor;
|
const Contributor = kredits.Contributor;
|
||||||
const Operator = kredits.Operator;
|
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) {
|
function getContributorByWikiUser(username) {
|
||||||
return Contributor.all().then(contributors => {
|
let account = {
|
||||||
let contrib = contributors.find(c => {
|
site: url.parse(process.env.KREDITS_MEDIAWIKI_URL).hostname,
|
||||||
if (typeof c.accounts !== 'object') { return false; }
|
username: username
|
||||||
return c.accounts.find(a => {
|
}
|
||||||
a.url === `${process.env.KREDITS_MEDIAWIKI_URL}User:${username}`;
|
return Contributor.findByAccount(account).then(contributor => {
|
||||||
});
|
robot.logger.debug('CONTRIBUTOR: ', contributor)
|
||||||
});
|
if (contributor) { return contributor; } else { throw new Error(); }
|
||||||
if (!contrib) {
|
|
||||||
throw new Error();
|
|
||||||
} else {
|
|
||||||
return contrib;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +117,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pageTitlesFromChanges(changes) {
|
function pageTitlesFromChanges(changes) {
|
||||||
return changes.map(c => `"${c.title}"`).join(', ');
|
return [...new Set(changes.map(c => `"${c.title}"`))].join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateAmountForChanges(details) {
|
function calculateAmountForChanges(details) {
|
||||||
@@ -140,7 +137,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
function createProposalForUserChanges (user, changes) {
|
function createProposalForUserChanges (user, changes) {
|
||||||
const details = analyzeUserChanges(user, changes);
|
const details = analyzeUserChanges(user, changes);
|
||||||
const amount = calculateAmountForChanges(changes);
|
const amount = calculateAmountForChanges(details);
|
||||||
|
|
||||||
let desc = `Added ${details.charsAdded} characters of text.`;
|
let desc = `Added ${details.charsAdded} characters of text.`;
|
||||||
if (details.pagesChanged.length > 0) {
|
if (details.pagesChanged.length > 0) {
|
||||||
@@ -149,13 +146,14 @@ module.exports = async function(robot, kredits) {
|
|||||||
if (details.pagesCreated.length > 0) {
|
if (details.pagesCreated.length > 0) {
|
||||||
desc = `Created ${pageTitlesFromChanges(details.pagesCreated)}. ${desc}`;
|
desc = `Created ${pageTitlesFromChanges(details.pagesCreated)}. ${desc}`;
|
||||||
}
|
}
|
||||||
|
desc = `Wiki contributions: ${desc}`;
|
||||||
|
|
||||||
let url;
|
let url;
|
||||||
if (changes.length > 1) {
|
if (changes.length > 1) {
|
||||||
url = `https://wiki.kosmos.org/Special:Contributions/${user}?hideMinor=1`;
|
url = `${wikiURL}Special:Contributions/${user}?hideMinor=1`;
|
||||||
} else {
|
} else {
|
||||||
rc = changes[0];
|
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);
|
return createProposal(user, amount, desc, url, details);
|
||||||
@@ -173,6 +171,6 @@ module.exports = async function(robot, kredits) {
|
|||||||
.then(() => updateTimestampForNextFetch());
|
.then(() => updateTimestampForNextFetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
cron.schedule('* 7 * * *', processWikiChangesSinceLastRun);
|
cron.schedule('0 7 * * *', processWikiChangesSinceLastRun);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "2.0.0",
|
"version": "2.1.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "2.0.0",
|
"version": "2.1.3",
|
||||||
"description": "Kosmos Kredits functionality for chat bots",
|
"description": "Kosmos Kredits functionality for chat bots",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -23,7 +23,9 @@
|
|||||||
"url": "git+https://github.com/67P/hubot-kredits.git"
|
"url": "git+https://github.com/67P/hubot-kredits.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"kosmos"
|
"kosmos",
|
||||||
|
"kredits",
|
||||||
|
"hubot-scripts"
|
||||||
],
|
],
|
||||||
"author": "Kosmos Developers <mail@kosmos.org>",
|
"author": "Kosmos Developers <mail@kosmos.org>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
|||||||
Reference in New Issue
Block a user