...
 
Commits (4)
{
"name": "fxabot",
"version": "0.2.6",
"version": "0.3.0",
"private": true,
"description": "Downtrodden dogsbody for the Firefox Accounts team.",
"keywords": [
......
......@@ -4,6 +4,11 @@
// Dependencies:
// "request-promise": "4.2.4"
//
// Configuration:
// GITHUB_TOKEN
// POLL_INTERVAL
// USER_AGENT
//
// Author:
// philbooth
......@@ -23,13 +28,12 @@ const ACTIONS = new Set([
'opened',
'reopened',
])
const EVENTS_URI = 'https://api.github.com/repos/mozilla/fxa/events'
module.exports = robot => {
poll()
async function poll () {
robot.logger.info('polling GitHub')
let pollInterval = POLL_INTERVAL || 60000
try {
......@@ -42,16 +46,21 @@ module.exports = robot => {
headers['If-None-Match'] = etag
}
robot.logger.info(`polling ${EVENTS_URI}, headers=${JSON.stringify(headers, null, ' ')}`)
robot.logger.debug(`PRs in brain: ${robot.brain.get('prs')}`)
const prs = JSON.parse(robot.brain.get('prs') || '{}')
const response = await request({
uri: 'https://api.github.com/repos/mozilla/fxa/events',
uri: EVENTS_URI,
headers,
resolveWithFullResponse: true,
simple: false,
})
if (response.statusCode === 200) {
robot.logger.debug(`GitHub response headers: ${response.headers}`)
if (response.headers.etag) {
robot.brain.set('etag', response.headers.etag)
}
......@@ -67,8 +76,15 @@ module.exports = robot => {
const key = `${number}-${action}`
if (event.type === 'PullRequestEvent' && ACTIONS.has(action) && ! prs[key]) {
prs[key] = true
const room = robot.adapterName === 'irc' ? '#fxa' : 'fxa'
robot.messageRoom(room, `PR #${number}: ${action}\n${pr.html_url}`)
let room = 'fxa'
let message = `PR #${number}: ${action} by ${pr.user.login}\n${pr.html_url}`
if (robot.adapterName === 'irc') {
room = `#${room}`
message = `${message}\n${pr.title}`
}
robot.messageRoom(room, message)
}
})
......@@ -77,7 +93,7 @@ module.exports = robot => {
robot.logger.error('GitHub returned non-array response body')
}
} else {
robot.logger.info(`ignoring GitHub ${response.statusCode} response`)
robot.logger.warning(`ignoring GitHub ${response.statusCode} response`)
}
} catch (error) {
robot.logger.error(error.stack)
......