Skip to content

Commit 788ec59

Browse files
committed
Add CRUD issues
1 parent d584b1e commit 788ec59

File tree

7 files changed

+127
-3
lines changed

7 files changed

+127
-3
lines changed

gogs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.7.3"
17+
return "0.8.0"
1818
}
1919

2020
// Client represents a Gogs API client.

issue.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
"net/http"
12+
"time"
13+
)
14+
15+
type PullRequestMeta struct {
16+
HasMerged bool `json:"merged"`
17+
Merged *time.Time `json:"merged_at"`
18+
}
19+
20+
type Issue struct {
21+
ID int64 `json:"id"`
22+
Index int64 `json:"number"`
23+
State string `json:"state"`
24+
Title string `json:"title"`
25+
Body string `json:"body"`
26+
User *User `json:"user"`
27+
Labels []*Label `json:"labels"`
28+
Assignee *User `json:"assignee"`
29+
Milestone *Milestone `json:"milestone"`
30+
Comments int `json:"comments"`
31+
PullRequest *PullRequestMeta `json:"pull_request"`
32+
Created time.Time `json:"created_at"`
33+
Updated time.Time `json:"updated_at"`
34+
}
35+
36+
type ListIssueOption struct {
37+
Page int
38+
}
39+
40+
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
41+
issues := make([]*Issue, 0, 10)
42+
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
43+
}
44+
45+
func (c *Client) GetIssue(owner, repo string, index int) (*Issue, error) {
46+
issue := new(Issue)
47+
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
48+
}
49+
50+
type CreateIssueOption struct {
51+
Title string `json:"title" binding:"Required"`
52+
Body string `json:"body"`
53+
Assignee string `json:"assignee"`
54+
Milestone int64 `json:"milestone"`
55+
Labels []int64 `json:"labels"`
56+
}
57+
58+
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
59+
body, err := json.Marshal(&opt)
60+
if err != nil {
61+
return nil, err
62+
}
63+
issue := new(Issue)
64+
return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
65+
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), issue)
66+
}
67+
68+
type EditIssueOption struct {
69+
Title string `json:"title"`
70+
Body *string `json:"body"`
71+
Assignee *string `json:"assignee"`
72+
Milestone *int64 `json:"milestone"`
73+
}
74+
75+
func (c *Client) EditIssue(owner, repo string, index int, opt EditIssueOption) (*Issue, error) {
76+
body, err := json.Marshal(&opt)
77+
if err != nil {
78+
return nil, err
79+
}
80+
issue := new(Issue)
81+
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
82+
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), issue)
83+
}

issue_label.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
type Label struct {
8+
Name string `json:"name"`
9+
Color string `json:"color"`
10+
}

issue_milestone.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 "time"
8+
9+
type Milestone struct {
10+
ID int64 `json:"id"`
11+
State string `json:"state"`
12+
Title string `json:"title"`
13+
Description string `json:"description"`
14+
OpenIssues int `json:"open_issues"`
15+
ClosedIssues int `json:"closed_issues"`
16+
Closed *time.Time `json:"closed_at"`
17+
Deadline *time.Time `json:"due_on"`
18+
}

repo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Permission struct {
2020

2121
// Repository represents a API repository.
2222
type Repository struct {
23-
Id int64 `json:"id"`
24-
Owner User `json:"owner"`
23+
ID int64 `json:"id"`
24+
Owner *User `json:"owner"`
2525
FullName string `json:"full_name"`
2626
Private bool `json:"private"`
2727
Fork bool `json:"fork"`

repo_hooks.go

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ type PayloadRepo struct {
105105
DefaultBranch string `json:"default_branch"`
106106
}
107107

108+
var (
109+
_ Payloader = &CreatePayload{}
110+
_ Payloader = &PushPayload{}
111+
)
112+
108113
// _________ __
109114
// \_ ___ \_______ ____ _____ _/ |_ ____
110115
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \

utils.go

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ package gogs
77
func Bool(v bool) *bool {
88
return &v
99
}
10+
11+
func String(v string) *string {
12+
return &v
13+
}
14+
15+
func Int64(v int64) *int64 {
16+
return &v
17+
}

0 commit comments

Comments
 (0)