Repository: xanzy/go-gitlab
Pull request #934 (2020-09-07 09:57:04)

Add with merge request status recheck
Add With Merge Status Recheck for support Github 13.0 

> Note: Starting in GitLab 13.0, listing merge requests may not proactively update the merge_status field (which also affects the has_conflicts field), as this can be an expensive operation. If you are interested in the value of these fields from this endpoint, set the with_merge_status_recheck parameter to true in the query.

Ref:
https://docs.gitlab.com/ce/api/merge_requests.html#list-merge-requests


Patch:
diff --git a/issues_statistics.go b/issues_statistics.go
index 990544a..86d126c 100644
--- a/issues_statistics.go
+++ b/issues_statistics.go
@@ -52,7 +52,7 @@ func (n IssuesStatistics) String() string {
 // https://docs.gitlab.com/ee/api/issues_statistics.html#get-issues-statistics
 type GetIssuesStatisticsOptions struct {
 	Labels           Labels     `url:"labels,omitempty" json:"labels,omitempty"`
-	Milestone        *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
+	Milestone        *Milestone `url:"milestone,omitempty" json:"milestone,omitempty"`
 	Scope            *string    `url:"scope,omitempty" json:"scope,omitempty"`
 	AuthorID         *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
 	AuthorUsername   *string    `url:"author_username,omitempty" json:"author_username,omitempty"`
diff --git a/merge_requests.go b/merge_requests.go
index 02e951d..c2cc618 100644
--- a/merge_requests.go
+++ b/merge_requests.go
@@ -133,26 +133,28 @@ func (m MergeRequestDiffVersion) String() string {
 // https://docs.gitlab.com/ce/api/merge_requests.html#list-merge-requests
 type ListMergeRequestsOptions struct {
 	ListOptions
-	State           *string    `url:"state,omitempty" json:"state,omitempty"`
-	OrderBy         *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
-	Sort            *string    `url:"sort,omitempty" json:"sort,omitempty"`
-	Milestone       *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
-	View            *string    `url:"view,omitempty" json:"view,omitempty"`
-	Labels          Labels     `url:"labels,comma,omitempty" json:"labels,omitempty"`
-	NotLabels       Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
-	CreatedAfter    *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
-	CreatedBefore   *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
-	UpdatedAfter    *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
-	UpdatedBefore   *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
-	Scope           *string    `url:"scope,omitempty" json:"scope,omitempty"`
-	AuthorID        *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
-	AssigneeID      *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
-	MyReactionEmoji *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
-	SourceBranch    *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
-	TargetBranch    *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
-	Search          *string    `url:"search,omitempty" json:"search,omitempty"`
-	In              *string    `url:"in,omitempty" json:"in,omitempty"`
-	WIP             *string    `url:"wip,omitempty" json:"wip,omitempty"`
+	State                  *string    `url:"state,omitempty" json:"state,omitempty"`
+	OrderBy                *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
+	Sort                   *string    `url:"sort,omitempty" json:"sort,omitempty"`
+	Milestone              *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
+	View                   *string    `url:"view,omitempty" json:"view,omitempty"`
+	Labels                 Labels     `url:"labels,comma,omitempty" json:"labels,omitempty"`
+	NotLabels              Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
+	WithLabelsDetails      *bool      `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
+	WithMergeStatusRecheck *bool      `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
+	CreatedAfter           *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
+	CreatedBefore          *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
+	UpdatedAfter           *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
+	UpdatedBefore          *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
+	Scope                  *string    `url:"scope,omitempty" json:"scope,omitempty"`
+	AuthorID               *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
+	AssigneeID             *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
+	MyReactionEmoji        *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
+	SourceBranch           *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
+	TargetBranch           *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
+	Search                 *string    `url:"search,omitempty" json:"search,omitempty"`
+	In                     *string    `url:"in,omitempty" json:"in,omitempty"`
+	WIP                    *string    `url:"wip,omitempty" json:"wip,omitempty"`
 }
 
 // ListMergeRequests gets all merge requests. The state parameter can be used
@@ -184,24 +186,26 @@ func (s *MergeRequestsService) ListMergeRequests(opt *ListMergeRequestsOptions,
 // https://docs.gitlab.com/ce/api/merge_requests.html#list-group-merge-requests
 type ListGroupMergeRequestsOptions struct {
 	ListOptions
-	State           *string    `url:"state,omitempty" json:"state,omitempty"`
-	OrderBy         *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
-	Sort            *string    `url:"sort,omitempty" json:"sort,omitempty"`
-	Milestone       *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
-	View            *string    `url:"view,omitempty" json:"view,omitempty"`
-	Labels          Labels     `url:"labels,omitempty" json:"labels,omitempty"`
-	NotLabels       Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
-	CreatedAfter    *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
-	CreatedBefore   *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
-	UpdatedAfter    *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
-	UpdatedBefore   *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
-	Scope           *string    `url:"scope,omitempty" json:"scope,omitempty"`
-	AuthorID        *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
-	AssigneeID      *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
-	MyReactionEmoji *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
-	SourceBranch    *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
-	TargetBranch    *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
-	Search          *string    `url:"search,omitempty" json:"search,omitempty"`
+	State                  *string    `url:"state,omitempty" json:"state,omitempty"`
+	OrderBy                *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
+	Sort                   *string    `url:"sort,omitempty" json:"sort,omitempty"`
+	Milestone              *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
+	View                   *string    `url:"view,omitempty" json:"view,omitempty"`
+	Labels                 Labels     `url:"labels,omitempty" json:"labels,omitempty"`
+	NotLabels              Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
+	WithLabelsDetails      *bool      `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
+	WithMergeStatusRecheck *bool      `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
+	CreatedAfter           *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
+	CreatedBefore          *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
+	UpdatedAfter           *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
+	UpdatedBefore          *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
+	Scope                  *string    `url:"scope,omitempty" json:"scope,omitempty"`
+	AuthorID               *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
+	AssigneeID             *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
+	MyReactionEmoji        *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
+	SourceBranch           *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
+	TargetBranch           *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
+	Search                 *string    `url:"search,omitempty" json:"search,omitempty"`
 }
 
 // ListGroupMergeRequests gets all merge requests for this group.
@@ -236,26 +240,28 @@ func (s *MergeRequestsService) ListGroupMergeRequests(gid interface{}, opt *List
 // https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
 type ListProjectMergeRequestsOptions struct {
 	ListOptions
-	IIDs            []int      `url:"iids[],omitempty" json:"iids,omitempty"`
-	State           *string    `url:"state,omitempty" json:"state,omitempty"`
-	OrderBy         *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
-	Sort            *string    `url:"sort,omitempty" json:"sort,omitempty"`
-	Milestone       *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
-	View            *string    `url:"view,omitempty" json:"view,omitempty"`
-	Labels          Labels     `url:"labels,comma,omitempty" json:"labels,omitempty"`
-	NotLabels       Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
-	CreatedAfter    *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
-	CreatedBefore   *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
-	UpdatedAfter    *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
-	UpdatedBefore   *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
-	Scope           *string    `url:"scope,omitempty" json:"scope,omitempty"`
-	AuthorID        *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
-	AssigneeID      *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
-	MyReactionEmoji *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
-	SourceBranch    *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
-	TargetBranch    *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
-	Search          *string    `url:"search,omitempty" json:"search,omitempty"`
-	WIP             *string    `url:"wip,omitempty" json:"wip,omitempty"`
+	IIDs                   []int      `url:"iids[],omitempty" json:"iids,omitempty"`
+	State                  *string    `url:"state,omitempty" json:"state,omitempty"`
+	OrderBy                *string    `url:"order_by,omitempty" json:"order_by,omitempty"`
+	Sort                   *string    `url:"sort,omitempty" json:"sort,omitempty"`
+	Milestone              *string    `url:"milestone,omitempty" json:"milestone,omitempty"`
+	View                   *string    `url:"view,omitempty" json:"view,omitempty"`
+	Labels                 Labels     `url:"labels,comma,omitempty" json:"labels,omitempty"`
+	NotLabels              Labels     `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
+	WithLabelsDetails      *bool      `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
+	WithMergeStatusRecheck *bool      `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
+	CreatedAfter           *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
+	CreatedBefore          *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
+	UpdatedAfter           *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
+	UpdatedBefore          *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
+	Scope                  *string    `url:"scope,omitempty" json:"scope,omitempty"`
+	AuthorID               *int       `url:"author_id,omitempty" json:"author_id,omitempty"`
+	AssigneeID             *int       `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
+	MyReactionEmoji        *string    `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
+	SourceBranch           *string    `url:"source_branch,omitempty" json:"source_branch,omitempty"`
+	TargetBranch           *string    `url:"target_branch,omitempty" json:"target_branch,omitempty"`
+	Search                 *string    `url:"search,omitempty" json:"search,omitempty"`
+	WIP                    *string    `url:"wip,omitempty" json:"wip,omitempty"`
 }
 
 // ListProjectMergeRequests gets all merge requests for this project.
diff --git a/registry.go b/registry.go
index 8694cf9..57f4575 100644
--- a/registry.go
+++ b/registry.go
@@ -190,13 +190,9 @@ func (s *ContainerRegistryService) DeleteRegistryRepositoryTag(pid interface{},
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/container_registry.html#delete-repository-tags-in-bulk
 type DeleteRegistryRepositoryTagsOptions struct {
-	NameRegexpDelete *string `url:"name_regex_delete,omitempty" json:"name_regex_delete,omitempty"`
-	NameRegexpKeep   *string `url:"name_regex_keep,omitempty" json:"name_regex_keep,omitempty"`
-	KeepN            *int    `url:"keep_n,omitempty" json:"keep_n,omitempty"`
-	OlderThan        *string `url:"older_than,omitempty" json:"older_than,omitempty"`
-
-	// Deprecated members
 	NameRegexp *string `url:"name_regex,omitempty" json:"name_regex,omitempty"`
+	KeepN      *int    `url:"keep_n,omitempty" json:"keep_n,omitempty"`
+	OlderThan  *string `url:"older_than,omitempty" json:"older_than,omitempty"`
 }
 
 // DeleteRegistryRepositoryTags deletes repository tags in bulk based on


Test patch:
diff --git a/gitlab_test.go b/gitlab_test.go
index ee96093..db4e4c0 100644
--- a/gitlab_test.go
+++ b/gitlab_test.go
@@ -66,6 +66,12 @@ func testBody(t *testing.T, r *http.Request, want string) {
 	}
 }
 
+func testParams(t *testing.T, r *http.Request, want string) {
+	if got := r.URL.RawQuery; got != want {
+		t.Errorf("Request query: %s, want %s", got, want)
+	}
+}
+
 func mustWriteHTTPResponse(t *testing.T, w io.Writer, fixturePath string) {
 	f, err := os.Open(fixturePath)
 	if err != nil {
diff --git a/merge_requests_test.go b/merge_requests_test.go
index 75e0ad0..2ac418a 100644
--- a/merge_requests_test.go
+++ b/merge_requests_test.go
@@ -134,9 +134,14 @@ func TestListProjectMergeRequests(t *testing.T) {
 
 	mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
+		testParams(t, r, "with_labels_details=true&with_merge_status_recheck=true")
 		mustWriteHTTPResponse(t, w, "testdata/get_merge_requests.json")
 	})
-	opts := ListProjectMergeRequestsOptions{}
+
+	opts := ListProjectMergeRequestsOptions{
+		WithLabelsDetails:      Bool(true),
+		WithMergeStatusRecheck: Bool(true),
+	}
 
 	mergeRequests, _, err := client.MergeRequests.ListProjectMergeRequests(278964, &opts)