Repository: xanzy/go-gitlab
Pull request #1690 (2023-04-10 23:01:26)

Updated Issue event
Added missing fields.


@svanharmelen Looking for review.


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 5044444..d16f810 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -255,6 +255,7 @@ type IssueCommentEvent struct {
 // https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#issue-events
 type IssueEvent struct {
 	ObjectKind string     `json:"object_kind"`
+	EventType  string     `json:"event_type"`
 	User       *EventUser `json:"user"`
 	Project    struct {
 		ID                int             `json:"id"`
@@ -275,21 +276,45 @@ type IssueEvent struct {
 	} `json:"project"`
 	Repository       *Repository `json:"repository"`
 	ObjectAttributes struct {
-		ID          int    `json:"id"`
-		Title       string `json:"title"`
-		AssigneeID  int    `json:"assignee_id"`
-		AuthorID    int    `json:"author_id"`
-		ProjectID   int    `json:"project_id"`
-		CreatedAt   string `json:"created_at"` // Should be *time.Time (see Gitlab issue #21468)
-		UpdatedAt   string `json:"updated_at"` // Should be *time.Time (see Gitlab issue #21468)
-		Position    int    `json:"position"`
-		BranchName  string `json:"branch_name"`
-		Description string `json:"description"`
-		MilestoneID int    `json:"milestone_id"`
-		State       string `json:"state"`
-		IID         int    `json:"iid"`
-		URL         string `json:"url"`
-		Action      string `json:"action"`
+		ID                  int      `json:"id"`
+		Title               string   `json:"title"`
+		AssigneeIDs         []int    `json:"assignee_ids"`
+		AssigneeID          int      `json:"assignee_id"`
+		AuthorID            int      `json:"author_id"`
+		ProjectID           int      `json:"project_id"`
+		CreatedAt           string   `json:"created_at"` // Should be *time.Time (see Gitlab issue #21468)
+		UpdatedAt           string   `json:"updated_at"` // Should be *time.Time (see Gitlab issue #21468)
+		UpdatedByID         int      `json:"updated_by_id"`
+		LastEditedAt        string   `json:"last_edited_at"`
+		LastEditedByID      int      `json:"last_edited_by_id"`
+		RelativePosition    int      `json:"relative_position"`
+		BranchName          string   `json:"branch_name"`
+		Description         string   `json:"description"`
+		MilestoneID         int      `json:"milestone_id"`
+		StateID             StateID  `json:"state_id"`
+		Confidential        bool     `json:"confidential"`
+		DiscussionLocked    bool     `json:"discussion_locked"`
+		DueDate             *ISOTime `json:"due_date"`
+		MovedToID           int      `json:"moved_to_id"`
+		DuplicatedToID      int      `json:"duplicated_to_id"`
+		TimeEstimate        int      `json:"time_estimate"`
+		TotalTimeSpent      int      `json:"total_time_spent"`
+		TimeChange          int      `json:"time_change"`
+		HumanTotalTimeSpent string   `json:"human_total_time_spent"`
+		HumanTimeEstimate   string   `json:"human_time_estimate"`
+		HumanTimeChange     string   `json:"human_time_change"`
+		Weight              string   `json:"weight"`
+		IID                 int      `json:"iid"`
+		URL                 string   `json:"url"`
+		State               string   `json:"state"`
+		Action              string   `json:"action"`
+		Severity            string   `json:"severity"`
+		EscalationStatus    string   `json:"escalation_status"`
+		EscalationPolicy    struct {
+			ID   int    `json:"id"`
+			Name string `json:"name"`
+		} `json:"escalation_policy"`
+		Labels []*EventLabel `json:"labels"`
 	} `json:"object_attributes"`
 	Assignee  *EventUser    `json:"assignee"`
 	Assignees *[]EventUser  `json:"assignees"`


Test patch:
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 421e3c6..d48545d 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -262,18 +262,61 @@ func TestIssueEventUnmarshal(t *testing.T) {
 		t.Errorf("Issue Event can not unmarshaled: %v\n ", err.Error())
 	}
 
+	if event.ObjectKind != string(IssueEventTargetType) {
+		t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, IssueEventTargetType)
+	}
+
+	if event.EventType != "issue" {
+		t.Errorf("EventType is %v, want %v", event.EventType, "issue")
+	}
+
 	if event.Project.ID != 1 {
 		t.Errorf("Project.ID is %v, want %v", event.Project.ID, 1)
 	}
 
-	if event.User.ID != 42 {
-		t.Errorf("User ID is %d, want %d", event.User.ID, 42)
+	if event.User.ID != 1 {
+		t.Errorf("User ID is %d, want %d", event.User.ID, 1)
 	}
 
 	if event.Assignee.Username != "user1" {
 		t.Errorf("Assignee username is %s, want %s", event.Assignee.Username, "user1")
 	}
 
+	if event.ObjectAttributes.ID != 301 {
+		t.Errorf("ObjectAttributes.ID is %v, want %v", event.ObjectAttributes.ID, 301)
+	}
+
+	if event.ObjectAttributes.Title != "New API: create/update/delete file" {
+		t.Errorf("ObjectAttributes.Title is %v, want %v", event.ObjectAttributes.Title, "New API: create/update/delete file")
+	}
+
+	if event.ObjectAttributes.StateID != StateIDOpen {
+		t.Errorf("ObjectAttributes.StateID is %v, want %v", event.ObjectAttributes.StateID, StateIDOpen)
+	}
+
+	if event.ObjectAttributes.State != "opened" {
+		t.Errorf("ObjectAttributes.State is %v, want %v", event.ObjectAttributes.State, "opened")
+	}
+	if event.ObjectAttributes.Confidential != false {
+		t.Errorf("ObjectAttributes.Confidential is %v, want %v", event.ObjectAttributes.Confidential, false)
+	}
+
+	if event.ObjectAttributes.TotalTimeSpent != 0 {
+		t.Errorf("ObjectAttributes.TotalTimeSpent is %v, want %v", event.ObjectAttributes.TotalTimeSpent, 0)
+	}
+
+	if event.ObjectAttributes.Action != "open" {
+		t.Errorf("ObjectAttributes.Action is %v, want %v", event.ObjectAttributes.Action, "open")
+	}
+
+	if event.ObjectAttributes.EscalationStatus != "triggered" {
+		t.Errorf("ObjectAttributes.EscalationStatus is %v, want %v", event.ObjectAttributes.EscalationStatus, "triggered")
+	}
+
+	if event.ObjectAttributes.EscalationPolicy.ID != 18 {
+		t.Errorf("ObjectAttributes.EscalationPolicy.ID is %v, want %v", event.ObjectAttributes.EscalationPolicy.ID, 18)
+	}
+
 	if event.Changes.TotalTimeSpent.Previous != 8100 {
 		t.Errorf("Changes.TotalTimeSpent.Previous is %v , want %v", event.Changes.TotalTimeSpent.Previous, 8100)
 	}
@@ -330,8 +373,8 @@ func TestIssueEventUnmarshal(t *testing.T) {
 	assert.Equal(t, "2017-09-15 16:54:55 UTC", event.Changes.ClosedAt.Previous)
 	assert.Equal(t, "2017-09-15 16:56:00 UTC", event.Changes.ClosedAt.Current)
 
-	assert.Equal(t, StateIDOpen, event.Changes.StateID.Previous)
-	assert.Equal(t, StateIDClosed, event.Changes.StateID.Current)
+	assert.Equal(t, StateIDNone, event.Changes.StateID.Previous)
+	assert.Equal(t, StateIDOpen, event.Changes.StateID.Current)
 
 	assert.Equal(t, "2017-09-15 16:50:55 UTC", event.Changes.UpdatedAt.Previous)
 	assert.Equal(t, "2017-09-15 16:52:00 UTC", event.Changes.UpdatedAt.Current)
diff --git a/testdata/webhooks/issue.json b/testdata/webhooks/issue.json
index 02d8255..2f10e1e 100644
--- a/testdata/webhooks/issue.json
+++ b/testdata/webhooks/issue.json
@@ -1,34 +1,30 @@
 {
   "object_kind": "issue",
+  "event_type": "issue",
   "user": {
-    "id": 42,
-    "name": "User1",
-    "username": "user1",
-    "email": "user1@example.com",
-    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
+    "id": 1,
+    "name": "Administrator",
+    "username": "root",
+    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
+    "email": "admin@example.com"
   },
   "project": {
     "id": 1,
-    "name": "Gitlab Test",
-    "description": "Aut reprehenderit ut est.",
-    "web_url": "http://example.com/gitlabhq/gitlab-test",
-    "avatar_url": null,
-    "git_ssh_url": "git@example.com:gitlabhq/gitlab-test.git",
-    "git_http_url": "http://example.com/gitlabhq/gitlab-test.git",
-    "namespace": "GitlabHQ",
-    "visibility_level": 20,
-    "path_with_namespace": "gitlabhq/gitlab-test",
-    "default_branch": "master",
-    "homepage": "http://example.com/gitlabhq/gitlab-test",
-    "url": "http://example.com/gitlabhq/gitlab-test.git",
-    "ssh_url": "git@example.com:gitlabhq/gitlab-test.git",
-    "http_url": "http://example.com/gitlabhq/gitlab-test.git"
-  },
-  "repository": {
-    "name": "Gitlab Test",
-    "url": "http://example.com/gitlabhq/gitlab-test.git",
-    "description": "Aut reprehenderit ut est.",
-    "homepage": "http://example.com/gitlabhq/gitlab-test"
+    "name":"Gitlab Test",
+    "description":"Aut reprehenderit ut est.",
+    "web_url":"http://example.com/gitlabhq/gitlab-test",
+    "avatar_url":null,
+    "git_ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
+    "git_http_url":"http://example.com/gitlabhq/gitlab-test.git",
+    "namespace":"GitlabHQ",
+    "visibility_level":20,
+    "path_with_namespace":"gitlabhq/gitlab-test",
+    "default_branch":"master",
+    "ci_config_path": null,
+    "homepage":"http://example.com/gitlabhq/gitlab-test",
+    "url":"http://example.com/gitlabhq/gitlab-test.git",
+    "ssh_url":"git@example.com:gitlabhq/gitlab-test.git",
+    "http_url":"http://example.com/gitlabhq/gitlab-test.git"
   },
   "object_attributes": {
     "id": 301,
@@ -39,45 +35,76 @@
     "project_id": 14,
     "created_at": "2013-12-03T17:15:43Z",
     "updated_at": "2013-12-03T17:15:43Z",
-    "position": 0,
-    "branch_name": null,
+    "updated_by_id": 1,
+    "last_edited_at": null,
+    "last_edited_by_id": null,
+    "relative_position": 0,
     "description": "Create new API for manipulations with repository",
     "milestone_id": null,
-    "state": "opened",
+    "state_id": 1,
+    "confidential": false,
+    "discussion_locked": true,
+    "due_date": null,
+    "moved_to_id": null,
+    "duplicated_to_id": null,
+    "time_estimate": 0,
+    "total_time_spent": 0,
+    "time_change": 0,
+    "human_total_time_spent": null,
+    "human_time_estimate": null,
+    "human_time_change": null,
+    "weight": null,
     "iid": 23,
     "url": "http://example.com/diaspora/issues/23",
-    "action": "open"
+    "state": "opened",
+    "action": "open",
+    "severity": "high",
+    "escalation_status": "triggered",
+    "escalation_policy": {
+      "id": 18,
+      "name": "Engineering On-call"
+    },
+    "labels": [{
+        "id": 206,
+        "title": "API",
+        "color": "#ffffff",
+        "project_id": 14,
+        "created_at": "2013-12-03T17:15:43Z",
+        "updated_at": "2013-12-03T17:15:43Z",
+        "template": false,
+        "description": "API related issues",
+        "type": "ProjectLabel",
+        "group_id": 41
+      }]
   },
-  "assignees": [
-    {
-      "id": 3,
-      "name": "User1",
-      "username": "user1",
-      "email": "test.user1@example.com",
-      "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
-    }
-  ],
+  "repository": {
+    "name": "Gitlab Test",
+    "url": "http://example.com/gitlabhq/gitlab-test.git",
+    "description": "Aut reprehenderit ut est.",
+    "homepage": "http://example.com/gitlabhq/gitlab-test"
+  },
+  "assignees": [{
+    "name": "User1",
+    "username": "user1",
+    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
+  }],
   "assignee": {
-    "id": 3,
     "name": "User1",
     "username": "user1",
-    "email": "test.user1@example.com",
     "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
   },
-  "labels": [
-    {
-      "id": 206,
-      "title": "API",
-      "color": "#ffffff",
-      "project_id": 14,
-      "created_at": "2013-12-03T17:15:43Z",
-      "updated_at": "2013-12-03T17:15:43Z",
-      "template": false,
-      "description": "API related issues",
-      "type": "ProjectLabel",
-      "group_id": 41
-    }
-  ],
+  "labels": [{
+    "id": 206,
+    "title": "API",
+    "color": "#ffffff",
+    "project_id": 14,
+    "created_at": "2013-12-03T17:15:43Z",
+    "updated_at": "2013-12-03T17:15:43Z",
+    "template": false,
+    "description": "API related issues",
+    "type": "ProjectLabel",
+    "group_id": 41
+  }],
   "changes": {
     "updated_by_id": {
       "previous": null,
@@ -92,38 +119,34 @@
       "current": "2017-09-15 16:56:00 UTC"
     },
     "state_id": {
-      "previous": 1,
-      "current": 2
+      "previous": 0,
+      "current": 1
     },
     "labels": {
-      "previous": [
-        {
-          "id": 206,
-          "title": "API",
-          "color": "#ffffff",
-          "project_id": 14,
-          "created_at": "2013-12-03T17:15:43Z",
-          "updated_at": "2013-12-03T17:15:43Z",
-          "template": false,
-          "description": "API related issues",
-          "type": "ProjectLabel",
-          "group_id": 41
-        }
-      ],
-      "current": [
-        {
-          "id": 205,
-          "title": "Platform",
-          "color": "#123123",
-          "project_id": 14,
-          "created_at": "2013-12-03T17:15:43Z",
-          "updated_at": "2013-12-03T17:15:43Z",
-          "template": false,
-          "description": "Platform related issues",
-          "type": "ProjectLabel",
-          "group_id": 41
-        }
-      ]
+      "previous": [{
+        "id": 206,
+        "title": "API",
+        "color": "#ffffff",
+        "project_id": 14,
+        "created_at": "2013-12-03T17:15:43Z",
+        "updated_at": "2013-12-03T17:15:43Z",
+        "template": false,
+        "description": "API related issues",
+        "type": "ProjectLabel",
+        "group_id": 41
+      }],
+      "current": [{
+        "id": 205,
+        "title": "Platform",
+        "color": "#123123",
+        "project_id": 14,
+        "created_at": "2013-12-03T17:15:43Z",
+        "updated_at": "2013-12-03T17:15:43Z",
+        "template": false,
+        "description": "Platform related issues",
+        "type": "ProjectLabel",
+        "group_id": 41
+      }]
     },
     "description": {
       "previous": null,