1 | Octokat = require "octokat"
|
2 | moment = require "moment"
|
3 |
|
4 | Config = require "../config"
|
5 | Utils = require "../utils"
|
6 |
|
7 | octo = new Octokat token: Config.github.token
|
8 |
|
9 | class PullRequest
|
10 | constructor: (json) ->
|
11 | @[k] = v for k,v of json
|
12 |
|
13 | toAttachment: ->
|
14 | github = octo.fromUrl(@assignee.url) if @assignee?.url
|
15 | Utils.lookupUserWithGithub(github).then (assignee) =>
|
16 | color: "#ff9933"
|
17 | author_name: @user.login
|
18 | author_icon: @user.avatarUrl
|
19 | author_link: @user.htmlUrl
|
20 | title: @title
|
21 | title_link: @htmlUrl
|
22 | fields: [
|
23 | title: "Updated"
|
24 | value: moment(@updatedAt).fromNow()
|
25 | short: yes
|
26 | ,
|
27 | title: "Status"
|
28 | value: if @mergeable then "Mergeable" else "Unresolved Conflicts"
|
29 | short: yes
|
30 | ,
|
31 | title: "Assignee"
|
32 | value: if assignee then "<@#{assignee.id}>" else "Unassigned"
|
33 | short: yes
|
34 | ,
|
35 | title: "Lines"
|
36 | value: "+#{@additions} -#{@deletions}"
|
37 | short: yes
|
38 | ]
|
39 | fallback: """
|
40 | *#{@title}* +#{@additions} -#{@deletions}
|
41 | Updated: *#{moment(@updatedAt).fromNow()}*
|
42 | Status: #{if @mergeable then "Mergeable" else "Unresolved Conflicts"}
|
43 | Author: #{@user.login}
|
44 | Assignee: #{if assignee then "#{assignee.name}" else "Unassigned"}
|
45 | """
|
46 |
|
47 | module.exports = PullRequest
|