...
 
Commits (2)
{
"name": "fxabot",
"version": "0.2.5",
"version": "0.2.6",
"private": true,
"description": "Downtrodden dogsbody for the Firefox Accounts team.",
"keywords": [
......
......@@ -32,16 +32,18 @@ module.exports = robot => {
let pollInterval = POLL_INTERVAL || 60000
const headers = {
Authorization: `token ${GITHUB_TOKEN}`,
'User-Agent': USER_AGENT || 'philbooth',
}
const etag = robot.brain.get('etag')
if (etag) {
headers['If-None-Match'] = etag
}
try {
const headers = {
Authorization: `token ${GITHUB_TOKEN}`,
'User-Agent': USER_AGENT || 'philbooth',
}
const etag = robot.brain.get('etag')
if (etag) {
headers['If-None-Match'] = etag
}
const prs = JSON.parse(robot.brain.get('prs') || '{}')
const response = await request({
uri: 'https://api.github.com/repos/mozilla/fxa/events',
headers,
......@@ -60,15 +62,17 @@ module.exports = robot => {
const events = JSON.parse(response.body)
if (Array.isArray(events)) {
const prs = new Set()
events.forEach(event => {
const { action, number, pull_request: pr } = event.payload
if (event.type === 'PullRequestEvent' && ACTIONS.has(action) && ! prs.has(number)) {
prs.add(number)
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}`)
}
})
robot.brain.set('prs', JSON.stringify(prs))
} else {
robot.logger.error('GitHub returned non-array response body')
}
......