Repository: xanzy/go-gitlab
Pull request #1349 (2022-01-24 20:05:16)

Update snippet comment note webhook with current payload
This adds all fields that are currently delivered by a GitLab.com instance. The main issue that I had was apparently `Snippet.CreatedAt` and `Snippet.UpdatedAt` changed their format and are now like a merge request note. This caused

```
parsing time "\"2022-01-24 18:41:19 UTC\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse " 18:41:19 UTC\"" as "T"
```

I ignored some fields for now since I don't know anything about them, like
- `encrypted_secret_token`
- `encrypted_secret_token_iv`
- `secret_token`

Docs: https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#comment-on-a-code-snippet

The original webhook payload (with some values edited) for reference:
```json
{
  "object_kind": "note",
  "event_type": "note",
  "user": {
    "id": 1,
    "name": "xxx",
    "username": "xxx",
    "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/xxx/avatar.png",
    "email": "[REDACTED]"
  },
  "project_id": 1,
  "project": {
    "id": 1,
    "name": "xxx",
    "description": "xxx",
    "web_url": "https://gitlab.com/xxx",
    "avatar_url": "https://gitlab.com/uploads/-/system/project/avatar/1/xxx.png",
    "git_ssh_url": "git@gitlab.com:xxx.git",
    "git_http_url": "https://gitlab.com/xxx.git",
    "namespace": "xxx",
    "visibility_level": 0,
    "path_with_namespace": "xxx",
    "default_branch": "main",
    "ci_config_path": "",
    "homepage": "https://gitlab.com/xxx",
    "url": "git@gitlab.com:xxx.git",
    "ssh_url": "git@gitlab.com:xxx.git",
    "http_url": "https://gitlab.com/xxx.git"
  },
  "object_attributes": {
    "attachment": null,
    "author_id": 1,
    "change_position": null,
    "commit_id": null,
    "created_at": "2022-01-24 18:23:11 UTC",
    "discussion_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "id": 1,
    "line_code": null,
    "note": "test",
    "noteable_id": 1,
    "noteable_type": "Snippet",
    "original_position": null,
    "position": null,
    "project_id": 1,
    "resolved_at": null,
    "resolved_by_id": null,
    "resolved_by_push": null,
    "st_diff": null,
    "system": false,
    "type": null,
    "updated_at": "2022-01-24 18:23:01 UTC",
    "updated_by_id": null,
    "description": "test",
    "url": "https://gitlab.com/xxx/-/snippets/xxx#note_xxx"
  },
  "repository": {
    "name": "xxx",
    "url": "git@gitlab.com:xxx.git",
    "description": "xxx",
    "homepage": "https://gitlab.com/xxx"
  },
  "snippet": {
    "id": 1,
    "title": "xxx",
    "content": "xxx",
    "author_id": 1,
    "project_id": 1,
    "created_at": "2022-01-21 04:21:14 UTC",
    "updated_at": "2022-01-24 18:23:11 UTC",
    "file_name": "xxx",
    "type": "ProjectSnippet",
    "visibility_level": 0,
    "description": "xxx",
    "encrypted_secret_token": null,
    "encrypted_secret_token_iv": null,
    "secret": false,
    "repository_read_only": false,
    "secret_token": null
  }
}
```


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index 1a14052..70c1160 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -868,7 +868,22 @@ type SnippetCommentEvent struct {
 		Description  string `json:"description"`
 		URL          string `json:"url"`
 	} `json:"object_attributes"`
-	Snippet *Snippet `json:"snippet"`
+	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"`
 }
 
 // TagEvent represents a tag event.


Test patch:
diff --git a/testdata/webhooks/note_snippet.json b/testdata/webhooks/note_snippet.json
index ef7ecf8..6817158 100644
--- a/testdata/webhooks/note_snippet.json
+++ b/testdata/webhooks/note_snippet.json
@@ -1,5 +1,6 @@
 {
   "object_kind": "note",
+  "event_type": "note",
   "user": {
     "id": 42,
     "name": "User1",
@@ -40,11 +41,20 @@
     "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": "",
+    "commit_id": null,
     "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"
   },
@@ -54,11 +64,17 @@
     "content": "puts 'Hello world'",
     "author_id": 1,
     "project_id": 5,
-    "created_at": "2016-01-04T15:31:46.176Z",
-    "updated_at": "2016-01-04T15:31:46.176Z",
+    "created_at": "2016-01-04 15:31:46 UTC",
+    "updated_at": "2016-01-04 15:32:46 UTC",
     "file_name": "test.rb",
     "expires_at": null,
     "type": "ProjectSnippet",
-    "visibility_level": 0
+    "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
   }
 }