This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
/
types.go
127 lines (109 loc) · 2.73 KB
/
types.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
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
"path"
"time"
)
type Event interface {
fmt.Stringer
Repo() string
Commit() string
Branch() string
}
type PushEvent struct {
Ref string `json:"ref"`
After string `json:"after"`
Before string `json:"before"`
Deleted bool `json:"deleted"`
Commits []*Commit `json:"commits"`
HeadCommit *Commit `json:"head_commit"`
Repository *Repository `json:"repository"`
Pusher *User `json:"pusher"`
}
func (e *PushEvent) Repo() string {
return e.Repository.Name
}
func (e *PushEvent) Commit() string {
return e.HeadCommit.Id
}
func (e *PushEvent) Branch() string {
return path.Base(e.Ref)
}
func (e *PushEvent) String() string {
return fmt.Sprintf(
"Push of %s[%s] by %s: %s => %s",
e.Repo(),
e.Ref,
e.Pusher.Name,
e.Before[0:7],
e.After[0:7],
)
}
type PullRequestEvent struct {
Action string `json:"action"`
Number int `json:"number"`
PullRequest *PullRequest `json:"pull_request"`
Repository *Repository `json:"repository"`
Sender *PRUser `json:"sender"`
}
func (e *PullRequestEvent) Repo() string {
return e.Repository.Name
}
func (e *PullRequestEvent) Commit() string {
return e.PullRequest.Head.Sha
}
func (e *PullRequestEvent) Branch() string {
return e.PullRequest.Head.Ref
}
func (e *PullRequestEvent) String() string {
return fmt.Sprintf(
"Pull Request %d %s by %s",
e.Number,
e.Action,
e.Sender.Login,
)
}
type Commit struct {
Id string `json:"id"`
Distinct bool `json:"distinct"`
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
Url string `json:"url"`
Author *User `json:"author"`
Committer *User `json:"committer"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}
type Repository struct {
Id int `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
Description string `json:"description"`
}
type User struct {
Name string `json:"name"`
Email string `json:"email"`
Username string `json:"username"`
}
type PullRequest struct {
Url string `json:"url"`
Number int `json:"number"`
State string `json:"state"`
Title string `json:"title"`
User *PRUser `json:"user"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Head *PRBranch `json:"head"`
Base *PRBranch `json:"base"`
}
type PRUser struct {
Login string `json:"login"`
}
type PRBranch struct {
Label string `json:"label"`
Ref string `json:"ref"`
Sha string `json:"sha"`
User *PRUser `json:"user"`
Repo *Repository `json:"repo"`
}