Repository: xanzy/go-gitlab
Pull request #1688 (2023-04-10 21:39:12)

Updated Commit comment event
@svanharmelen Looking for a review


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 5044444..f322cec 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -80,9 +80,11 @@ type BuildEvent struct {
 // https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#comment-on-a-commit
 type CommitCommentEvent struct {
 	ObjectKind string `json:"object_kind"`
+	EventType  string `json:"event_type"`
 	User       *User  `json:"user"`
 	ProjectID  int    `json:"project_id"`
 	Project    struct {
+		ID                int             `json:"id"`
 		Name              string          `json:"name"`
 		Description       string          `json:"description"`
 		AvatarURL         string          `json:"avatar_url"`
@@ -112,18 +114,9 @@ type CommitCommentEvent struct {
 		CommitID     string `json:"commit_id"`
 		NoteableID   int    `json:"noteable_id"`
 		System       bool   `json:"system"`
-		StDiff       struct {
-			Diff        string `json:"diff"`
-			NewPath     string `json:"new_path"`
-			OldPath     string `json:"old_path"`
-			AMode       string `json:"a_mode"`
-			BMode       string `json:"b_mode"`
-			NewFile     bool   `json:"new_file"`
-			RenamedFile bool   `json:"renamed_file"`
-			DeletedFile bool   `json:"deleted_file"`
-		} `json:"st_diff"`
-		Description string `json:"description"`
-		URL         string `json:"url"`
+		StDiff       *Diff  `json:"st_diff"`
+		Description  string `json:"description"`
+		URL          string `json:"url"`
 	} `json:"object_attributes"`
 	Commit *struct {
 		ID        string     `json:"id"`


Test patch:
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 421e3c6..e9614c4 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -64,6 +64,48 @@ func TestBuildEventUnmarshal(t *testing.T) {
 	}
 }
 
+func TestCommitCommentEventUnmarshal(t *testing.T) {
+	jsonObject := loadFixture("testdata/webhooks/note_commit.json")
+
+	var event *CommitCommentEvent
+	err := json.Unmarshal(jsonObject, &event)
+	if err != nil {
+		t.Errorf("Commit Comment Event can not unmarshaled: %v\n ", err.Error())
+	}
+
+	if event == nil {
+		t.Errorf("Commit Comment Event is null")
+	}
+
+	if event.ObjectKind != string(NoteEventTargetType) {
+		t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, NoteEventTargetType)
+	}
+
+	if event.EventType != "note" {
+		t.Errorf("EventType is %v, want %v", event.EventType, "note")
+	}
+
+	if event.ProjectID != 5 {
+		t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5)
+	}
+
+	if event.User.ID != 42 {
+		t.Errorf("User ID is %d, want %d", event.User.ID, 42)
+	}
+
+	if event.Repository.Name != "Gitlab Test" {
+		t.Errorf("Repository name is %v, want %v", event.Repository.Name, "Gitlab Test")
+	}
+
+	if event.ObjectAttributes.NoteableType != "Commit" {
+		t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Commit")
+	}
+
+	if event.Commit.Title != "Add submodule" {
+		t.Errorf("Issue title is %v, want %v", event.Commit.Title, "Add submodule")
+	}
+}
+
 func TestJobEventUnmarshal(t *testing.T) {
 	jsonObject := loadFixture("testdata/webhooks/job.json")
 
diff --git a/testdata/webhooks/note_commit.json b/testdata/webhooks/note_commit.json
index cc268b3..a976b78 100644
--- a/testdata/webhooks/note_commit.json
+++ b/testdata/webhooks/note_commit.json
@@ -1,5 +1,6 @@
 {
   "object_kind": "note",
+  "event_type": "note",
   "user": {
     "id": 42,
     "name": "User1",