- Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathissue_label.go
99 lines (83 loc) · 3.25 KB
/
issue_label.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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"
)
typeLabelstruct {
IDint64`json:"id"`
Namestring`json:"name"`
Colorstring`json:"color"`
URLstring`json:"url"`
}
func (c*Client) ListRepoLabels(owner, repostring) ([]*Label, error) {
labels:=make([]*Label, 0, 10)
returnlabels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
}
func (c*Client) GetRepoLabel(owner, repostring, idint64) (*Label, error) {
label:=new(Label)
returnlabel, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
}
typeCreateLabelOptionstruct {
Namestring`json:"name" binding:"Required"`
Colorstring`json:"color" binding:"Required;Size(7)"`
}
func (c*Client) CreateLabel(owner, repostring, optCreateLabelOption) (*Label, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
label:=new(Label)
returnlabel, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/labels", owner, repo),
jsonHeader, bytes.NewReader(body), label)
}
typeEditLabelOptionstruct {
Name*string`json:"name"`
Color*string`json:"color"`
}
func (c*Client) EditLabel(owner, repostring, idint64, optEditLabelOption) (*Label, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
label:=new(Label)
returnlabel, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
}
func (c*Client) DeleteLabel(owner, repostring, idint64) error {
_, err:=c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
returnerr
}
typeIssueLabelsOptionstruct {
Labels []int64`json:"labels"`
}
func (c*Client) GetIssueLabels(owner, repostring, indexint64) ([]*Label, error) {
labels:=make([]*Label, 0, 5)
returnlabels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels)
}
func (c*Client) AddIssueLabels(owner, repostring, indexint64, optIssueLabelsOption) ([]*Label, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
labels:=make([]*Label, 0)
returnlabels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
}
func (c*Client) ReplaceIssueLabels(owner, repostring, indexint64, optIssueLabelsOption) ([]*Label, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
labels:=make([]*Label, 0)
returnlabels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
}
func (c*Client) DeleteIssueLabel(owner, repostring, index, labelint64) error {
_, err:=c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
returnerr
}
func (c*Client) ClearIssueLabels(owner, repostring, indexint64) error {
_, err:=c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
returnerr
}