Repository: xanzy/go-gitlab
Pull request #1302 (2021-12-02 13:10:36)

Add References to MergeRequest.
Adds references as defined in the API:

```
    "references": {
      "short": "!1",
      "relative": "my-group/my-project!1",
      "full": "my-group/my-project!1"
    },
```

https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr



svanharmelen: @finn-ball guess you need to fixup the tests first...

Patch:
diff --git a/merge_requests.go b/merge_requests.go
index 0879ca8..1cfb3c7 100644
--- a/merge_requests.go
+++ b/merge_requests.go
@@ -35,45 +35,46 @@ type MergeRequestsService struct {
 //
 // GitLab API docs: https://docs.gitlab.com/ce/api/merge_requests.html
 type MergeRequest struct {
-	ID                        int          `json:"id"`
-	IID                       int          `json:"iid"`
-	TargetBranch              string       `json:"target_branch"`
-	SourceBranch              string       `json:"source_branch"`
-	ProjectID                 int          `json:"project_id"`
-	Title                     string       `json:"title"`
-	State                     string       `json:"state"`
-	CreatedAt                 *time.Time   `json:"created_at"`
-	UpdatedAt                 *time.Time   `json:"updated_at"`
-	Upvotes                   int          `json:"upvotes"`
-	Downvotes                 int          `json:"downvotes"`
-	Author                    *BasicUser   `json:"author"`
-	Assignee                  *BasicUser   `json:"assignee"`
-	Assignees                 []*BasicUser `json:"assignees"`
-	Reviewers                 []*BasicUser `json:"reviewers"`
-	SourceProjectID           int          `json:"source_project_id"`
-	TargetProjectID           int          `json:"target_project_id"`
-	Labels                    Labels       `json:"labels"`
-	Description               string       `json:"description"`
-	WorkInProgress            bool         `json:"work_in_progress"`
-	Milestone                 *Milestone   `json:"milestone"`
-	MergeWhenPipelineSucceeds bool         `json:"merge_when_pipeline_succeeds"`
-	MergeStatus               string       `json:"merge_status"`
-	MergeError                string       `json:"merge_error"`
-	MergedBy                  *BasicUser   `json:"merged_by"`
-	MergedAt                  *time.Time   `json:"merged_at"`
-	ClosedBy                  *BasicUser   `json:"closed_by"`
-	ClosedAt                  *time.Time   `json:"closed_at"`
-	Subscribed                bool         `json:"subscribed"`
-	SHA                       string       `json:"sha"`
-	MergeCommitSHA            string       `json:"merge_commit_sha"`
-	SquashCommitSHA           string       `json:"squash_commit_sha"`
-	UserNotesCount            int          `json:"user_notes_count"`
-	ChangesCount              string       `json:"changes_count"`
-	ShouldRemoveSourceBranch  bool         `json:"should_remove_source_branch"`
-	ForceRemoveSourceBranch   bool         `json:"force_remove_source_branch"`
-	AllowCollaboration        bool         `json:"allow_collaboration"`
-	WebURL                    string       `json:"web_url"`
-	DiscussionLocked          bool         `json:"discussion_locked"`
+	ID                        int              `json:"id"`
+	IID                       int              `json:"iid"`
+	TargetBranch              string           `json:"target_branch"`
+	SourceBranch              string           `json:"source_branch"`
+	ProjectID                 int              `json:"project_id"`
+	Title                     string           `json:"title"`
+	State                     string           `json:"state"`
+	CreatedAt                 *time.Time       `json:"created_at"`
+	UpdatedAt                 *time.Time       `json:"updated_at"`
+	Upvotes                   int              `json:"upvotes"`
+	Downvotes                 int              `json:"downvotes"`
+	Author                    *BasicUser       `json:"author"`
+	Assignee                  *BasicUser       `json:"assignee"`
+	Assignees                 []*BasicUser     `json:"assignees"`
+	Reviewers                 []*BasicUser     `json:"reviewers"`
+	SourceProjectID           int              `json:"source_project_id"`
+	TargetProjectID           int              `json:"target_project_id"`
+	Labels                    Labels           `json:"labels"`
+	Description               string           `json:"description"`
+	WorkInProgress            bool             `json:"work_in_progress"`
+	Milestone                 *Milestone       `json:"milestone"`
+	MergeWhenPipelineSucceeds bool             `json:"merge_when_pipeline_succeeds"`
+	MergeStatus               string           `json:"merge_status"`
+	MergeError                string           `json:"merge_error"`
+	MergedBy                  *BasicUser       `json:"merged_by"`
+	MergedAt                  *time.Time       `json:"merged_at"`
+	ClosedBy                  *BasicUser       `json:"closed_by"`
+	ClosedAt                  *time.Time       `json:"closed_at"`
+	Subscribed                bool             `json:"subscribed"`
+	SHA                       string           `json:"sha"`
+	MergeCommitSHA            string           `json:"merge_commit_sha"`
+	SquashCommitSHA           string           `json:"squash_commit_sha"`
+	UserNotesCount            int              `json:"user_notes_count"`
+	ChangesCount              string           `json:"changes_count"`
+	ShouldRemoveSourceBranch  bool             `json:"should_remove_source_branch"`
+	ForceRemoveSourceBranch   bool             `json:"force_remove_source_branch"`
+	AllowCollaboration        bool             `json:"allow_collaboration"`
+	WebURL                    string           `json:"web_url"`
+	References                *IssueReferences `json:"references"`
+	DiscussionLocked          bool             `json:"discussion_locked"`
 	Changes                   []struct {
 		OldPath     string `json:"old_path"`
 		NewPath     string `json:"new_path"`


Test patch:
diff --git a/commits_test.go b/commits_test.go
index b3e5b0f..7f022b2 100644
--- a/commits_test.go
+++ b/commits_test.go
@@ -816,13 +816,18 @@ func TestCommitsService_ListMergeRequestsByCommit(t *testing.T) {
 		ForceRemoveSourceBranch:  false,
 		AllowCollaboration:       false,
 		WebURL:                   "http://gitlab.example.com/my-group/my-project/merge_requests/1",
-		DiscussionLocked:         false,
-		Squash:                   false,
-		DivergedCommitsCount:     0,
-		RebaseInProgress:         false,
-		ApprovalsBeforeMerge:     0,
-		Reference:                "",
-		FirstContribution:        false,
+		References: &IssueReferences{
+			Short:    "!1",
+			Relative: "my-group/my-project!1",
+			Full:     "my-group/my-project!1",
+		},
+		DiscussionLocked:     false,
+		Squash:               false,
+		DivergedCommitsCount: 0,
+		RebaseInProgress:     false,
+		ApprovalsBeforeMerge: 0,
+		Reference:            "",
+		FirstContribution:    false,
 		TaskCompletionStatus: &TasksCompletionStatus{
 			Count:          0,
 			CompletedCount: 0,
diff --git a/group_milestones_test.go b/group_milestones_test.go
index 278b5fc..0ed27a9 100644
--- a/group_milestones_test.go
+++ b/group_milestones_test.go
@@ -507,13 +507,18 @@ func TestGroupMilestonesService_GetGroupMilestoneMergeRequests(t *testing.T) {
 		ForceRemoveSourceBranch:  false,
 		AllowCollaboration:       false,
 		WebURL:                   "http://gitlab.example.com/my-group/my-project/merge_requests/1",
-		DiscussionLocked:         false,
-		Squash:                   false,
-		DivergedCommitsCount:     0,
-		RebaseInProgress:         false,
-		ApprovalsBeforeMerge:     0,
-		Reference:                "",
-		FirstContribution:        false,
+		References: &IssueReferences{
+			Short:    "!1",
+			Relative: "my-group/my-project!1",
+			Full:     "my-group/my-project!1",
+		},
+		DiscussionLocked:     false,
+		Squash:               false,
+		DivergedCommitsCount: 0,
+		RebaseInProgress:     false,
+		ApprovalsBeforeMerge: 0,
+		Reference:            "",
+		FirstContribution:    false,
 		TaskCompletionStatus: &TasksCompletionStatus{
 			Count:          0,
 			CompletedCount: 0,
diff --git a/milestones_test.go b/milestones_test.go
index b9e335e..aad59da 100644
--- a/milestones_test.go
+++ b/milestones_test.go
@@ -532,13 +532,18 @@ func TestMilestonesService_GetMilestoneMergeRequests(t *testing.T) {
 		ForceRemoveSourceBranch:  false,
 		AllowCollaboration:       false,
 		WebURL:                   "http://gitlab.example.com/my-group/my-project/merge_requests/1",
-		DiscussionLocked:         false,
-		Squash:                   false,
-		DivergedCommitsCount:     0,
-		RebaseInProgress:         false,
-		ApprovalsBeforeMerge:     0,
-		Reference:                "",
-		FirstContribution:        false,
+		References: &IssueReferences{
+			Short:    "!1",
+			Relative: "my-group/my-project!1",
+			Full:     "my-group/my-project!1",
+		},
+		DiscussionLocked:     false,
+		Squash:               false,
+		DivergedCommitsCount: 0,
+		RebaseInProgress:     false,
+		ApprovalsBeforeMerge: 0,
+		Reference:            "",
+		FirstContribution:    false,
 		TaskCompletionStatus: &TasksCompletionStatus{
 			Count:          0,
 			CompletedCount: 0,