Repository: xanzy/go-gitlab
Pull request #1532 (2022-08-23 09:37:11)

Add reviewer to merge request to webhook event
Gitlab support  [Add reviewer to merge request to webhook api](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/93663) in 15.3 release.

MR webhook_event:
```yaml
  "changes": {
    "reviewers": {
      "previous": [

      ],
      "current": [
        {
          "id": 1,
          "name": "User1",
          "username": "user1",
          "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
          "email": "[REDACTED]"
        }
      ]
    }
  },
```


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index a0162e0..f3900dc 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -537,6 +537,10 @@ type MergeEvent struct {
 			Previous []*EventUser `json:"previous"`
 			Current  []*EventUser `json:"current"`
 		} `json:"assignees"`
+		Reviewers struct {
+			Previous []*EventUser `json:"previous"`
+			Current  []*EventUser `json:"current"`
+		} `json:"reviewers"`
 		Description struct {
 			Previous string `json:"previous"`
 			Current  string `json:"current"`
diff --git a/groups.go b/groups.go
index 96a1e3a..feeac74 100644
--- a/groups.go
+++ b/groups.go
@@ -105,8 +105,8 @@ type LDAPGroupLink struct {
 //
 // GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#saml-group-links
 type SAMLGroupLink struct {
-	Name        string           `json:"name"`
-	AccessLevel AccessLevelValue `json:"access_level"`
+	Name        string `json:"name"`
+	AccessLevel string `json:"access_level"`
 }
 
 // ListGroupsOptions represents the available ListGroups() options.
@@ -810,8 +810,8 @@ func (s *GroupsService) GetGroupSAMLLink(gid interface{}, samlGroupName string,
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/groups.html#add-saml-group-link
 type AddGroupSAMLLinkOptions struct {
-	SAMLGroupName *string           `url:"saml_group_name,omitempty" json:"saml_group_name,omitempty"`
-	AccessLevel   *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
+	SAMLGroupName *string `url:"saml_group_name,omitempty" json:"saml_group_name,omitempty"`
+	AccessLevel   *string `url:"access_level,omitempty" json:"access_level,omitempty"`
 }
 
 // AddGroupSAMLLink creates a new group SAML link. Available only for users who


Test patch:
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 5ac45d0..a61a0f9 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -234,6 +234,18 @@ func TestMergeEventUnmarshal(t *testing.T) {
 	if event.Assignees[0].Email != expectedEmail {
 		t.Errorf("Assignees[0].Email is %v, want %v", event.Assignees[0].Email, expectedEmail)
 	}
+
+	if len(event.Changes.Reviewers.Previous) != 0 {
+		t.Errorf("Changes.Reviewer.Previeous length is %d, want %d", len(event.Changes.Reviewers.Previous), 0)
+	}
+
+	if len(event.Changes.Reviewers.Current) != 1 {
+		t.Errorf("Changes.Reviewer.Current length is %d, want %d", len(event.Changes.Reviewers.Current), 1)
+	}
+
+	if event.Changes.Reviewers.Current[0].Username != expectedUsername {
+		t.Errorf("Changes.Reviewer.Current[0].Username is %v, want %v", event.Changes.Reviewers.Current[0].Username, expectedUsername)
+	}
 }
 
 func TestMergeEventUnmarshalFromGroup(t *testing.T) {
diff --git a/groups_test.go b/groups_test.go
index 0ab7b6b..41edb45 100644
--- a/groups_test.go
+++ b/groups_test.go
@@ -373,11 +373,11 @@ func TestListGroupSAMLLinks(t *testing.T) {
 			testMethod(t, r, http.MethodGet)
 			fmt.Fprint(w, `[
 	{
-		"access_level":30,
+		"access_level":"Developer",
 		"name":"gitlab_group_example_developer"
 	},
 	{
-		"access_level":40,
+		"access_level":"Maintainer",
 		"name":"gitlab_group_example_maintainer"
 	}
 ]`)
@@ -390,11 +390,11 @@ func TestListGroupSAMLLinks(t *testing.T) {
 
 	want := []*SAMLGroupLink{
 		{
-			AccessLevel: DeveloperPermissions,
+			AccessLevel: "Developer",
 			Name:        "gitlab_group_example_developer",
 		},
 		{
-			AccessLevel: MaintainerPermissions,
+			AccessLevel: "Maintainer",
 			Name:        "gitlab_group_example_maintainer",
 		},
 	}
@@ -412,7 +412,7 @@ func TestGetGroupSAMLLink(t *testing.T) {
 			testMethod(t, r, http.MethodGet)
 			fmt.Fprint(w, `
 {
-	"access_level":30,
+	"access_level":"Developer",
 	"name":"gitlab_group_example_developer"
 }`)
 		})
@@ -423,7 +423,7 @@ func TestGetGroupSAMLLink(t *testing.T) {
 	}
 
 	want := &SAMLGroupLink{
-		AccessLevel: DeveloperPermissions,
+		AccessLevel: "Developer",
 		Name:        "gitlab_group_example_developer",
 	}
 	if !reflect.DeepEqual(want, links) {
@@ -440,14 +440,14 @@ func TestAddGroupSAMLLink(t *testing.T) {
 			testMethod(t, r, http.MethodPost)
 			fmt.Fprint(w, `
 {
-	"access_level":30,
+	"access_level":"Developer",
 	"name":"gitlab_group_example_developer"
 }`)
 		})
 
 	opt := &AddGroupSAMLLinkOptions{
 		SAMLGroupName: String("gitlab_group_example_developer"),
-		AccessLevel:   AccessLevel(DeveloperPermissions),
+		AccessLevel:   String("Developer"),
 	}
 
 	link, _, err := client.Groups.AddGroupSAMLLink(1, opt)
@@ -456,7 +456,7 @@ func TestAddGroupSAMLLink(t *testing.T) {
 	}
 
 	want := &SAMLGroupLink{
-		AccessLevel: DeveloperPermissions,
+		AccessLevel: "Developer",
 		Name:        "gitlab_group_example_developer",
 	}
 	if !reflect.DeepEqual(want, link) {
diff --git a/testdata/webhooks/merge_request.json b/testdata/webhooks/merge_request.json
index c52d560..721dd89 100644
--- a/testdata/webhooks/merge_request.json
+++ b/testdata/webhooks/merge_request.json
@@ -159,6 +159,18 @@
         "type": "ProjectLabel",
         "group_id": 41
       }]
+    },
+    "reviewers": {
+      "previous": [],
+      "current": [
+        {
+          "id": 1,
+          "name": "User1",
+          "username": "user1",
+          "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40&d=identicon",
+          "email": "[REDACTED]"
+        }
+      ]
     }
   }
 }