From 8c6844fd71641fc6ea0fd6fa09922a4721e3fbcd Mon Sep 17 00:00:00 2001 From: WinXaito Date: Wed, 5 Jul 2023 13:19:37 +0200 Subject: [PATCH 1/2] Add the field GroupID to the Milestone struct --- group_boards_test.go | 2 ++ issues_test.go | 76 ++++++++++++++++++++++++++++++++++++++++++++ milestones.go | 1 + 3 files changed, 79 insertions(+) diff --git a/group_boards_test.go b/group_boards_test.go index 1a3aeb2c6..0b658dc5a 100644 --- a/group_boards_test.go +++ b/group_boards_test.go @@ -359,6 +359,7 @@ func TestGroupIssueBoardsService_UpdateIssueBoard(t *testing.T) { ID: 44, IID: 1, ProjectID: 0, + GroupID: 5, Title: "Group Milestone", Description: "Group Milestone Desc", State: "active", @@ -580,6 +581,7 @@ func TestGroupIssueBoardsService_CreateGroupIssueBoardList(t *testing.T) { Milestone: &Milestone{ ID: 7, IID: 3, + GroupID: 12, Title: "Milestone with due date", Description: "", State: "active", diff --git a/issues_test.go b/issues_test.go index c7d4cbc8a..c70bc7db4 100644 --- a/issues_test.go +++ b/issues_test.go @@ -857,3 +857,79 @@ func TestGetIssueParticipants(t *testing.T) { t.Errorf("Issues.GetIssueParticipants returned %+v, want %+v", issueParticipants, want) } } + +// See issue #1749 - Issue with a group milestone +func TestGetIssueMilestone(t *testing.T) { + mux, client := setup(t) + + mux.HandleFunc("/api/v4/projects/1/issues/5", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + fmt.Fprint(w, `{"id":1, "description": "This is test project", "author" : {"id" : 1, "name": "snehal"}, "assignees":[{"id":1}],"merge_requests_count": 1, + "milestone": {"due_date": null, "project_id": 1, "state": "closed", "description": "test", "iid": 3, "id": 11, "title": "v3.0"}}`) + }) + + issue, _, err := client.Issues.GetIssue("1", 5) + if err != nil { + log.Fatal(err) + } + + want := &Issue{ + ID: 1, + Description: "This is test project", + Author: &IssueAuthor{ID: 1, Name: "snehal"}, + Assignees: []*IssueAssignee{{ID: 1}}, + MergeRequestCount: 1, + Milestone: &Milestone{ + DueDate: nil, + ProjectID: 1, + GroupID: 0, + State: "closed", + Description: "test", + IID: 3, + ID: 11, + Title: "v3.0", + }, + } + + if !reflect.DeepEqual(want, issue) { + t.Errorf("Issues.GetIssue returned %+v, want %+v", issue, want) + } +} + +// See issue #1749 - Issue with a group milestone +func TestGetIssueGroupMilestone(t *testing.T) { + mux, client := setup(t) + + mux.HandleFunc("/api/v4/projects/1/issues/5", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + fmt.Fprint(w, `{"id":1, "description": "This is test project", "author" : {"id" : 1, "name": "snehal"}, "assignees":[{"id":1}],"merge_requests_count": 1, + "milestone": {"due_date": null, "group_id": 13, "state": "closed", "description": "test", "iid": 3, "id": 11, "title": "v3.0"}}`) + }) + + issue, _, err := client.Issues.GetIssue("1", 5) + if err != nil { + log.Fatal(err) + } + + want := &Issue{ + ID: 1, + Description: "This is test project", + Author: &IssueAuthor{ID: 1, Name: "snehal"}, + Assignees: []*IssueAssignee{{ID: 1}}, + MergeRequestCount: 1, + Milestone: &Milestone{ + DueDate: nil, + ProjectID: 0, + GroupID: 13, + State: "closed", + Description: "test", + IID: 3, + ID: 11, + Title: "v3.0", + }, + } + + if !reflect.DeepEqual(want, issue) { + t.Errorf("Issues.GetIssue returned %+v, want %+v", issue, want) + } +} diff --git a/milestones.go b/milestones.go index 095c9132d..15bef9e92 100644 --- a/milestones.go +++ b/milestones.go @@ -37,6 +37,7 @@ type Milestone struct { ID int `json:"id"` IID int `json:"iid"` ProjectID int `json:"project_id"` + GroupID int `json:"group_id"` // See issue #1749 Title string `json:"title"` Description string `json:"description"` StartDate *ISOTime `json:"start_date"` From 1ef4e9147cc77799687230a13fafa79fa6218b16 Mon Sep 17 00:00:00 2001 From: WinXaito Date: Wed, 5 Jul 2023 14:45:32 +0200 Subject: [PATCH 2/2] Fix according to review --- group_boards_test.go | 1 - issues_test.go | 3 --- milestones.go | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/group_boards_test.go b/group_boards_test.go index 0b658dc5a..27b8a4585 100644 --- a/group_boards_test.go +++ b/group_boards_test.go @@ -358,7 +358,6 @@ func TestGroupIssueBoardsService_UpdateIssueBoard(t *testing.T) { Milestone: &Milestone{ ID: 44, IID: 1, - ProjectID: 0, GroupID: 5, Title: "Group Milestone", Description: "Group Milestone Desc", diff --git a/issues_test.go b/issues_test.go index c70bc7db4..19086384c 100644 --- a/issues_test.go +++ b/issues_test.go @@ -858,7 +858,6 @@ func TestGetIssueParticipants(t *testing.T) { } } -// See issue #1749 - Issue with a group milestone func TestGetIssueMilestone(t *testing.T) { mux, client := setup(t) @@ -882,7 +881,6 @@ func TestGetIssueMilestone(t *testing.T) { Milestone: &Milestone{ DueDate: nil, ProjectID: 1, - GroupID: 0, State: "closed", Description: "test", IID: 3, @@ -919,7 +917,6 @@ func TestGetIssueGroupMilestone(t *testing.T) { MergeRequestCount: 1, Milestone: &Milestone{ DueDate: nil, - ProjectID: 0, GroupID: 13, State: "closed", Description: "test", diff --git a/milestones.go b/milestones.go index 15bef9e92..17c97e031 100644 --- a/milestones.go +++ b/milestones.go @@ -36,8 +36,8 @@ type MilestonesService struct { type Milestone struct { ID int `json:"id"` IID int `json:"iid"` + GroupID int `json:"group_id"` ProjectID int `json:"project_id"` - GroupID int `json:"group_id"` // See issue #1749 Title string `json:"title"` Description string `json:"description"` StartDate *ISOTime `json:"start_date"`