Repository: xanzy/go-gitlab
Pull request #1112 (2021-03-25 19:20:04)

Add Labels to Issue Comment Events
Add labels field to IssueCommentEvent
  Add label checks to IssueCommentEvent tests
Fix typo in IssueEvent unmarshal test

re #973 


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 03486b9..f59b831 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -213,6 +213,7 @@ type IssueCommentEvent struct {
 		Description         string   `json:"description"`
 		State               string   `json:"state"`
 		Title               string   `json:"title"`
+		Labels              []Label  `json:"labels"`
 		LastEditedAt        string   `json:"last_edit_at"`
 		LastEditedByID      int      `json:"last_edited_by_id"`
 		UpdatedAt           string   `json:"updated_at"`
diff --git a/groups.go b/groups.go
index 89e49cc..8632357 100644
--- a/groups.go
+++ b/groups.go
@@ -458,10 +458,10 @@ func (s *GroupsService) ListGroupLDAPLinks(gid interface{}, options ...RequestOp
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/groups.html#add-ldap-group-link-starter
 type AddGroupLDAPLinkOptions struct {
-	CN          *string `url:"cn,omitempty" json:"cn,omitempty"`
-	Filter      *string `url:"filter,omitempty" json:"filter,omitempty"`
-	GroupAccess *AccessLevelValue    `url:"group_access,omitempty" json:"group_access,omitempty"`
-	Provider    *string `url:"provider,omitempty" json:"provider,omitempty"`
+	CN          *string           `url:"cn,omitempty" json:"cn,omitempty"`
+	Filter      *string           `url:"filter,omitempty" json:"filter,omitempty"`
+	GroupAccess *AccessLevelValue `url:"group_access,omitempty" json:"group_access,omitempty"`
+	Provider    *string           `url:"provider,omitempty" json:"provider,omitempty"`
 }
 
 // DeleteGroupLDAPLinkWithCNOrFilterOptions represents the available DeleteGroupLDAPLinkWithCNOrFilter() options.
diff --git a/validate.go b/validate.go
index b9cee79..2ca7227 100644
--- a/validate.go
+++ b/validate.go
@@ -33,8 +33,8 @@ type ValidateService struct {
 //
 // GitLab API docs: https://docs.gitlab.com/ce/api/lint.html
 type LintResult struct {
-	Status 	 string   `json:"status"`
-	Errors 	 []string `json:"errors"`
+	Status   string   `json:"status"`
+	Errors   []string `json:"errors"`
 	Warnings []string `json:"warnings"`
 }
 


Test patch:
diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go
index ffadbd7..5721004 100644
--- a/event_parsing_webhook_test.go
+++ b/event_parsing_webhook_test.go
@@ -133,9 +133,10 @@ func TestParseIssueCommentHook(t *testing.T) {
 		t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Issue")
 	}
 
-	if event.Issue.Title != "test" {
-		t.Errorf("Issue title is %v, want %v", event.Issue.Title, "test")
+	if event.Issue.Title != "test_issue" {
+		t.Errorf("Issue title is %v, want %v", event.Issue.Title, "test_issue")
 	}
+	assert.Equal(t, 2, len(event.Issue.Labels))
 }
 
 func TestParseIssueHook(t *testing.T) {
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 244c315..3cfd52c 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -67,6 +67,37 @@ func TestDeploymentEventUnmarshal(t *testing.T) {
 	}
 }
 
+func TestIssueCommentEventUnmarshal(t *testing.T) {
+	jsonObject := loadFixture("testdata/webhooks/note_issue.json")
+
+	var event *IssueCommentEvent
+	err := json.Unmarshal(jsonObject, &event)
+
+	if err != nil {
+		t.Errorf("Issue Comment Event can not unmarshaled: %v\n ", err.Error())
+	}
+
+	if event.ObjectKind != string(NoteEventTargetType) {
+		t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, NoteEventTargetType)
+	}
+
+	if event.ProjectID != 5 {
+		t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5)
+	}
+
+	if event.ObjectAttributes.NoteableType != "Issue" {
+		t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Issue")
+	}
+
+	if event.Issue.Title != "test_issue" {
+		t.Errorf("Issue title is %v, want %v", event.Issue.Title, "test_issue")
+	}
+
+	if len(event.Issue.Labels) == 0 || event.Issue.Labels[0].ID != 25 {
+		t.Errorf("Label id is null")
+	}
+}
+
 func TestIssueEventUnmarshal(t *testing.T) {
 	jsonObject := loadFixture("testdata/webhooks/issue.json")
 
@@ -74,7 +105,7 @@ func TestIssueEventUnmarshal(t *testing.T) {
 	err := json.Unmarshal(jsonObject, &event)
 
 	if err != nil {
-		t.Errorf("Deployment Event can not unmarshaled: %v\n ", err.Error())
+		t.Errorf("Issue Event can not unmarshaled: %v\n ", err.Error())
 	}
 	if event.Project.ID != 1 {
 		t.Errorf("Project.ID is %v, want %v", event.Project.ID, 1)
diff --git a/testdata/webhooks/note_issue.json b/testdata/webhooks/note_issue.json
index 12e2520..3f91945 100644
--- a/testdata/webhooks/note_issue.json
+++ b/testdata/webhooks/note_issue.json
@@ -47,7 +47,7 @@
   },
   "issue": {
     "id": 92,
-    "title": "test",
+    "title": "test_issue",
     "assignee_ids": [],
     "assignee_id": null,
     "author_id": 1,
@@ -56,7 +56,7 @@
     "updated_at": "2016-01-04T15:31:46.176Z",
     "position": 0,
     "branch_name": null,
-    "description": "test",
+    "description": "test issue",
     "milestone_id": null,
     "state": "closed",
     "iid": 17,