Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let API create and edit system webhooks, attempt 2 #33180

Merged
merged 8 commits into from
Jan 13, 2025

Conversation

mbollmann-v
Copy link
Contributor

@mbollmann-v mbollmann-v commented Jan 9, 2025

This PR fixes inconsistencies between system and default webhooks in the Gitea API. (See also #26418)

  • A system webhook is a webhook that captures events for all repositories.
  • A default webhook is copied to a new repository when it is created.

Before this PR POST /api/v1/admin/hooks/ creates default webhooks (if not configured otherwise) and GET /api/v1/admin/hooks/ returns system webhooks.

The PR introduces an optional query parameter to GET /api/v1/admin/hooks/ to enable selecting if either default, system or both kind of webhooks should be retrieved. By default the flag is set to return system webhooks keep current behaviour.

Examples

System Webhooks

Create

POST /api/v1/admin/hooks/

{
  "type": "gitea",
  "active": false,
  "branch_filter": "*",
  "events": [ "create", "..." ],
  "config": {
    "url": "http://...",
    "content_type": "json",
    "secret": "secret",
    "is_system_webhook": true // <-- controls hook type
  }
}

List

GET/api/v1/admin/hooks?type=system //type argument is optional here since it's the default

Others

The other relevant endpoints work as expected by referencing the hook by id

GET /api/v1/admin/hooks/:id
PATCH /api/v1/admin/hooks/:id
DELETE /api/v1/admin/hooks/:id

Default Webhooks

Create

POST /api/v1/admin/hooks/

{
  "type": "gitea",
  "active": false,
  "branch_filter": "*",
  "events": [ "create", "..." ],
  "config": {
    "url": "http://...",
    "content_type": "json",
    "secret": "secret",
    "is_system_webhook": false // optional, as false is the default value
  }
}

List

GET/api/v1/admin/hooks?type=default

Others

The other relevant endpoints work as expected by referencing the hook by id

GET /api/v1/admin/hooks/:id
PATCH /api/v1/admin/hooks/:id
DELETE /api/v1/admin/hooks/:id

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 9, 2025
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 9, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Jan 9, 2025
@lunny lunny added this to the 1.24.0 milestone Jan 9, 2025
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 10, 2025
@mbollmann-v mbollmann-v requested a review from lunny January 10, 2025 11:56
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 10, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 13, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jan 13, 2025
@lunny lunny enabled auto-merge (squash) January 13, 2025 16:51
@lunny lunny merged commit a90af22 into go-gitea:main Jan 13, 2025
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jan 13, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 14, 2025
* giteaofficial/main: (21 commits)
  Support public code/issue access for private repositories (go-gitea#33127)
  Validate that the tag doesn't exist when creating a tag via the web (go-gitea#33241)
  [skip ci] Updated translations via Crowdin
  Switch back to `vue-tsc` (go-gitea#33248)
  Let API create and edit system webhooks, attempt 2 (go-gitea#33180)
  Fix incorrect ref "blob" (go-gitea#33240)
  Refactor RefName (go-gitea#33234)
  Refactor context RefName and RepoAssignment (go-gitea#33226)
  [skip ci] Updated translations via Crowdin
  Fix upload file form (go-gitea#33230)
  Fix mirror bug (go-gitea#33224)
  Remove unused CSS styles and move some styles to proper files (go-gitea#33217)
  Refactor context repository (go-gitea#33202)
  [skip ci] Updated translations via Crowdin
  Fix unpin hint on the pinned pull requests (go-gitea#33207)
  fix(cache): cache test triggered by non memory cache (go-gitea#33220)
  Update README.md (go-gitea#33149)
  Fix editor markdown not incrementing in a numbered list (go-gitea#33187)
  Some small refactors (go-gitea#33144)
  Fix sync fork for consistency (go-gitea#33147)
  ...
@mbollmann-v mbollmann-v deleted the fix/23139-system-webhooks branch January 14, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants