Skip to content

Commit 498b5f5

Browse files
authored
Merge pull request xanzy#1505 from lizalc/iterations
feat(issues): iteration field, search by iteration
2 parents 4a79f74 + 702e1be commit 498b5f5

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

issues.go

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type Issue struct {
120120
MergeRequestCount int `json:"merge_requests_count"`
121121
EpicIssueID int `json:"epic_issue_id"`
122122
Epic *Epic `json:"epic"`
123+
Iteration *GroupIteration `json:"iteration"`
123124
TaskCompletionStatus *TasksCompletionStatus `json:"task_completion_status"`
124125
}
125126

@@ -232,6 +233,7 @@ type ListIssuesOptions struct {
232233
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
233234
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
234235
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
236+
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
235237
}
236238

237239
// ListIssues gets all issues created by authenticated user. This function
@@ -284,6 +286,7 @@ type ListGroupIssuesOptions struct {
284286
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
285287
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
286288
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
289+
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
287290
}
288291

289292
// ListGroupIssues gets a list of group issues. This function accepts
@@ -343,6 +346,7 @@ type ListProjectIssuesOptions struct {
343346
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
344347
Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
345348
IssueType *string `url:"issue_type,omitempty" json:"issue_type,omitempty"`
349+
IterationID *int `url:"iteration_id,omitempty" json:"iteration_id,omitempty"`
346350
}
347351

348352
// ListProjectIssues gets a list of project issues. This function accepts

issues_test.go

+166
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,62 @@ func TestListIssuesSearchInDescription(t *testing.T) {
324324
t.Errorf("Issues.ListIssues returned %+v, want %+v", issues, want)
325325
}
326326
}
327+
328+
func TestListIssuesSearchByIterationID(t *testing.T) {
329+
mux, server, client := setup(t)
330+
defer teardown(server)
331+
332+
mux.HandleFunc("/api/v4/issues", func(w http.ResponseWriter, r *http.Request) {
333+
testMethod(t, r, http.MethodGet)
334+
testURL(t, r, "/api/v4/issues?iteration_id=90")
335+
fmt.Fprint(w, `
336+
[
337+
{
338+
"id": 1,
339+
"title": "A Test Issue Title",
340+
"description": "This is the description for the issue",
341+
"iteration": {
342+
"id":90,
343+
"iid":4,
344+
"sequence":2,
345+
"group_id":162,
346+
"state":2,
347+
"web_url":"https://gitlab.com/groups/my-group/-/iterations/90"
348+
}
349+
}
350+
]`,
351+
)
352+
})
353+
354+
listProjectIssue := &ListIssuesOptions{
355+
IterationID: Int(90),
356+
}
357+
358+
issues, _, err := client.Issues.ListIssues(listProjectIssue)
359+
360+
if err != nil {
361+
log.Fatal(err)
362+
}
363+
364+
want := []*Issue{{
365+
ID: 1,
366+
Title: "A Test Issue Title",
367+
Description: "This is the description for the issue",
368+
Iteration: &GroupIteration{
369+
ID: 90,
370+
IID: 4,
371+
Sequence: 2,
372+
GroupID: 162,
373+
State: 2,
374+
WebURL: "https://gitlab.com/groups/my-group/-/iterations/90",
375+
},
376+
}}
377+
378+
if !reflect.DeepEqual(want, issues) {
379+
t.Errorf("Issues.ListIssues returned %+v, want %+v", issues, want)
380+
}
381+
}
382+
327383
func TestListProjectIssues(t *testing.T) {
328384
mux, server, client := setup(t)
329385
defer teardown(server)
@@ -355,6 +411,61 @@ func TestListProjectIssues(t *testing.T) {
355411
}
356412
}
357413

414+
func TestListProjectIssuesSearchByIterationID(t *testing.T) {
415+
mux, server, client := setup(t)
416+
defer teardown(server)
417+
418+
mux.HandleFunc("/api/v4/projects/1/issues", func(w http.ResponseWriter, r *http.Request) {
419+
testMethod(t, r, http.MethodGet)
420+
testURL(t, r, "/api/v4/projects/1/issues?iteration_id=90")
421+
fmt.Fprint(w, `
422+
[
423+
{
424+
"id": 1,
425+
"title": "A Test Issue Title",
426+
"description": "This is the description for the issue",
427+
"iteration": {
428+
"id":90,
429+
"iid":4,
430+
"sequence":2,
431+
"group_id":162,
432+
"state":2,
433+
"web_url":"https://gitlab.com/groups/my-group/-/iterations/90"
434+
}
435+
}
436+
]`,
437+
)
438+
})
439+
440+
listProjectIssue := &ListProjectIssuesOptions{
441+
IterationID: Int(90),
442+
}
443+
444+
issues, _, err := client.Issues.ListProjectIssues(1 ,listProjectIssue)
445+
446+
if err != nil {
447+
log.Fatal(err)
448+
}
449+
450+
want := []*Issue{{
451+
ID: 1,
452+
Title: "A Test Issue Title",
453+
Description: "This is the description for the issue",
454+
Iteration: &GroupIteration{
455+
ID: 90,
456+
IID: 4,
457+
Sequence: 2,
458+
GroupID: 162,
459+
State: 2,
460+
WebURL: "https://gitlab.com/groups/my-group/-/iterations/90",
461+
},
462+
}}
463+
464+
if !reflect.DeepEqual(want, issues) {
465+
t.Errorf("Issues.ListIssues returned %+v, want %+v", issues, want)
466+
}
467+
}
468+
358469
func TestListGroupIssues(t *testing.T) {
359470
mux, server, client := setup(t)
360471
defer teardown(server)
@@ -388,6 +499,61 @@ func TestListGroupIssues(t *testing.T) {
388499
}
389500
}
390501

502+
func TestListGroupIssuesSearchByIterationID(t *testing.T) {
503+
mux, server, client := setup(t)
504+
defer teardown(server)
505+
506+
mux.HandleFunc("/api/v4/groups/1/issues", func(w http.ResponseWriter, r *http.Request) {
507+
testMethod(t, r, http.MethodGet)
508+
testURL(t, r, "/api/v4/groups/1/issues?iteration_id=90")
509+
fmt.Fprint(w, `
510+
[
511+
{
512+
"id": 1,
513+
"title": "A Test Issue Title",
514+
"description": "This is the description for the issue",
515+
"iteration": {
516+
"id":90,
517+
"iid":4,
518+
"sequence":2,
519+
"group_id":162,
520+
"state":2,
521+
"web_url":"https://gitlab.com/groups/my-group/-/iterations/90"
522+
}
523+
}
524+
]`,
525+
)
526+
})
527+
528+
listProjectIssue := &ListGroupIssuesOptions{
529+
IterationID: Int(90),
530+
}
531+
532+
issues, _, err := client.Issues.ListGroupIssues(1, listProjectIssue)
533+
534+
if err != nil {
535+
log.Fatal(err)
536+
}
537+
538+
want := []*Issue{{
539+
ID: 1,
540+
Title: "A Test Issue Title",
541+
Description: "This is the description for the issue",
542+
Iteration: &GroupIteration{
543+
ID: 90,
544+
IID: 4,
545+
Sequence: 2,
546+
GroupID: 162,
547+
State: 2,
548+
WebURL: "https://gitlab.com/groups/my-group/-/iterations/90",
549+
},
550+
}}
551+
552+
if !reflect.DeepEqual(want, issues) {
553+
t.Errorf("Issues.ListIssues returned %+v, want %+v", issues, want)
554+
}
555+
}
556+
391557
func TestCreateIssue(t *testing.T) {
392558
mux, server, client := setup(t)
393559
defer teardown(server)

0 commit comments

Comments
 (0)