Repository: xanzy/go-gitlab
Pull request #1406 (2022-03-09 10:50:53)

Add Title to MergeCommentEvent.LastCommit struct
This has been missing while it's definitively passed by gitlab to the
MergeCommentEvent

Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>



Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 452d43f..8545b75 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -430,6 +430,7 @@ type MergeCommentEvent struct {
 		Target                    *Repository  `json:"target"`
 		LastCommit                struct {
 			ID        string     `json:"id"`
+			Title     string     `json:"title"`
 			Message   string     `json:"message"`
 			Timestamp *time.Time `json:"timestamp"`
 			URL       string     `json:"url"`
@@ -868,22 +869,7 @@ type SnippetCommentEvent struct {
 		Description  string `json:"description"`
 		URL          string `json:"url"`
 	} `json:"object_attributes"`
-	Snippet *struct {
-		ID                 int        `json:"id"`
-		Title              string     `json:"title"`
-		Content            string     `json:"content"`
-		AuthorID           int        `json:"author_id"`
-		ProjectID          int        `json:"project_id"`
-		CreatedAt          string     `json:"created_at"`
-		UpdatedAt          string     `json:"updated_at"`
-		Filename           string     `json:"file_name"`
-		ExpiresAt          string     `json:"expires_at"`
-		Type               string     `json:"type"`
-		VisibilityLevel    int        `json:"visibility_level"`
-		Description        string     `json:"description"`
-		Secret             bool       `json:"secret"`
-		RepositoryReadOnly bool       `json:"repository_read_only"`
-	} `json:"snippet"`
+	Snippet *Snippet `json:"snippet"`
 }
 
 // SubGroupEvent represents a subgroup event.


Test patch:
diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go
index b991deb..07cb40c 100644
--- a/event_parsing_webhook_test.go
+++ b/event_parsing_webhook_test.go
@@ -207,6 +207,11 @@ func TestParseMergeRequestCommentHook(t *testing.T) {
 	if event.MergeRequest.ID != 7 {
 		t.Errorf("MergeRequest ID is %v, want %v", event.MergeRequest.ID, 7)
 	}
+
+	expectedTitle := "Merge branch 'another-branch' into 'master'"
+	if event.MergeRequest.LastCommit.Title != expectedTitle {
+		t.Errorf("MergeRequest Title is %v, want %v", event.MergeRequest.Title, expectedTitle)
+	}
 }
 
 func TestParseMergeRequestHook(t *testing.T) {
diff --git a/testdata/webhooks/note_merge_request.json b/testdata/webhooks/note_merge_request.json
index d0b9bfc..f2d4121 100644
--- a/testdata/webhooks/note_merge_request.json
+++ b/testdata/webhooks/note_merge_request.json
@@ -100,6 +100,7 @@
     "last_commit": {
       "id": "562e173be03b8ff2efb05345d12df18815438a4b",
       "message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
+      "title": "Merge branch 'another-branch' into 'master'",
       "timestamp": "2015-04-08T21:00:25-07:00",
       "url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
       "author": {
diff --git a/testdata/webhooks/note_snippet.json b/testdata/webhooks/note_snippet.json
index 6817158..ef7ecf8 100644
--- a/testdata/webhooks/note_snippet.json
+++ b/testdata/webhooks/note_snippet.json
@@ -1,6 +1,5 @@
 {
   "object_kind": "note",
-  "event_type": "note",
   "user": {
     "id": 42,
     "name": "User1",
@@ -41,20 +40,11 @@
     "updated_at": "2015-05-17 18:35:50 UTC",
     "project_id": 5,
     "attachment": null,
-    "change_position": null,
-    "discussion_id": "e1c5835f5f99414806f6fe45b28s48cfebb89ee1",
     "line_code": null,
-    "commit_id": null,
+    "commit_id": "",
     "noteable_id": 53,
     "system": false,
-    "original_position": null,
-    "position": null,
-    "resolved_at": null,
-    "resolved_by_id": null,
-    "resolved_by_push": null,
     "st_diff": null,
-    "type": null,
-    "updated_by_id": null,
     "description": "Is this snippet doing what it's supposed to be doing?",
     "url": "http://example.com/gitlab-org/gitlab-test/snippets/53#note_1245"
   },
@@ -64,17 +54,11 @@
     "content": "puts 'Hello world'",
     "author_id": 1,
     "project_id": 5,
-    "created_at": "2016-01-04 15:31:46 UTC",
-    "updated_at": "2016-01-04 15:32:46 UTC",
+    "created_at": "2016-01-04T15:31:46.176Z",
+    "updated_at": "2016-01-04T15:31:46.176Z",
     "file_name": "test.rb",
     "expires_at": null,
     "type": "ProjectSnippet",
-    "visibility_level": 0,
-    "description": "Prints 'Hello world'",
-    "encrypted_secret_token": null,
-    "encrypted_secret_token_iv": null,
-    "secret": false,
-    "repository_read_only": false,
-    "secret_token": null
+    "visibility_level": 0
   }
 }