Created
September 10, 2014 08:54
-
-
Save adonaldson/863bb0188f6bd1ab9e1a to your computer and use it in GitHub Desktop.
Lighthouse ticket linker script for hubot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Turning mentions of tickets (#(\d+)) into Lighthouse URLs, with info | |
# | |
# Dependencies: | |
# None | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# #1323 #1142 #1231 | |
module.exports = (robot) -> | |
baseUrl = "https://YOURACCOUNT.lighthouseapp.com/projects/PROJECTID" | |
lighthouseToken = "YOURTOKEN" # Read-only token, project specific from Lighthouse | |
lowestTicketNumber = 2000 # Low-tech way to avoid super old tickets when talking about Github PRs | |
robot.hear /(#\d+)/gi, (msg) -> | |
ticketNumbers = msg.message.text.match(/(#\d+)/ig).slice(0, 5) | |
announceTicket = (ticketNumber) -> | |
ticketNumber = ticketNumber.replace('#', '') | |
if parseInt(ticketNumber, 10) < lowestTicketNumber | |
console.log "ticket #{ticketNumber} lower than #{lowestTicketNumber} - skipping" | |
return | |
try | |
msg.http("#{baseUrl}/tickets/#{ticketNumber}.json?_token=#{lighthouseToken}") | |
.get() (err, res, body) -> | |
if err | |
console.log "error getting ticket #{ticketNumber} - #{err}" | |
return | |
try | |
parsed = JSON.parse(body) | |
ticket = parsed.ticket | |
msg.send "##{ticket.number}: #{ticket.title}\n#{ticket.url}" | |
catch error | |
console.log "lighthouse linker parsing JSON error: #{error}" | |
catch error | |
console.log "lighthouse linker error: #{error}" | |
announceTicket ticketNumber for ticketNumber in ticketNumbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment