Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 26 lines (26 sloc) 1.137 kb
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
# Show open issues from a Github repository.
#
# You need to set the following variables:
# HUBOT_GITHUB_TOKEN ="<oauth token>"
# HUBOT_GITHUB_USER ="<user name>"
#
# HUBOT_GITHUB_USER is optional, but if you set it, you can ask `show me issues
# for hubot` instead of `show me issues for github/hubot`.
#
# show me issues for <user/repo> -- Shows open issues for that project.
module.exports = (robot) ->
  robot.respond /show\s+(me\s+)?issues\s+(for\s+)?(.*)/i, (msg)->
    oauth_token = process.env.HUBOT_GITHUB_TOKEN
    repo = msg.match[3].toLowerCase()
    repo = "#{process.env.HUBOT_GITHUB_USER}/#{repo}" unless ~repo.indexOf("/")
    msg.http("https://api.github.com/repos/#{repo}/issues")
      .headers(Authorization: "token #{oauth_token}", Accept: "application/json")
      .query(state: "open", sort: "created")
      .get() (err, res, body) ->
        if err
          msg.send "GitHub says: #{err}"
          return
        issues = JSON.parse(body)
        for issue in issues
          labels = ("##{label.name}" for label in issue.labels)
          msg.send "[#{issue.number}] #{issue.title} #{labels.join(" ")}"
Something went wrong with that request. Please try again.