-
Notifications
You must be signed in to change notification settings - Fork 12
/
model.go
115 lines (96 loc) · 2 KB
/
model.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"github.com/google/go-github/github"
)
type (
Issue struct {
Number int
Repository Repository
User User
}
Issueable interface {
Issue() Issue
}
IssueComment struct {
IssueNumber int
Comment string
IsPullRequest bool
Repository Repository
User User
}
PullRequestEvent struct {
IssueNumber int
Action string
Head PullRequestBranch
Repository Repository
User User
}
StatusEvent struct {
SHA string
State string
Branches []Branch
Repository Repository
}
Repository struct {
Owner string
Name string
URL string
}
PullRequestBranch struct {
SHA string
Repository Repository
}
Branch struct {
SHA string // The SHA of the head commit of the branch
}
User struct {
Login string
}
)
func (i IssueComment) Issue() Issue {
return Issue{
Number: i.IssueNumber,
Repository: i.Repository,
User: i.User,
}
}
func (p PullRequestEvent) Issue() Issue {
return Issue{
Number: p.IssueNumber,
Repository: p.Repository,
User: p.User,
}
}
func (i Issue) Issue() Issue {
return i
}
func (i Issue) FullName() string {
return fmt.Sprintf("%s/%s#%d", i.Repository.Owner, i.Repository.Name, i.Number)
}
func prFullName(pr *github.PullRequest) string {
baseRepository := pr.Base.Repo
return fmt.Sprintf("%s/%s#%d", *baseRepository.Owner.Login, *baseRepository.Name, *pr.Number)
}
func prIssue(pr *github.PullRequest) Issue {
return Issue{
Number: *pr.Number,
Repository: baseRepository(pr),
User: User{
Login: *pr.User.Login,
},
}
}
func baseRepository(pr *github.PullRequest) Repository {
return repositoryInternalRepresentation(pr.Base.Repo)
}
func headRepository(pr *github.PullRequest) Repository {
return repositoryInternalRepresentation(pr.Head.Repo)
}
func repositoryInternalRepresentation(repo *github.Repository) Repository {
return Repository{
Owner: *repo.Owner.Login,
Name: *repo.Name,
URL: *repo.SSHURL,
}
}