-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitcoin-rss.js
104 lines (80 loc) · 3.76 KB
/
gitcoin-rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const util = require('util');
const fs = require('fs');
const tmp = require('tmp');
const nconf = require('nconf');
const Feed = require('feed');
var _ = require('lodash');
const format = require('./lib/format.js')
nconf.argv()
.env()
.file({ file: './config.json' });
const repository = require('./lib/repository.js')(nconf);
const contract = require('./lib/contract.js')(nconf);
const start = () => {
return new Promise((resolve, reject) => {
contract.getNumBounties((e, numBounties) => {
if (e) reject(e);
console.log(`numBounties ${numBounties}`);
const bountyArray = [];
for (let i = 0; i < 15 && i < numBounties - 1; i++) {
bountyArray.push(repository.dataForBounty(numBounties - 1 - i, contract));
}
Promise.all(bountyArray)
.then((vals) => {
console.log(`num bounties: ${vals.length}`);
// sort the bounty array according to created date
let mappedVals = vals.map((val) => JSON.parse(val))
let sortedVals = mappedVals.sort((b, a) => {
if (a.payload.created < b.payload.created) {
return -1;
} else if (a.payload.created > b.payload.created) {
return 1;
} else { return 0; }
});
sortedVals.forEach((val) => console.log(`${val.payload.created}: ${val.payload.title}`));
createFeedAndUpload(sortedVals);
})
.catch((err) => {
console.error(`error: ${err.stack}`);
reject(err);
});
const createFeedAndUpload = (bountyArray) => {
console.log(`creating new feed with ${bountyArray.length} bounties`);
let feed = new Feed({
title: 'Gitcoin Bounties (Unofficial)',
description: 'Gitcoin Bounties',
id: 'https://github.com/browep/gitcoin-rss',
link: 'https://github.com/browep/gitcoin-rss',
image: 'https://s3-us-west-2.amazonaws.com/gitcoin-rss/gitcoin-logo.png',
favicon: 'https://s3-us-west-2.amazonaws.com/gitcoin-rss/gitcoin-favicon.png',
copyright: 'see Gitcoin',
author: {
name: 'Paul Brower',
email: 'brower.paul@gmail.com',
link: 'https://github.com/browep/gitcoin-rss'
}
});
// if bountyArray does not have 15 elems, throw
if (!bountyArray || bountyArray.length < 15) throw "expecting at least 15 bounties";
bountyArray.forEach((bountyData) => {
try {
feed.addItem({
title: bountyData.payload.title,
link: bountyData.payload.webReferenceURL,
description: format.toHtml(_.get(bountyData, "payload.metadata.issueKeywords", bountyData.payload.description)),
content: format.toHtml(bountyData.payload.description),
})
} catch (err) {
console.error("issue with " + bountyData + " " + err.stack);
}
});
const rssContent = feed.rss2();
repository.uploadRss(rssContent, resolve, reject);
};
});
});
}
module.exports = {
start: start
};