Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Update snippet comment note webhook with current payload #1349

Merged
merged 1 commit into from
Mar 8, 2022
Merged

Update snippet comment note webhook with current payload #1349

merged 1 commit into from
Mar 8, 2022

Conversation

vntw
Copy link
Contributor

@vntw vntw commented Jan 24, 2022

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:

{
  "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": "[email protected]: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": "[email protected]:xxx.git",
    "ssh_url": "[email protected]: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": "[email protected]: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
  }
}

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 since I don't know anything about them, like `encrypted_secret_token`/`encrypted_secret_token_iv`/`secret_token`.
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Filename string `json:"file_name"`
ExpiresAt string `json:"expires_at"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is documented but doesn't exist in the payload… 🤷‍♀️ not sure what to do. It looks like a docs error since I don't see any way to define an expiration date in the UI

Maybe: (?)

Suggested change
ExpiresAt string `json:"expires_at"`

Copy link
Member

@svanharmelen svanharmelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long, long delay @vntw! LGTM 👍🏻

@svanharmelen svanharmelen merged commit e63371f into xanzy:master Mar 8, 2022
@vntw vntw deleted the fix-snippet-comment-note branch March 8, 2022 15:40
@vntw
Copy link
Contributor Author

vntw commented Mar 8, 2022

No problem at all, thank you for merging!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants