mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-18 23:20:51 +00:00
Actions Failure, Succes, Recover Webhooks (#7508)
Implement Actions Success, Failure and Recover webhooks for Forgejo, Gitea, Gogs, Slack, Discord, DingTalk, Telegram, Microsoft Teams, Feishu / Lark Suite, Matrix, WeCom (Wechat Work), Packagist. Some of these webhooks have not been manually tested. Implement settings for these new webhooks. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/7508): <!--number 7508 --><!--line 0 --><!--description QWN0aW9ucyBGYWlsdXJlLCBTdWNjZXMsIFJlY292ZXIgV2ViaG9va3M=-->Actions Failure, Succes, Recover Webhooks<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7508 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: christopher-besch <mail@chris-besch.com> Co-committed-by: christopher-besch <mail@chris-besch.com>
This commit is contained in:
parent
6ce9d764bc
commit
d17aa98262
27 changed files with 683 additions and 12 deletions
|
@ -74,7 +74,8 @@ func TestWebhook_EventsArray(t *testing.T) {
|
|||
"pull_request", "pull_request_assign", "pull_request_label", "pull_request_milestone",
|
||||
"pull_request_comment", "pull_request_review_approved", "pull_request_review_rejected",
|
||||
"pull_request_review_comment", "pull_request_sync", "wiki", "repository", "release",
|
||||
"package", "pull_request_review_request",
|
||||
"package", "pull_request_review_request", "action_run_failure",
|
||||
"action_run_recover", "action_run_success",
|
||||
},
|
||||
(&Webhook{
|
||||
HookEvent: &webhook_module.HookEvent{SendEverything: true},
|
||||
|
@ -89,15 +90,78 @@ func TestWebhook_EventsArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateWebhook(t *testing.T) {
|
||||
hook := &Webhook{
|
||||
RepoID: 3,
|
||||
URL: "https://www.example.com/unit_test",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":false,"send_everything":false,"choose_events":false,"events":{"create":false,"push":true,"pull_request":true}}`,
|
||||
}
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
require.NoError(t, CreateWebhook(db.DefaultContext, hook))
|
||||
unittest.AssertExistsAndLoadBean(t, hook)
|
||||
t.Run("Some chosen events 1", func(t *testing.T) {
|
||||
hook := &Webhook{
|
||||
RepoID: 3,
|
||||
URL: "https://www.example.com/unit_test",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":false,"send_everything":false,"choose_events":true,"events":{"create":false,"push":true,"pull_request":true}}`,
|
||||
}
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
require.NoError(t, CreateWebhook(db.DefaultContext, hook))
|
||||
hookFromDb := unittest.AssertExistsAndLoadBean(t, hook)
|
||||
assert.Equal(t, []string{
|
||||
string(webhook_module.HookEventPush),
|
||||
string(webhook_module.HookEventPullRequest),
|
||||
}, hookFromDb.EventsArray())
|
||||
})
|
||||
|
||||
t.Run("Some chosen events 2", func(t *testing.T) {
|
||||
hook := &Webhook{
|
||||
RepoID: 3,
|
||||
URL: "https://www.example.com/unit_test",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":false,"send_everything":false,"choose_events":true,"events":{"action_run_recover":false,"action_run_success":true}}`,
|
||||
}
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
require.NoError(t, CreateWebhook(db.DefaultContext, hook))
|
||||
hookFromDb := unittest.AssertExistsAndLoadBean(t, hook)
|
||||
assert.Equal(t, []string{string(webhook_module.HookEventActionRunSuccess)}, hookFromDb.EventsArray())
|
||||
})
|
||||
|
||||
t.Run("All events", func(t *testing.T) {
|
||||
hook := &Webhook{
|
||||
RepoID: 3,
|
||||
URL: "https://www.example.com/unit_test",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":false,"send_everything":false,"choose_events":true,"events":{"create":true,"delete":true,"fork":true,"issues":true,"issue_assign":true,"issue_label":true,"issue_milestone":true,"issue_comment":true,"push":true,"pull_request":true,"pull_request_assign":true,"pull_request_label":true,"pull_request_milestone":true,"pull_request_comment":true,"pull_request_review":true,"pull_request_sync":true,"pull_request_review_request":true,"wiki":true,"repository":true,"release":true,"package":true,"action_run_failure":true,"action_run_recover":true,"action_run_success":true}}`,
|
||||
}
|
||||
unittest.AssertNotExistsBean(t, hook)
|
||||
require.NoError(t, CreateWebhook(db.DefaultContext, hook))
|
||||
hookFromDb := unittest.AssertExistsAndLoadBean(t, hook)
|
||||
assert.Equal(t, []string{
|
||||
string(webhook_module.HookEventCreate),
|
||||
string(webhook_module.HookEventDelete),
|
||||
string(webhook_module.HookEventFork),
|
||||
string(webhook_module.HookEventPush),
|
||||
string(webhook_module.HookEventIssues),
|
||||
string(webhook_module.HookEventIssueAssign),
|
||||
string(webhook_module.HookEventIssueLabel),
|
||||
string(webhook_module.HookEventIssueMilestone),
|
||||
string(webhook_module.HookEventIssueComment),
|
||||
string(webhook_module.HookEventPullRequest),
|
||||
string(webhook_module.HookEventPullRequestAssign),
|
||||
string(webhook_module.HookEventPullRequestLabel),
|
||||
string(webhook_module.HookEventPullRequestMilestone),
|
||||
string(webhook_module.HookEventPullRequestComment),
|
||||
string(webhook_module.HookEventPullRequestReviewApproved),
|
||||
string(webhook_module.HookEventPullRequestReviewRejected),
|
||||
string(webhook_module.HookEventPullRequestReviewComment),
|
||||
string(webhook_module.HookEventPullRequestSync),
|
||||
string(webhook_module.HookEventWiki),
|
||||
string(webhook_module.HookEventRepository),
|
||||
string(webhook_module.HookEventRelease),
|
||||
string(webhook_module.HookEventPackage),
|
||||
string(webhook_module.HookEventPullRequestReviewRequest),
|
||||
// these aren't webhook event types
|
||||
// string(webhook_module.HookEventSchedule),
|
||||
// string(webhook_module.HookEventWorkflowDispatch),
|
||||
string(webhook_module.HookEventActionRunFailure),
|
||||
string(webhook_module.HookEventActionRunRecover),
|
||||
string(webhook_module.HookEventActionRunSuccess),
|
||||
},
|
||||
hookFromDb.EventsArray())
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetWebhookByRepoID(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue