This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
64 lines (60 loc) · 2.35 KB
/
index.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
// TODO Add calendar integration
// const PublicGcal = require('public-gcal')
// const gcal = new PublicGcal({
// API_key: process.env.IPFS_CALENDAR_API,
// calendarId: '[email protected]'
// })
const hackmd = require('generate-hackmd-links')
const Octo = require('octokat')
const gh = new Octo({
token: process.env.NODE_GITHUB_ISSUE_BOT
})
const path = require('path')
const Promise = require('bluebird')
const readFile = Promise.promisify(require('fs').readFile)
const atob = require('atob')
// This gets the list from the README of the repo, from the section `Facilitators and Notetakers`
function getNewRoles (repo, lastLead) {
return gh.repos(repo).readme.fetch()
.then((res) => {
var readme = atob(res.content)
// Dumbly read from the Header to the end of the document, looking for names per line
// Could be optimized to only look in that section
var facilitators = readme.substring(readme.lastIndexOf('Facilitators and Notetakers')).match(/\n- @.*/g)
facilitators = facilitators.map((item) => '@' + item.split('@')[1].toLowerCase())
var numFacilitators = facilitators.length
if (facilitators.indexOf(lastLead) !== -1) {
return {
lead: facilitators[(facilitators.indexOf(lastLead) + 1) % numFacilitators],
notetaker: facilitators[(facilitators.indexOf(lastLead) + 2) % numFacilitators]
}
} else {
// If you mess up, blame the @ipfs-helper
return {
lead: '@ipfs-helper',
notetaker: 'TBD'
}
}
})
}
function getLastLead (repo) {
return gh.repos(repo).issues.fetch({labels: 'calls', state: 'all'})
.then((res) => {
var issue = res.items[0].body
var lastLead = issue.substring(issue.lastIndexOf('All Hands Call')).match(/@[a-zA-Z0-9]*/g)[0]
return lastLead.toLowerCase()
}).then((lastLead) => {
return getNewRoles(repo, lastLead)
})
}
module.exports = function createIssue (issue) {
readFile(path.join(__dirname, issue.template), 'utf8').then((data) => {
return hackmd(data)
}).then((data) => {
return getLastLead(issue.repo).then((roles) => {
data = data.replace(/LEAD/, roles.lead)
data = data.replace(/NOTER/, roles.notetaker)
gh.repos(issue.repo).issues.create({title: issue.title, body: data, labels: issue.labels})
})
}).then((res) => res)
}