Add CRUD issues
This commit is contained in:
parent
d584b1e0fb
commit
788ec59749
7 changed files with 127 additions and 3 deletions
2
gogs.go
2
gogs.go
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func Version() string {
|
||||
return "0.7.3"
|
||||
return "0.8.0"
|
||||
}
|
||||
|
||||
// Client represents a Gogs API client.
|
||||
|
|
83
issue.go
Normal file
83
issue.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
// 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 (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PullRequestMeta struct {
|
||||
HasMerged bool `json:"merged"`
|
||||
Merged *time.Time `json:"merged_at"`
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
ID int64 `json:"id"`
|
||||
Index int64 `json:"number"`
|
||||
State string `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"`
|
||||
Comments int `json:"comments"`
|
||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ListIssueOption struct {
|
||||
Page int
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||
issues := make([]*Issue, 0, 10)
|
||||
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
|
||||
}
|
||||
|
||||
func (c *Client) GetIssue(owner, repo string, index int) (*Issue, error) {
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
}
|
||||
|
||||
type CreateIssueOption struct {
|
||||
Title string `json:"title" binding:"Required"`
|
||||
Body string `json:"body"`
|
||||
Assignee string `json:"assignee"`
|
||||
Milestone int64 `json:"milestone"`
|
||||
Labels []int64 `json:"labels"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), issue)
|
||||
}
|
||||
|
||||
type EditIssueOption struct {
|
||||
Title string `json:"title"`
|
||||
Body *string `json:"body"`
|
||||
Assignee *string `json:"assignee"`
|
||||
Milestone *int64 `json:"milestone"`
|
||||
}
|
||||
|
||||
func (c *Client) EditIssue(owner, repo string, index int, opt EditIssueOption) (*Issue, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), issue)
|
||||
}
|
10
issue_label.go
Normal file
10
issue_label.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// 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
|
||||
|
||||
type Label struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
}
|
18
issue_milestone.go
Normal file
18
issue_milestone.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
// 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"
|
||||
|
||||
type Milestone struct {
|
||||
ID int64 `json:"id"`
|
||||
State string `json:"state"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
OpenIssues int `json:"open_issues"`
|
||||
ClosedIssues int `json:"closed_issues"`
|
||||
Closed *time.Time `json:"closed_at"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
4
repo.go
4
repo.go
|
@ -20,8 +20,8 @@ type Permission struct {
|
|||
|
||||
// Repository represents a API repository.
|
||||
type Repository struct {
|
||||
Id int64 `json:"id"`
|
||||
Owner User `json:"owner"`
|
||||
ID int64 `json:"id"`
|
||||
Owner *User `json:"owner"`
|
||||
FullName string `json:"full_name"`
|
||||
Private bool `json:"private"`
|
||||
Fork bool `json:"fork"`
|
||||
|
|
|
@ -105,6 +105,11 @@ type PayloadRepo struct {
|
|||
DefaultBranch string `json:"default_branch"`
|
||||
}
|
||||
|
||||
var (
|
||||
_ Payloader = &CreatePayload{}
|
||||
_ Payloader = &PushPayload{}
|
||||
)
|
||||
|
||||
// _________ __
|
||||
// \_ ___ \_______ ____ _____ _/ |_ ____
|
||||
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
||||
|
|
8
utils.go
8
utils.go
|
@ -7,3 +7,11 @@ package gogs
|
|||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func String(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
func Int64(v int64) *int64 {
|
||||
return &v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue