Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 5799eb6

Browse files
committed
Add pull request
1 parent 87e4334 commit 5799eb6

File tree

6 files changed

+130
-40
lines changed

6 files changed

+130
-40
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.10.4"
17+
return "0.11.0"
1818
}
1919

2020
// Client represents a Gogs API client.

issue.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,33 @@ import (
1111
"time"
1212
)
1313

14+
type StateType string
15+
16+
const (
17+
STATE_OPEN StateType = "open"
18+
STATE_CLOSED StateType = "closed"
19+
)
20+
1421
type PullRequestMeta struct {
1522
HasMerged bool `json:"merged"`
1623
Merged *time.Time `json:"merged_at"`
1724
}
1825

1926
type Issue struct {
20-
ID int64 `json:"id"`
21-
Index int64 `json:"number"`
22-
State string `json:"state"`
23-
Title string `json:"title"`
24-
Body string `json:"body"`
25-
User *User `json:"user"`
26-
Labels []*Label `json:"labels"`
27-
Assignee *User `json:"assignee"`
28-
Milestone *Milestone `json:"milestone"`
29-
Comments int `json:"comments"`
27+
ID int64 `json:"id"`
28+
Index int64 `json:"number"`
29+
State StateType `json:"state"`
30+
Title string `json:"title"`
31+
Body string `json:"body"`
32+
User *User `json:"user"`
33+
Labels []*Label `json:"labels"`
34+
Milestone *Milestone `json:"milestone"`
35+
Assignee *User `json:"assignee"`
36+
Comments int `json:"comments"`
37+
Created time.Time `json:"created_at"`
38+
Updated time.Time `json:"updated_at"`
39+
3040
PullRequest *PullRequestMeta `json:"pull_request"`
31-
Created time.Time `json:"created_at"`
32-
Updated time.Time `json:"updated_at"`
3341
}
3442

