Skip to content

Commit 4948a7b

Browse files
author
Antoine Huret
committed
add a new method that allow to get an issue by id instead of iid
1 parent 85caccc commit 4948a7b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

issues.go

+20
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,26 @@ func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssue
387387
return i, resp, err
388388
}
389389

390+
// GetIssueByID gets a single issue.
391+
//
392+
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#single-issue
393+
func (s *IssuesService) GetIssueByID(issue int, options ...RequestOptionFunc) (*Issue, *Response, error) {
394+
u := fmt.Sprintf("issues/%d", issue)
395+
396+
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
397+
if err != nil {
398+
return nil, nil, err
399+
}
400+
401+
i := new(Issue)
402+
resp, err := s.client.Do(req, i)
403+
if err != nil {
404+
return nil, resp, err
405+
}
406+
407+
return i, resp, err
408+
}
409+
390410
// GetIssue gets a single project issue.
391411
//
392412
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#single-project-issue

issues_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@ func TestGetIssue(t *testing.T) {
5252
}
5353
}
5454

55+
func TestGetIssueByID(t *testing.T) {
56+
mux, client := setup(t)
57+
58+
mux.HandleFunc("/api/v4/issues/5", func(w http.ResponseWriter, r *http.Request) {
59+
testMethod(t, r, http.MethodGet)
60+
fmt.Fprint(w, `{"id":5, "description": "This is test project", "author" : {"id" : 1, "name": "snehal"}, "assignees":[{"id":1}],"merge_requests_count": 1}`)
61+
})
62+
63+
issue, _, err := client.Issues.GetIssueByID(5)
64+
if err != nil {
65+
log.Fatal(err)
66+
}
67+
68+
want := &Issue{
69+
ID: 5,
70+
Description: "This is test project",
71+
Author: &IssueAuthor{ID: 1, Name: "snehal"},
72+
Assignees: []*IssueAssignee{{ID: 1}},
73+
MergeRequestCount: 1,
74+
}
75+
76+
if !reflect.DeepEqual(want, issue) {
77+
t.Errorf("Issues.GetIssueByID returned %+v, want %+v", issue, want)
78+
}
79+
}
80+
5581
func TestDeleteIssue(t *testing.T) {
5682
mux, client := setup(t)
5783

0 commit comments

Comments
 (0)