55package gitea
66
77import (
8- "bytes"
9- "encoding/json"
108 "fmt"
119)
1210
@@ -44,13 +42,9 @@ type CreateLabelOption struct {
4442
4543// CreateLabel create one label of repository
4644func (c * Client ) CreateLabel (owner , repo string , opt CreateLabelOption ) (* Label , error ) {
47- body , err := json .Marshal (& opt )
48- if err != nil {
49- return nil , err
50- }
5145 label := new (Label )
5246 return label , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/labels" , owner , repo ),
53- jsonHeader , bytes . NewReader ( body ) , label )
47+ jsonHeader , opt , label )
5448}
5549
5650// EditLabelOption options for editing a label
@@ -61,12 +55,8 @@ type EditLabelOption struct {
6155
6256// EditLabel modify one label with options
6357func (c * Client ) EditLabel (owner , repo string , id int64 , opt EditLabelOption ) (* Label , error ) {
64- body , err := json .Marshal (& opt )
65- if err != nil {
66- return nil , err
67- }
6858 label := new (Label )
69- return label , c .getParsedResponse ("PATCH" , fmt .Sprintf ("/repos/%s/%s/labels/%d" , owner , repo , id ), jsonHeader , bytes . NewReader ( body ) , label )
59+ return label , c .getParsedResponse ("PATCH" , fmt .Sprintf ("/repos/%s/%s/labels/%d" , owner , repo , id ), jsonHeader , opt , label )
7060}
7161
7262// DeleteLabel delete one label of repository by id
@@ -90,22 +80,14 @@ func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, erro
9080
9181// AddIssueLabels add one or more labels to one issue
9282func (c * Client ) AddIssueLabels (owner , repo string , index int64 , opt IssueLabelsOption ) ([]* Label , error ) {
93- body , err := json .Marshal (& opt )
94- if err != nil {
95- return nil , err
96- }
9783 var labels []* Label
98- return labels , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/issues/%d/labels" , owner , repo , index ), jsonHeader , bytes . NewReader ( body ) , & labels )
84+ return labels , c .getParsedResponse ("POST" , fmt .Sprintf ("/repos/%s/%s/issues/%d/labels" , owner , repo , index ), jsonHeader , opt , & labels )
9985}
10086
10187// ReplaceIssueLabels replace old labels of issue with new labels
10288func (c * Client ) ReplaceIssueLabels (owner , repo string , index int64 , opt IssueLabelsOption ) ([]* Label , error ) {
103- body , err := json .Marshal (& opt )
104- if err != nil {
105- return nil , err
106- }
10789 var labels []* Label
108- return labels , c .getParsedResponse ("PUT" , fmt .Sprintf ("/repos/%s/%s/issues/%d/labels" , owner , repo , index ), jsonHeader , bytes . NewReader ( body ) , & labels )
90+ return labels , c .getParsedResponse ("PUT" , fmt .Sprintf ("/repos/%s/%s/issues/%d/labels" , owner , repo , index ), jsonHeader , opt , & labels )
10991}
11092
11193// DeleteIssueLabel delete one label of one issue by issue id and label id
0 commit comments