You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/models
Michael B. a90af22003
Let API create and edit system webhooks, attempt 2 (#33180)
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
```
4 weeks ago
..
actions Refactor RefName (#33234) 4 weeks ago
activities Refactor RefName (#33234) 4 weeks ago
admin Fix javascript error when an anonymous user visiting migration page (#32144) 4 months ago
asymkey Refactor older tests to use testify (#33140) 4 weeks ago
auth Refactor tests (#33021) 1 month ago
avatars Replace 10 more gt- classes with tw- (#29945) 11 months ago
db Refactor older tests to use testify (#33140) 4 weeks ago
dbfs Enable `unparam` linter (#31277) 8 months ago
fixtures Let API create and edit system webhooks, attempt 2 (#33180) 4 weeks ago
git Enable tenv and testifylint rules (#32852) 2 months ago
issues Fix unpin hint on the pinned pull requests (#33207) 4 weeks ago
migrations Automerge supports deleting branch automatically after merging (#32343) 4 weeks ago
organization Refactor older tests to use testify (#33140) 4 weeks ago
packages Refactor maven package registry (#33049) 1 month ago
perm Enable tenv and testifylint rules (#32852) 2 months ago
project Use project's redirect url instead of composing url (#33058) 1 month ago
pull Automerge supports deleting branch automatically after merging (#32343) 4 weeks ago
renderhelper Refactor render system (orgmode) (#32671) 2 months ago
repo Refactor context RefName and RepoAssignment (#33226) 4 weeks ago
secret Clarify Actions resources ownership (#31724) 6 months ago
shared/types Refactor locale&string&template related code (#29165) 12 months ago
system Refactor deletion (#28610) 1 year ago
unit Add `DEFAULT_MIRROR_REPO_UNITS` and `DEFAULT_TEMPLATE_REPO_UNITS` options (#32416) 3 months ago
unittest Make git clone URL could use current signed-in user (#33091) 1 month ago
user Some small refactors (#33144) 4 weeks ago
webhook Let API create and edit system webhooks, attempt 2 (#33180) 4 weeks ago
main_test.go make writing main test easier (#27270) 1 year ago
repo.go Fix issue comment number (#30556) 1 month ago
repo_test.go Fix issue comment number (#30556) 1 month ago