Forgejo compatible webhook #3

Closed
opened 2022-10-05 16:45:52 +05:30 by dachary · 8 comments

It would be nice to have an API endpoint such as /api/v1/gitea that accepts a Gitea webhook payload. Such a webhook could be set system wide by a Gitea instance to keep librepages informed of any new repository or branch created as well as any new push to all repositories.

Librepages could then decide to checkout such a repository or branch based on configurable rules such as "the name of the branch is pages", "the name of the repo is pages".

A secret can be added to quickly discard unauthorized POST to the API.

image

It would be nice to have an API endpoint such as `/api/v1/gitea` that accepts a [Gitea webhook](https://docs.gitea.io/en-us/webhooks/) payload. Such a webhook could be set system wide by a Gitea instance to keep librepages informed of any new repository or branch created as well as any new push to all repositories. Librepages could then decide to checkout such a repository or branch based on configurable rules such as "the name of the branch is pages", "the name of the repo is pages". A secret can be added to quickly discard unauthorized POST to the API. ![image](/attachments/8bd83e3f-4267-4e1b-951a-51bee4778133)
Owner

Great idea! I'm working on a Gitea integration service (bootstrapped a couple of weeks ago, nothing interesting to publish yet). I think this webhook can be added to it.

I would like to keep the main service as generic as possible and provide integrations as separate services.

Great idea! I'm working on a Gitea integration service (bootstrapped a couple of weeks ago, nothing interesting to publish yet). I think this webhook can be added to it. I would like to keep the main service as generic as possible and provide integrations as separate services.
realaravinth added spent time 2022-12-25 12:35:46 +05:30
12 hours
Owner

Logging time spent between 22-12-2022 to 255-12-2022

Summary

  1. Investigate Gitea webhooks([0][1][2][3])
  2. Wrote a test server to inspect webhook payload
  3. Design:
    User can create new webhooks, a webhook can be associated to multiple repositories in the same forge instance. Webhook requests are processed to effect relevant changes within the system
Logging time spent between 22-12-2022 to 255-12-2022 ## Summary 1. Investigate Gitea webhooks([0][1][2][3]) 2. Wrote a test server to inspect webhook payload 3. Design: User can create new webhooks, a webhook can be associated to multiple repositories in the same forge instance. Webhook requests are processed to effect relevant changes within the system [^0]: https://docs.gitea.io/en-us/webhooks/ [^1]: https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks#validating-payloads-from-github [^2]: https://libmedium.batsense.net/aergonaut/writing-a-github-webhook-with-rust-part-1-rocket-4426dd06d45d [^3]: https://github.com/go-gitea/gitea/issues/11755
realaravinth added spent time 2022-12-28 04:45:55 +05:30
8 hours
Owner

Diff: b93373e96b...0c6199494b

Summary

  • Store webhooks in DB
  • Verify integrity of Gitea webhook payloads
  • Web view to add, view and list all webhooks
  • REST API views to add, view and list all webhooks
Diff: https://git.batsense.net/LibrePages/librepages/compare/b93373e96bc35352bf8b0256e0b8981061aa6254...0c6199494b13499036a0e734346a52db05b4ca20 ## Summary - Store webhooks in DB - Verify integrity of Gitea webhook payloads - Web view to add, view and list all webhooks - REST API views to add, view and list all webhooks
realaravinth added spent time 2022-12-28 13:39:39 +05:30
2 hours
Owner

Diff: d919bad570

Unit test webhook endpoint with signature verification.

Diff: https://git.batsense.net/LibrePages/librepages/commit/d919bad5702d757f600df9c30a303d8cd4fdd4f8 Unit test webhook endpoint with signature verification.
Owner

@dachary: I've implemented a basic webhook integration where users can install webhooks to their repositories (or admins can set default webhooks from the admin panel). However, auto-enabling repositories for publication is not implemented as, I feel, it could lead to a lot of wastage.

This webhook integration removes the need for the user to notify LibrePages from the CI. A push event from the webhook on the deployed branch will update the deployment.

Workflow

  1. Create webhook: Authenticated users can create webhooks on LibrePages

image

  1. Grab webhook configuration parameters from LibrePages:

image

  1. Configure Forgejo/Gitea:

image

@dachary: I've implemented a basic webhook integration where users can install webhooks to their repositories (or admins can set default webhooks from the admin panel). However, auto-enabling repositories for publication is not implemented as, I feel, it could lead to a lot of wastage. This webhook integration removes the need for the user to notify LibrePages from the CI. A push event from the webhook on the deployed branch will update the deployment. ## Workflow 1. Create webhook: Authenticated users can create webhooks on LibrePages ![image](/attachments/a42971ab-2d34-45a4-a6bd-18fc9dd8c292) 2. Grab webhook configuration parameters from LibrePages: ![image](/attachments/71d5b752-30d4-4583-a287-839a8256eb98) 3. Configure Forgejo/Gitea: ![image](/attachments/981c0b8a-d3f4-41d0-8e5d-302c8846a596)
realaravinth added spent time 2022-12-28 14:08:34 +05:30
20 minutes
dachary changed title from Gitea compatible webhook to Forgejo compatible webhook 2022-12-28 15:31:08 +05:30
Author

Sounds good. I did a cosmetic change for the title 😄

Sounds good. I did a cosmetic change for the title :smile:
Owner

I did a cosmetic change for the title

I followed suite with #17 :)

> I did a cosmetic change for the title I followed suite with #17 :)
Owner

Feel free to reopen this issue if you think this needs more work.

Current implementation archives the bare minimum but to offer more would complicate the UX and the codebase. A LibrePages instance will serve multiple Forgejo (and other forge) instances. Supporting tighter integration without forgefed will require heavy involvement from LibrePages and forge instance admins.

I explored this matter with #16 and abandoned efforts due to the reasons mentioned here.

Feel free to reopen this issue if you think this needs more work. Current implementation archives the bare minimum but to offer more would complicate the UX and the codebase. A LibrePages instance will serve multiple Forgejo (and other forge) instances. Supporting tighter integration without forgefed will require heavy involvement from LibrePages and forge instance admins. I explored this matter with https://git.batsense.net/LibrePages/librepages/issues/16 and abandoned efforts due to the reasons [mentioned here](https://git.batsense.net/LibrePages/librepages/issues/16#issuecomment-807).
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Total Time Spent: 22 hours 20 minutes
realaravinth
22 hours 20 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: LibrePages/librepages#3
No description provided.