3543
type ListIssueOption struct {

issue_milestone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "time"
88

99
type Milestone struct {
1010
ID int64 `json:"id"`
11-
State string `json:"state"`
11+
State StateType `json:"state"`
1212
Title string `json:"title"`
1313
Description string `json:"description"`
1414
OpenIssues int `json:"open_issues"`

pull.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Gogs Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gogs
6+
7+
import (
8+
"time"
9+
)
10+
11+
// PullRequest represents a pull reqesut API object.
12+
type PullRequest struct {
13+
// Copied from issue.go
14+
ID int64 `json:"id"`
15+
Index int64 `json:"number"`
16+
State StateType `json:"state"`
17+
Title string `json:"title"`
18+
Body string `json:"body"`
19+
User *User `json:"user"`
20+
Labels []*Label `json:"labels"`
21+
Milestone *Milestone `json:"milestone"`
22+
Assignee *User `json:"assignee"`
23+
Comments int `json:"comments"`
24+
25+
Mergeable *bool `json:"mergeable"`
26+
HasMerged bool `json:"merged"`
27+
Merged *time.Time `json:"merged_at"`
28+
MergedCommitID *string `json:"merge_commit_sha"`
29+
MergedBy *User `json:"merged_by"`
30+
}

repo.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ type Permission struct {
2020

2121
// Repository represents a API repository.
2222
type Repository struct {
23-
ID int64 `json:"id"`
24-
Owner *User `json:"owner"`
25-
FullName string `json:"full_name"`
26-
Description string `json:"description"`
27-
Private bool `json:"private"`
28-
Fork bool `json:"fork"`
29-
HtmlUrl string `json:"html_url"`
30-
CloneUrl string `json:"clone_url"`
31-
SshUrl string `json:"ssh_url"`
32-
Stars int `json:"stars_count"`
33-
Forks int `json:"forks_count"`
34-
Watchers int `json:"watchers_count"`
35-
OpenIssues int `json:"open_issues_count"`
36-
Created time.Time `json:"created_at"`
37-
Updated time.Time `json:"updated_at"`
38-
Permissions Permission `json:"permissions"`
23+
ID int64 `json:"id"`
24+
Owner *User `json:"owner"`
25+
Name string `json:"name"`
26+
FullName string `json:"full_name"`
27+
Description string `json:"description"`
28+
Private bool `json:"private"`
29+
Fork bool `json:"fork"`
30+
HTMLURL string `json:"html_url"`
31+
SSHURL string `json:"ssh_url"`
32+
CloneURL string `json:"clone_url"`
33+
Website string `json:"website"`
34+
Stars int `json:"stars_count"`
35+
Forks int `json:"forks_count"`
36+
Watchers int `json:"watchers_count"`
37+
OpenIssues int `json:"open_issues_count"`
38+
DefaultBranch string `json:"default_branch"`
39+
Created time.Time `json:"created_at"`
40+
Updated time.Time `json:"updated_at"`
41+
Permissions *Permission `json:"permissions,omitempty"`
3942
}
4043

4144
// ListMyRepos lists all repositories for the authenticated user that has access to.

repo_hook.go

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type PayloadRepo struct {
118118
var (
119119
_ Payloader = &CreatePayload{}
120120
_ Payloader = &PushPayload{}
121+
_ Payloader = &PullRequestPayload{}
121122
)
122123

123124
// _________ __
@@ -140,11 +141,7 @@ func (p *CreatePayload) SetSecret(secret string) {
140141
}
141142

142143
func (p *CreatePayload) JSONPayload() ([]byte, error) {
143-
data, err := json.MarshalIndent(p, "", " ")
144-
if err != nil {
145-
return []byte{}, err
146-
}
147-
return data, nil
144+
return json.MarshalIndent(p, "", " ")
148145
}
149146

150147
// ParseCreateHook parses create event hook content.
@@ -192,11 +189,7 @@ func (p *PushPayload) SetSecret(secret string) {
192189
}
193190

194191
func (p *PushPayload) JSONPayload() ([]byte, error) {
195-
data, err := json.MarshalIndent(p, "", " ")
196-
if err != nil {
197-
return []byte{}, err
198-
}
199-
return data, nil
192+
return json.MarshalIndent(p, "", " ")
200193
}
201194

202195
// ParsePushHook parses push event hook content.
@@ -219,3 +212,59 @@ func ParsePushHook(raw []byte) (*PushPayload, error) {
219212
func (p *PushPayload) Branch() string {
220213
return strings.Replace(p.Ref, "refs/heads/", "", -1)
221214
}
215+
216+
// .___
217+
// | | ______ ________ __ ____
218+
// | |/ ___// ___/ | \_/ __ \
219+
// | |\___ \ \___ \| | /\ ___/
220+
// |___/____ >____ >____/ \___ >
221+
// \/ \/ \/
222+
223+
type HookIssueAction string
224+
225+
const (
226+
HOOK_ISSUE_OPENED HookIssueAction = "opened"
227+
HOOK_ISSUE_CLOSED HookIssueAction = "closed"
228+
HOOK_ISSUE_REOPENED HookIssueAction = "reopened"
229+
HOOK_ISSUE_EDITED HookIssueAction = "edited"
230+
HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned"
231+
HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
232+
HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
233+
HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
234+
HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
235+
)
236+
237+
type ChangesFromPayload struct {
238+
From string `json:"from"`
239+
}
240+
241+
type ChangesPayload struct {
242+
Title *ChangesFromPayload `json:"title,omitempty"`
243+
Body *ChangesFromPayload `json:"body,omitempty"`
244+
}
245+
246+
// __________ .__ .__ __________ __
247+
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
248+
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
249+
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
250+
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
251+
// \/ \/ |__| \/ \/
252+
253+
// PullRequestPayload represents a payload information of pull request event.
254+
type PullRequestPayload struct {
255+
Secret string `json:"secret"`
256+
Action HookIssueAction `json:"action"`
257+
Index int64 `json:"number"`
258+
Changes *ChangesPayload `json:"changes,omitempty"`
259+
PullRequest *PullRequest `json:"pull_request"`
260+
Repository *Repository `json:"repository"`
261+
Sender *User `json:"sender"`
262+
}
263+
264+
func (p *PullRequestPayload) SetSecret(secret string) {
265+
p.Secret = secret
266+
}
267+
268+
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
269+
return json.MarshalIndent(p, "", " ")
270+
}

0 commit comments

Comments
 (0)