geluk / matrix-webhook-gateway

Webhook gateway for Matrix / Synapse. Create and manage webhooks in Matrix channels for multiple services.
MIT License
18 stars 4 forks source link

Gitea Plugin #21

Closed Dual-0 closed 2 years ago

Dual-0 commented 2 years ago

Hello,

I tried the gitea.ts plugin on my hosted gitea but webhook-gateway shows the error: 2021-10-16 10:00:46.810.000 INFO [plg-gitea] Unknown Gitea action: 'undefined'

gitea config: image

last webhook: image

do you need more informations to debug?

regards

geluk commented 2 years ago

Perhaps the request body is formatted in an unexpected manner? Can you try replacing the following line:

this.logger.info(`Unknown Gitea action: '${body.action}'`);

With this?

this.logger.info(`Gitea webhook body: '${JSON.stringify(body)}'`);
Dual-0 commented 2 years ago

hope this helps Gitea webhook body: '{"ref":"refs/heads/master","before":"009a21d2d7a6120c0c8b64c6313b4a57335b784e","after":"009a21d2d7a6120c0c8b64c6313b4a57335b784e","compare_url":"","commits":[{"id":"009a21d2d7a6120c0c8b64c6313b4a57335b784e","message":"update iconTheme extension\n","url":"https://git.domain.com/myusername/MY_Repo/commit/009a21d2d7a6120c0c8b64c6313b4a57335b784e","author":{"name":"myusername","email":"myusername@mail.com","username":""},"committer":{"name":"myusername","email":"myusername@mail.com","username":""},"verification":null,"timestamp":"0001-01-01T00:00:00Z","added":null,"removed":null,"modified":null}],"head_commit":{"id":"009a21d2d7a6120c0c8b64c6313b4a57335b784e","message":"update iconTheme extension\n","url":"https://git.domain.com/myusername/MY_Repo/commit/009a21d2d7a6120c0c8b64c6313b4a57335b784e","author":{"name":"myusername","email":"myusername@mail.com","username":""},"committer":{"name":"myusername","email":"myusername@mail.com","username":""},"verification":null,"timestamp":"0001-01-01T00:00:00Z","added":null,"removed":null,"modified":null},"repository":{"id":10,"owner":{"id":1,"login":"myusername","full_name":"myusername","email":"myusername@mail.com","avatar_url":"https://git.domain.com/user/avatar/myusername/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2021-01-30T17:08:17+01:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"myusername"},"name":"MY_Repo","full_name":"myusername/MY_Repo","description":"","empty":false,"private":true,"fork":false,"template":false,"parent":null,"mirror":false,"size":38,"html_url":"https://git.domain.com/myusername/MY_Repo","ssh_url":"git@git.domain.com:myusername/MY_Repo.git","clone_url":"https://git.domain.com/myusername/MY_Repo.git","original_url":"","website":"","stars_count":0,"forks_count":0,"watchers_count":1,"open_issues_count":0,"open_pr_counter":0,"release_counter":0,"default_branch":"master","archived":false,"created_at":"2021-08-14T20:32:06+02:00","updated_at":"2021-10-16T12:00:46+02:00","permissions":{"admin":false,"push":false,"pull":false},"has_issues":false,"has_wiki":false,"has_pull_requests":false,"has_projects":false,"ignore_whitespace_conflicts":false,"allow_merge_commits":false,"allow_rebase":false,"allow_rebase_explicit":false,"allow_squash_merge":false,"default_merge_style":"merge","avatar_url":"https://git.domain.com/repo-avatars/10-c7a07ea4eeed3ad67dcb5a8e42ac9f9a","internal":false,"mirror_interval":""},"pusher":{"id":1,"login":"myusername","full_name":"myusername","email":"myusername@mail.com","avatar_url":"https://git.domain.com/user/avatar/myusername/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2021-01-30T17:08:17+01:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"myusername"},"sender":{"id":1,"login":"myusername","full_name":"myusername","email":"myusername@mail.com","avatar_url":"https://git.domain.com/user/avatar/myusername/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2021-01-30T17:08:17+01:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"myusername"}}'

geluk commented 2 years ago

That definitely does help, it looks like the 'secret' field may be missing sometimes. I've made it an optional field.

You can pull the latest Docker image for the :dev tag to try it out. Could you let me know if this fixes your issue?

Dual-0 commented 2 years ago

yes for sure. My ansible script grabs the new girtea.ts tonight.

Oct 19 23:42:39 HOSTNAME node[1979113]: 2021-10-19 21:42:39.141.000         INFO         [plg-gitea]                    Unknown Gitea action: 'undefined'
Oct 19 23:46:46 HOSTNAME node[1979113]: 2021-10-19 21:46:46.504.000         INFO         [plg-gitea]                    Unknown Gitea action: 'undefined'

1st one was the intregratet webhook test in gitea. The 2nd one was a push to my repo.

geluk commented 2 years ago

I've created a test from your webhook content to check for any other issues with deserialisation, apparently the internal_tracker field is optional as well, so I've updated the plugin to reflect that.

If you update the plugin again, it should work now (the test successfully parses the JSON you've posted above).

Dual-0 commented 2 years ago

now it works. Thanks for the quick help. Two more things I found out:

geluk commented 2 years ago

I'm glad it works now! Regarding your questions:

only one message is sent even if multiple commits are submitted.

This is intentional, to prevent the plugin from generating too many messages, and because Gitea only sends the first and last commits if you push multiple commits at once.

in gitea webview i get 10 digits and in the matrix 8 digits for SHA1

This is because the length of shortened commit hashes is mostly arbitrary. Git itself uses 7 characters, as does GitHub, while Gitea uses 10 characters, and GitLab uses 8.

the compare link in the message above links to element web when "compare_url": "", in json is empty

Good point. I think it's reasonable to remove the link completely if the compare URL is not set.

geluk commented 2 years ago

Fixed in version 1.1.