UNPKG

774 Btext/coffeescriptView Raw
1_ = require "underscore"
2moment = require "moment"
3Octokat = require "octokat"
4
5Config = require "../config"
6PullRequest = require "./pullrequest"
7Utils = require "../utils"
8
9octo = new Octokat token: Config.github.token
10
11class PullRequests
12 constructor: (prs) ->
13 @prs = (new PullRequest p for p in prs)
14
15 @fromKey: (key) ->
16 octo.search.issues.fetch
17 q: "#{key} @#{Config.github.organization} state:open type:pr"
18 .then (json) ->
19 return Promise.all json.items.map (issue) ->
20 octo.fromUrl(issue.pullRequest.url).fetch() if issue.pullRequest?.url
21 .then (issues) ->
22 new PullRequests _(issues).compact()
23
24 toAttachment: ->
25 attachments = (pr.toAttachment() for pr in @prs)
26 Promise.all attachments
27
28module.exports = PullRequests