1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type IssueLinksService struct {
30 client *Client
31 }
32
33
34
35
36 type IssueLink struct {
37 SourceIssue *Issue `json:"source_issue"`
38 TargetIssue *Issue `json:"target_issue"`
39 LinkType string `json:"link_type"`
40 }
41
42
43
44
45
46 type IssueRelation struct {
47 ID int `json:"id"`
48 IID int `json:"iid"`
49 State string `json:"state"`
50 Description string `json:"description"`
51 Confidential bool `json:"confidential"`
52 Author *IssueAuthor `json:"author"`
53 Milestone *Milestone `json:"milestone"`
54 ProjectID int `json:"project_id"`
55 Assignees []*IssueAssignee `json:"assignees"`
56 Assignee *IssueAssignee `json:"assignee"`
57 UpdatedAt *time.Time `json:"updated_at"`
58 Title string `json:"title"`
59 CreatedAt *time.Time `json:"created_at"`
60 Labels Labels `json:"labels"`
61 DueDate *ISOTime `json:"due_date"`
62 WebURL string `json:"web_url"`
63 References *IssueReferences `json:"references"`
64 Weight int `json:"weight"`
65 UserNotesCount int `json:"user_notes_count"`
66 IssueLinkID int `json:"issue_link_id"`
67 LinkType string `json:"link_type"`
68 LinkCreatedAt *time.Time `json:"link_created_at"`
69 LinkUpdatedAt *time.Time `json:"link_updated_at"`
70 }
71
72
73
74
75
76
77
78
79 func (s *IssueLinksService) ListIssueRelations(pid interface{}, issue int, options ...RequestOptionFunc) ([]*IssueRelation, *Response, error) {
80 project, err := parseID(pid)
81 if err != nil {
82 return nil, nil, err
83 }
84 u := fmt.Sprintf("projects/%s/issues/%d/links", PathEscape(project), issue)
85
86 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
87 if err != nil {
88 return nil, nil, err
89 }
90
91 var is []*IssueRelation
92 resp, err := s.client.Do(req, &is)
93 if err != nil {
94 return nil, resp, err
95 }
96
97 return is, resp, nil
98 }
99
100
101
102
103
104 func (s *IssueLinksService) GetIssueLink(pid interface{}, issue, issueLink int, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
105 project, err := parseID(pid)
106 if err != nil {
107 return nil, nil, err
108 }
109 u := fmt.Sprintf("projects/%s/issues/%d/links/%d", PathEscape(project), issue, issueLink)
110
111 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
112 if err != nil {
113 return nil, nil, err
114 }
115
116 il := new(IssueLink)
117 resp, err := s.client.Do(req, il)
118 if err != nil {
119 return nil, resp, err
120 }
121
122 return il, resp, nil
123 }
124
125
126
127
128 type CreateIssueLinkOptions struct {
129 TargetProjectID *string `json:"target_project_id"`
130 TargetIssueIID *string `json:"target_issue_iid"`
131 LinkType *string `json:"link_type"`
132 }
133
134
135
136
137
138
139 func (s *IssueLinksService) CreateIssueLink(pid interface{}, issue int, opt *CreateIssueLinkOptions, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
140 project, err := parseID(pid)
141 if err != nil {
142 return nil, nil, err
143 }
144 u := fmt.Sprintf("projects/%s/issues/%d/links", PathEscape(project), issue)
145
146 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
147 if err != nil {
148 return nil, nil, err
149 }
150
151 i := new(IssueLink)
152 resp, err := s.client.Do(req, &i)
153 if err != nil {
154 return nil, resp, err
155 }
156
157 return i, resp, nil
158 }
159
160
161
162
163
164 func (s *IssueLinksService) DeleteIssueLink(pid interface{}, issue, issueLink int, options ...RequestOptionFunc) (*IssueLink, *Response, error) {
165 project, err := parseID(pid)
166 if err != nil {
167 return nil, nil, err
168 }
169 u := fmt.Sprintf("projects/%s/issues/%d/links/%d",
170 PathEscape(project),
171 issue,
172 issueLink)
173
174 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
175 if err != nil {
176 return nil, nil, err
177 }
178
179 il := new(IssueLink)
180 resp, err := s.client.Do(req, &il)
181 if err != nil {
182 return nil, resp, err
183 }
184
185 return il, resp, nil
186 }
187
View as plain text