Add pull request
This commit is contained in:
parent
87e433464c
commit
5799eb65e0
6 changed files with 130 additions and 40 deletions
2
gogs.go
2
gogs.go
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "0.10.4"
|
return "0.11.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents a Gogs API client.
|
// Client represents a Gogs API client.
|
||||||
|
|
32
issue.go
32
issue.go
|
@ -11,25 +11,33 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type StateType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
STATE_OPEN StateType = "open"
|
||||||
|
STATE_CLOSED StateType = "closed"
|
||||||
|
)
|
||||||
|
|
||||||
type PullRequestMeta struct {
|
type PullRequestMeta struct {
|
||||||
HasMerged bool `json:"merged"`
|
HasMerged bool `json:"merged"`
|
||||||
Merged *time.Time `json:"merged_at"`
|
Merged *time.Time `json:"merged_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Index int64 `json:"number"`
|
Index int64 `json:"number"`
|
||||||
State string `json:"state"`
|
State StateType `json:"state"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
User *User `json:"user"`
|
User *User `json:"user"`
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Assignee *User `json:"assignee"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Assignee *User `json:"assignee"`
|
||||||
Comments int `json:"comments"`
|
Comments int `json:"comments"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
|
||||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
Created time.Time `json:"created_at"`
|
|
||||||
Updated time.Time `json:"updated_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListIssueOption struct {
|
type ListIssueOption struct {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import "time"
|
||||||
|
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
State string `json:"state"`
|
State StateType `json:"state"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
OpenIssues int `json:"open_issues"`
|
OpenIssues int `json:"open_issues"`
|
||||||
|
|
30
pull.go
Normal file
30
pull.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PullRequest represents a pull reqesut API object.
|
||||||
|
type PullRequest struct {
|
||||||
|
// Copied from issue.go
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Index int64 `json:"number"`
|
||||||
|
State StateType `json:"state"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
User *User `json:"user"`
|
||||||
|
Labels []*Label `json:"labels"`
|
||||||
|
Milestone *Milestone `json:"milestone"`
|
||||||
|
Assignee *User `json:"assignee"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
|
||||||
|
Mergeable *bool `json:"mergeable"`
|
||||||
|
HasMerged bool `json:"merged"`
|
||||||
|
Merged *time.Time `json:"merged_at"`
|
||||||
|
MergedCommitID *string `json:"merge_commit_sha"`
|
||||||
|
MergedBy *User `json:"merged_by"`
|
||||||
|
}
|
35
repo.go
35
repo.go
|
@ -20,22 +20,25 @@ type Permission struct {
|
||||||
|
|
||||||
// Repository represents a API repository.
|
// Repository represents a API repository.
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Owner *User `json:"owner"`
|
Owner *User `json:"owner"`
|
||||||
FullName string `json:"full_name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
FullName string `json:"full_name"`
|
||||||
Private bool `json:"private"`
|
Description string `json:"description"`
|
||||||
Fork bool `json:"fork"`
|
Private bool `json:"private"`
|
||||||
HtmlUrl string `json:"html_url"`
|
Fork bool `json:"fork"`
|
||||||
CloneUrl string `json:"clone_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
SshUrl string `json:"ssh_url"`
|
SSHURL string `json:"ssh_url"`
|
||||||
Stars int `json:"stars_count"`
|
CloneURL string `json:"clone_url"`
|
||||||
Forks int `json:"forks_count"`
|
Website string `json:"website"`
|
||||||
Watchers int `json:"watchers_count"`
|
Stars int `json:"stars_count"`
|
||||||
OpenIssues int `json:"open_issues_count"`
|
Forks int `json:"forks_count"`
|
||||||
Created time.Time `json:"created_at"`
|
Watchers int `json:"watchers_count"`
|
||||||
Updated time.Time `json:"updated_at"`
|
OpenIssues int `json:"open_issues_count"`
|
||||||
Permissions Permission `json:"permissions"`
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
Permissions *Permission `json:"permissions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||||
|
|
69
repo_hook.go
69
repo_hook.go
|
@ -118,6 +118,7 @@ type PayloadRepo struct {
|
||||||
var (
|
var (
|
||||||
_ Payloader = &CreatePayload{}
|
_ Payloader = &CreatePayload{}
|
||||||
_ Payloader = &PushPayload{}
|
_ Payloader = &PushPayload{}
|
||||||
|
_ Payloader = &PullRequestPayload{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// _________ __
|
// _________ __
|
||||||
|
@ -140,11 +141,7 @@ func (p *CreatePayload) SetSecret(secret string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
||||||
data, err := json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
if err != nil {
|
|
||||||
return []byte{}, err
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseCreateHook parses create event hook content.
|
// ParseCreateHook parses create event hook content.
|
||||||
|
@ -192,11 +189,7 @@ func (p *PushPayload) SetSecret(secret string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
||||||
data, err := json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
if err != nil {
|
|
||||||
return []byte{}, err
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePushHook parses push event hook content.
|
// ParsePushHook parses push event hook content.
|
||||||
|
@ -219,3 +212,59 @@ func ParsePushHook(raw []byte) (*PushPayload, error) {
|
||||||
func (p *PushPayload) Branch() string {
|
func (p *PushPayload) Branch() string {
|
||||||
return strings.Replace(p.Ref, "refs/heads/", "", -1)
|
return strings.Replace(p.Ref, "refs/heads/", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .___
|
||||||
|
// | | ______ ________ __ ____
|
||||||
|
// | |/ ___// ___/ | \_/ __ \
|
||||||
|
// | |\___ \ \___ \| | /\ ___/
|
||||||
|
// |___/____ >____ >____/ \___ >
|
||||||
|
// \/ \/ \/
|
||||||
|
|
||||||
|
type HookIssueAction string
|
||||||
|
|
||||||
|
const (
|
||||||
|
HOOK_ISSUE_OPENED HookIssueAction = "opened"
|
||||||
|
HOOK_ISSUE_CLOSED HookIssueAction = "closed"
|
||||||
|
HOOK_ISSUE_REOPENED HookIssueAction = "reopened"
|
||||||
|
HOOK_ISSUE_EDITED HookIssueAction = "edited"
|
||||||
|
HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned"
|
||||||
|
HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
|
||||||
|
HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
|
||||||
|
HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
|
||||||
|
HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ChangesFromPayload struct {
|
||||||
|
From string `json:"from"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChangesPayload struct {
|
||||||
|
Title *ChangesFromPayload `json:"title,omitempty"`
|
||||||
|
Body *ChangesFromPayload `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// __________ .__ .__ __________ __
|
||||||
|
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
|
||||||
|
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
||||||
|
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
|
||||||
|
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
|
||||||
|
// \/ \/ |__| \/ \/
|
||||||
|
|
||||||
|
// PullRequestPayload represents a payload information of pull request event.
|
||||||
|
type PullRequestPayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookIssueAction `json:"action"`
|
||||||
|
Index int64 `json:"number"`
|
||||||
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||||
|
PullRequest *PullRequest `json:"pull_request"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PullRequestPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue