MediaWiki integration & integration architecture improvements . #16

Merged
raucao merged 19 commits from feature/6-mediawiki_integration into master 2018-04-21 09:31:30 +00:00
4 changed files with 91 additions and 79 deletions
Showing only changes of commit c0c2f97dae - Show all commits

View File

@ -147,4 +147,8 @@ module.exports = async function(robot) {
require('./integrations/github')(robot, kredits);
if (typeof process.env.KREDITS_MEDIAWIKI_URL !== 'undefined') {
require('./integrations/mediawiki')(robot, kredits);
}
};

View File

@ -1,5 +1,7 @@
bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.
module.exports = async function(robot, kredits) {
robot.logger.debug('[hubot-kredits] Loading GitHub integration...')
bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.
bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.
const Contributor = kredits.Contributor;
const Operator = kredits.Operator;

bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
bumi commented 2018-04-19 11:38:20 +00:00 (Migrated from github.com)
Review

do we need a const util = require('util'); in this file?

do we need a `const util = require('util');` in this file?
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.
raucao commented 2018-04-19 11:40:25 +00:00 (Migrated from github.com)
Review

Please ignore the code until I have pushed all of my changes. Thanks.

Please ignore the code until I have pushed all of my changes. Thanks.

85
integrations/mediawiki.js Normal file
View File

@ -0,0 +1,85 @@
const util = require('util');
const fetch = require('node-fetch');
const groupArray = require('group-array');
module.exports = async function(robot, kredits) {
robot.logger.debug('[hubot-kredits] Loading MediaWiki integration...')
const Contributor = kredits.Contributor;
const Operator = kredits.Operator;
const apiURL = process.env.KREDITS_MEDIAWIKI_URL + 'api.php';
const robot = {
data: {},
brain: {
set(key, value) {
this.data[key] = value;
},
get(key) {
return this.data[key];
}
}
};
bumi commented 2018-04-20 11:26:37 +00:00 (Migrated from github.com)
Review

do we need to do a toLowerCase or something to compare the usernames?

do we need to do a toLowerCase or something to compare the usernames?
raucao commented 2018-04-21 08:16:31 +00:00 (Migrated from github.com)
Review

Ideally we have the correct usernames on the blockchain. I haven't looked into the MediaWiki specifics there.

Ideally we have the correct usernames on the blockchain. I haven't looked into the MediaWiki specifics there.
bumi commented 2018-04-21 09:28:54 +00:00 (Migrated from github.com)
Review

we only have the usernames in the IPFS profile. which actually is fine because we want to store as little as possible in the contract

we only have the usernames in the IPFS profile. which actually is fine because we want to store as little as possible in the contract
function fetchChanges () {
const params = [
'action=query',
bumi commented 2018-04-20 11:27:26 +00:00 (Migrated from github.com)
Review

could provider an error message here, something like contributor not found ${username}

could provider an error message here, something like `contributor not found ${username}`
'format=json',
'list=recentchanges',
'rctype=edit|new',
'rcshow=!minor|!bot|!anon|!redirect',
'rclimit=max',
'rcprop=ids|title|timestamp|user|sizes|comment|flags'
];
const url = `${apiURL}?${params.join('&')}`;
return fetch(url).then(res => {
if (res.status === 200) {
return res.json();
} else {
robot.logger.warn(`Fetching ${url} returned HTTP status ${res.status}:`);
robot.logger.warn(res.body);
throw Error('Unexpected response from '+url);
}
}).then(res => {
return res.query.recentchanges;
});
}
function groupChangesByUser (changes) {
return groupArray(changes, 'user');
}
function analyzeUserChanges (user, changes) {
robot.logger.info(`Analyzing ${changes.length} edits from ${user} ...`);
const results = {};
results.pagesCreated = changes.filter(c => c.type === 'new');
results.pagesChanged = changes.filter(c => c.type === 'edit');
results.linesAdded = changes
.map(c => { return (c.oldlen < c.newlen) ? (c.newlen - c.oldlen) : 0; })
.reduce((a, b) => a + b);
robot.logger.info(`Created ${results.pagesCreated.length} pages`);
robot.logger.info(`Edited ${results.pagesChanged.length} pages`);
robot.logger.info(`Added ${results.linesAdded} lines of text\n`);
return results;
}
function createProposalForUserChanges (user, changes) {
const details = analyzeUserChanges(user, changes);
// robot.logger.info(util.inspect(details));
}
fetchChanges()
.then(res => groupChangesByUser(res))
.then(res => {
Object.keys(res).forEach(user => createProposalForUserChanges(user, res[user]));
});
};

View File

@ -1,79 +0,0 @@
#!/usr/bin/env node
const util = require('util');
const fetch = require('node-fetch');
const groupArray = require('group-array');
if (typeof process.env.KREDITS_MEDIAWIKI_URL === 'undefined') { return false; }
const apiURL = process.env.KREDITS_MEDIAWIKI_URL + 'api.php';
const robot = {
data: {},
brain: {
set(key, value) {
this.data[key] = value;
},
get(key) {
return this.data[key];
}
}
};
function fetchChanges () {
const params = [
'action=query',
'format=json',
'list=recentchanges',
'rctype=edit|new',
'rcshow=!minor|!bot|!anon|!redirect',
'rclimit=max',
'rcprop=ids|title|timestamp|user|sizes|comment|flags'
];
const url = `${apiURL}?${params.join('&')}`;
return fetch(url).then(res => {
if (res.status === 200) {
return res.json();
} else {
console.log(`Fetching ${url} returned HTTP status ${res.status}:`);
console.log(res.body);
throw Error('Unexpected response from '+url);
}
}).then(res => {
return res.query.recentchanges;
});
}
function groupChangesByUser (changes) {
return groupArray(changes, 'user');
}
function analyzeUserChanges (user, changes) {
console.log(`Analyzing ${changes.length} edits from ${user} ...`);
const results = {};
results.pagesCreated = changes.filter(c => c.type === 'new');
results.pagesChanged = changes.filter(c => c.type === 'edit');
results.linesAdded = changes
.map(c => { return (c.oldlen < c.newlen) ? (c.newlen - c.oldlen) : 0; })
.reduce((a, b) => a + b);
console.log(`Created ${results.pagesCreated.length} pages`);
console.log(`Edited ${results.pagesChanged.length} pages`);
console.log(`Added ${results.linesAdded} lines of text\n`);
return results;
}
function createProposalForUserChanges (user, changes) {
const details = analyzeUserChanges(user, changes);
// console.log(util.inspect(details));
}
fetchChanges()
.then(res => groupChangesByUser(res))
.then(res => {
Object.keys(res).forEach(user => createProposalForUserChanges(user, res[user]));
});