forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue.go
68 lines (59 loc) · 1.84 KB
/
issue.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
package gogitlab
import (
"encoding/json"
)
const (
project_issues_url = "/projects/:id/issues"
)
type Milestone struct {
Id int `json:"id,omitempty"`
IId int `json:"iid,omitempty"`
ProjectId int `json:"project_id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
DueDate string `json:"due_date,omitempty"`
State string `json:"state,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at,omitempty"`
}
type Issue struct {
Id int `json:"id"`
IId int `json:"iid"`
ProjectId int `json:"project_id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Labels []string `json:"labels,omitempty"`
Milestone *Milestone `json:"milestone,omitempty"`
Assignee *User `json:"assignee,omitempty"`
Author *User `json:"author,omitempty"`
State string `json:"state,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
type IssueRequest struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
AssigneeId int `json:"assignee_id,omitempty"`
MilestoneId int `json:"milestone_id,omitempty"`
Labels string `json:"labels,omitempty"`
}
func (g *Gitlab) AddIssue(projectId string, req *IssueRequest) (issue *Issue, err error) {
params := map[string]string{
":id": projectId,
}
u := g.ResourceUrl(project_issues_url, params)
encodedRequest, err := json.Marshal(req)
if err != nil {
return
}
data, err := g.buildAndExecRequest("POST", u, encodedRequest)
if err != nil {
return
}
issue = new(Issue)
err = json.Unmarshal(data, issue)
if err != nil {
panic(err)
}
return
}