Repository: xanzy/go-gitlab
Pull request #1700 (2023-04-12 23:25:35)

Added missing fields in snippet-comment, tag and wiki events


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 5044444..479d890 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -921,6 +921,7 @@ type ReleaseEvent struct {
 // https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#comment-on-a-code-snippet
 type SnippetCommentEvent struct {
 	ObjectKind string     `json:"object_kind"`
+	EventType  string     `json:"event_type"`
 	User       *EventUser `json:"user"`
 	ProjectID  int        `json:"project_id"`
 	Project    struct {
@@ -999,6 +1000,7 @@ type SubGroupEvent struct {
 // https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#tag-events
 type TagEvent struct {
 	ObjectKind   string `json:"object_kind"`
+	EventName    string `json:"event_name"`
 	Before       string `json:"before"`
 	After        string `json:"after"`
 	Ref          string `json:"ref"`
@@ -1011,6 +1013,7 @@ type TagEvent struct {
 	ProjectID    int    `json:"project_id"`
 	Message      string `json:"message"`
 	Project      struct {
+		ID                int             `json:"id"`
 		Name              string          `json:"name"`
 		Description       string          `json:"description"`
 		AvatarURL         string          `json:"avatar_url"`
@@ -1082,6 +1085,7 @@ type WikiPageEvent struct {
 		Slug    string `json:"slug"`
 		URL     string `json:"url"`
 		Action  string `json:"action"`
+		DiffURL string `json:"diff_url"`
 	} `json:"object_attributes"`
 }
 


Test patch:
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 421e3c6..89da50d 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -834,10 +834,18 @@ func TestTagEventUnmarshal(t *testing.T) {
 		t.Errorf("Tag Event is null")
 	}
 
+	if event.EventName != "tag_push" {
+		t.Errorf("EventName is %v, want %v", event.EventName, "tag_push")
+	}
+
 	if event.ProjectID != 1 {
 		t.Errorf("ProjectID is %v, want %v", event.ProjectID, 1)
 	}
 
+	if event.Project.ID != 1 {
+		t.Errorf("Project.ID is %v, want %v", event.Project.ID, 1)
+	}
+
 	if event.UserName != exampleEventUserName {
 		t.Errorf("Username is %s, want %s", event.UserName, exampleEventUserName)
 	}
diff --git a/testdata/webhooks/tag_push.json b/testdata/webhooks/tag_push.json
index d810817..92a6c79 100644
--- a/testdata/webhooks/tag_push.json
+++ b/testdata/webhooks/tag_push.json
@@ -1,5 +1,6 @@
 {
   "object_kind": "tag_push",
+  "event_name": "tag_push",
   "before": "0000000000000000000000000000000000000000",
   "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7",
   "ref": "refs/tags/v1.0.0",
diff --git a/testdata/webhooks/wiki_page.json b/testdata/webhooks/wiki_page.json
index 5bade8b..739635c 100644
--- a/testdata/webhooks/wiki_page.json
+++ b/testdata/webhooks/wiki_page.json
@@ -36,6 +36,7 @@
     "message": "adding an awesome page to the wiki",
     "slug": "awesome",
     "url": "http://example.com/root/awesome-project/wikis/awesome",
-    "action": "create"
+    "action": "create",
+    "diff_url": "http://example.com/root/awesome-project/wikis/awesome/diff" 
   }
 }