MediaWiki integration & integration architecture improvements . #16
4
index.js
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
|
|
||||
module.exports = async function(robot, kredits) {
|
||||
|
||||
robot.logger.debug('[hubot-kredits] Loading GitHub integration...')
|
||||
|
do we need a do we need a `const util = require('util');` in this file?
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.
|
||||
|
||||
|
do we need a do we need a `const util = require('util');` in this file?
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;
|
||||
|
||||
|
||||
|
do we need a do we need a `const util = require('util');` in this file?
do we need a do we need a `const util = require('util');` in this file?
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.
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
@ -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];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
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?
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.
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',
|
||||
|
could provider an error message here, something like 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]));
|
||||
});
|
||||
|
||||
};
|
||||
79
mediawiki.js
@ -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]));
|
||||
});
|
||||
do we need a
const util = require('util');in this file?do we need a
const util = require('util');in this file?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.