Add pull request

This commit is contained in:
Unknwon 2016-08-14 03:32:53 -07:00
parent 87e433464c
commit 5799eb65e0
6 changed files with 130 additions and 40 deletions

View file

@ -14,7 +14,7 @@ import (
)
func Version() string {
return "0.10.4"
return "0.11.0"
}
// Client represents a Gogs API client.

View file

@ -11,6 +11,13 @@ import (
"time"
)
type StateType string
const (
STATE_OPEN StateType = "open"
STATE_CLOSED StateType = "closed"
)
type PullRequestMeta struct {
HasMerged bool `json:"merged"`
Merged *time.Time `json:"merged_at"`
@ -19,17 +26,18 @@ type PullRequestMeta struct {
type Issue struct {
ID int64 `json:"id"`
Index int64 `json:"number"`
State string `json:"state"`
State StateType `json:"state"`
Title string `json:"title"`
Body string `json:"body"`
User *User `json:"user"`
Labels []*Label `json:"labels"`
Assignee *User `json:"assignee"`
Milestone *Milestone `json:"milestone"`
Assignee *User `json:"assignee"`
Comments int `json:"comments"`
PullRequest *PullRequestMeta `json:"pull_request"`
Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"`
PullRequest *PullRequestMeta `json:"pull_request"`
}
type ListIssueOption struct {

View file

@ -8,7 +8,7 @@ import "time"
type Milestone struct {
ID int64 `json:"id"`
State string `json:"state"`
State StateType `json:"state"`
Title string `json:"title"`
Description string `json:"description"`
OpenIssues int `json:"open_issues"`

30
pull.go Normal file
View 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"`
}

11
repo.go
View file

@ -22,20 +22,23 @@ type Permission struct {
type Repository struct {
ID int64 `json:"id"`
Owner *User `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Private bool `json:"private"`
Fork bool `json:"fork"`
HtmlUrl string `json:"html_url"`
CloneUrl string `json:"clone_url"`
SshUrl string `json:"ssh_url"`
HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
Website string `json:"website"`
Stars int `json:"stars_count"`
Forks int `json:"forks_count"`
Watchers int `json:"watchers_count"`
OpenIssues int `json:"open_issues_count"`
DefaultBranch string `json:"default_branch"`
Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"`
Permissions Permission `json:"permissions"`
Permissions *Permission `json:"permissions,omitempty"`
}
// ListMyRepos lists all repositories for the authenticated user that has access to.

View file

@ -118,6 +118,7 @@ type PayloadRepo struct {
var (
_ Payloader = &CreatePayload{}
_ Payloader = &PushPayload{}
_ Payloader = &PullRequestPayload{}
)
// _________ __
@ -140,11 +141,7 @@ func (p *CreatePayload) SetSecret(secret string) {
}
func (p *CreatePayload) JSONPayload() ([]byte, error) {
data, err := json.MarshalIndent(p, "", " ")
if err != nil {
return []byte{}, err
}
return data, nil
return json.MarshalIndent(p, "", " ")
}
// ParseCreateHook parses create event hook content.
@ -192,11 +189,7 @@ func (p *PushPayload) SetSecret(secret string) {
}
func (p *PushPayload) JSONPayload() ([]byte, error) {
data, err := json.MarshalIndent(p, "", " ")
if err != nil {
return []byte{}, err
}
return data, nil
return json.MarshalIndent(p, "", " ")
}
// ParsePushHook parses push event hook content.
@ -219,3 +212,59 @@ func ParsePushHook(raw []byte) (*PushPayload, error) {
func (p *PushPayload) Branch() string {
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, "", " ")
}