14 Commits

Author SHA1 Message Date
3ac2774c4f 2.1.3 2018-09-09 15:36:52 +08:00
83990a36dc Merge pull request #23 from 67P/bugfix/mediawiki_cron_syntax
Fix mediawiki polling cron
2018-09-09 15:36:25 +08:00
c427d7c313 Fix mediawiki polling cron
Was doing every minute after 7am, instead of every day once at 7am.
2018-09-09 15:35:09 +08:00
8b1977b53e 2.1.2 2018-06-14 15:03:30 +02:00
189f7fe4ee Fix amount calculation
Was using the wrong object as argument.
2018-06-14 15:02:20 +02:00
a95bf0141e 2.1.1 2018-05-07 14:04:15 +02:00
b4f6fb7ef7 Add missing require 2018-05-07 14:03:50 +02:00
98f4516217 2.1.0 2018-05-06 21:15:04 +02:00
149bc0c052 Use new wrapper function for finding contributor
Fixes a bug with the find algo as well.
2018-05-06 21:14:04 +02:00
c190490d9b Add context to contribution description
It didn't actually say where the pages were edited, i.e. the wiki.
2018-05-06 21:12:57 +02:00
eb767a90f2 Deduplicate title of pages edited/created 2018-05-06 21:12:37 +02:00
156ea44f0d Use configured wiki URL for contribution details 2018-05-06 21:12:06 +02:00
ec7f4a4d33 2.0.1 2018-05-03 13:32:15 +02:00
5f9e237f36 Add missing keywords to package config 2018-05-03 13:31:13 +02:00
3 changed files with 21 additions and 21 deletions

View File

@@ -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);
@@ -173,6 +171,6 @@ module.exports = async function(robot, kredits) {
.then(() => updateTimestampForNextFetch());
}
cron.schedule('* 7 * * *', processWikiChangesSinceLastRun);
cron.schedule('0 7 * * *', processWikiChangesSinceLastRun);
};

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "2.0.0",
"version": "2.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "hubot-kredits",
"version": "2.0.0",
"version": "2.1.3",
"description": "Kosmos Kredits functionality for chat bots",
"main": "index.js",
"scripts": {
@@ -23,7 +23,9 @@
"url": "git+https://github.com/67P/hubot-kredits.git"
},
"keywords": [
"kosmos"
"kosmos",
"kredits",
"hubot-scripts"
],
"author": "Kosmos Developers <mail@kosmos.org>",
"contributors": [