1 | _ = require "underscore"
|
2 | moment = require "moment"
|
3 | Octokat = require "octokat"
|
4 |
|
5 | Config = require "../config"
|
6 | PullRequest = require "./pullrequest"
|
7 | Utils = require "../utils"
|
8 |
|
9 | octo = new Octokat token: Config.github.token
|
10 |
|
11 | class 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 |
|
28 | module.exports = PullRequests
|