From ba6a9a915a8875a89ec3c419f6378c14a8e53133 Mon Sep 17 00:00:00 2001 From: Max Stanley Date: Sun, 12 Nov 2023 14:42:11 +0000 Subject: [PATCH] initial --- models/webhook/webhook.go | 6 + modules/structs/action_run.go | 19 ++++ modules/structs/hook_artifact.go | 7 ++ modules/structs/hook_workflow_run.go | 25 +++++ modules/webhook/structs.go | 2 + modules/webhook/type.go | 3 + options/locale/locale_en-US.ini | 2 + routers/api/actions/runner/runner.go | 6 + routers/api/actions/runner/utils.go | 4 + routers/web/repo/setting/webhook.go | 1 + services/actions/notifier_helper.go | 3 + services/convert/action.go | 31 +++++ services/convert/artifact.go | 17 +++ services/forms/repo_form.go | 1 + services/notify/notifier.go | 5 + services/notify/notify.go | 19 ++++ services/notify/null.go | 10 ++ services/webhook/notifier.go | 106 ++++++++++-------- templates/repo/settings/webhook/settings.tmpl | 11 ++ 19 files changed, 233 insertions(+), 45 deletions(-) create mode 100644 modules/structs/action_run.go create mode 100644 modules/structs/hook_artifact.go create mode 100644 modules/structs/hook_workflow_run.go create mode 100644 services/convert/action.go create mode 100644 services/convert/artifact.go diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index b28cea6a9cc9c..be8e143ae9cd1 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -304,6 +304,11 @@ func (w *Webhook) HasPullRequestReviewRequestEvent() bool { (w.ChooseEvents && w.HookEvents.PullRequestReviewRequest) } +// HasWorkflowRunEvent returns if hook enabled workflow run event. +func (w *Webhook) HasWorkflowRunEvent() bool { + return w.SendEverything || (w.ChooseEvents && w.HookEvents.WorkflowRun) +} + // EventCheckers returns event checkers func (w *Webhook) EventCheckers() []struct { Has func() bool @@ -336,6 +341,7 @@ func (w *Webhook) EventCheckers() []struct { {w.HasReleaseEvent, webhook_module.HookEventRelease}, {w.HasPackageEvent, webhook_module.HookEventPackage}, {w.HasPullRequestReviewRequestEvent, webhook_module.HookEventPullRequestReviewRequest}, + {w.HasWorkflowRunEvent, webhook_module.HookEventWorkflowRun}, } } diff --git a/modules/structs/action_run.go b/modules/structs/action_run.go new file mode 100644 index 0000000000000..71f5e849f4147 --- /dev/null +++ b/modules/structs/action_run.go @@ -0,0 +1,19 @@ +package structs + +type ActionRun struct { + ID int64 `json:"id"` + Title string `json:"title"` + Repo *Repository `json:"repo"` + Owner *User `json:"owner"` + TriggerUser *User `json:"trigger_user"` + WorkflowID string `json:"workflow_id"` + Index int64 `json:"index"` + Ref string `json:"ref"` + CommitSHA string `json:"commit_sha"` + Status string `json:"status"` + Version int `json:"version"` + Started string `json:"time_started"` + Stopped string `json:"time_stopped"` + Created string `json:"time_created"` + Updated string `json:"time_updated"` +} diff --git a/modules/structs/hook_artifact.go b/modules/structs/hook_artifact.go new file mode 100644 index 0000000000000..f808746471744 --- /dev/null +++ b/modules/structs/hook_artifact.go @@ -0,0 +1,7 @@ +package structs + +type ArtifactPayload struct { + ArtifactID int64 `json:"artifact_id"` + ArtifactName string `json:"artifact_name"` + RunID int64 `json:"run_id"` +} diff --git a/modules/structs/hook_workflow_run.go b/modules/structs/hook_workflow_run.go new file mode 100644 index 0000000000000..a756026f396ef --- /dev/null +++ b/modules/structs/hook_workflow_run.go @@ -0,0 +1,25 @@ +package structs + +import "code.gitea.io/gitea/modules/json" + +var _ Payloader = &WorkflowRunPayload{} + +type HookWorkflowRunAction string + +const ( + HookWorkflowRunRequested HookWorkflowRunAction = "requested" + HookWorkflowRunInProgress HookWorkflowRunAction = "in_progress" + HookWorkflowRunCompleted HookWorkflowRunAction = "completed" +) + +type WorkflowRunPayload struct { + Action HookWorkflowRunAction `json:"action"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` + ActionRun *ActionRun `json:"action_run"` + Artifacts *[]ArtifactPayload `json:"artifacts"` +} + +func (p *WorkflowRunPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} diff --git a/modules/webhook/structs.go b/modules/webhook/structs.go index 1e7d6c1a14e3c..7ad8056939733 100644 --- a/modules/webhook/structs.go +++ b/modules/webhook/structs.go @@ -28,6 +28,7 @@ type HookEvents struct { Repository bool `json:"repository"` Release bool `json:"release"` Package bool `json:"package"` + WorkflowRun bool `json:"workflow_run"` } // ParseHookEvents converts a list of strings to HookEvents @@ -54,6 +55,7 @@ func ParseHookEvents(eventTypes []string) HookEvents { Wiki: util.SliceContainsString(eventTypes, HookEventWiki.Event(), caseInsensitive), Repository: util.SliceContainsString(eventTypes, HookEventRepository.Event(), caseInsensitive), Release: util.SliceContainsString(eventTypes, HookEventRelease.Event(), caseInsensitive), + WorkflowRun: util.SliceContainsString(eventTypes, HookEventWorkflowRun.Event(), caseInsensitive), } } diff --git a/modules/webhook/type.go b/modules/webhook/type.go index 7042d391b7eb4..32b9e2a542066 100644 --- a/modules/webhook/type.go +++ b/modules/webhook/type.go @@ -31,6 +31,7 @@ const ( HookEventRepository HookEventType = "repository" HookEventRelease HookEventType = "release" HookEventPackage HookEventType = "package" + HookEventWorkflowRun HookEventType = "workflow_run" ) // Event returns the HookEventType as an event string @@ -63,6 +64,8 @@ func (h HookEventType) Event() string { return "repository" case HookEventRelease: return "release" + case HookEventWorkflowRun: + return "workflow_run" } return "" } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a7a7a4f4c50f9..954e3d2d33a9b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2220,6 +2220,8 @@ settings.event_pull_request_approvals = Pull Request Approvals settings.event_pull_request_merge = Pull Request Merge settings.event_package = Package settings.event_package_desc = Package created or deleted in a repository. +settings.event_workflow_run = Workflow Run +settings.event_workflow_run_desc = Workflow runs created, started or completed. settings.branch_filter = Branch filter settings.branch_filter_desc = Branch whitelist for push, branch creation and branch deletion events, specified as glob pattern. If empty or *, events for all branches are reported. See github.com/gobwas/glob documentation for syntax. Examples: master, {master,release*}. settings.authorization_header = Authorization Header diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go index 8df6f297ceb96..a879f0e60572f 100644 --- a/routers/api/actions/runner/runner.go +++ b/routers/api/actions/runner/runner.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" actions_service "code.gitea.io/gitea/services/actions" + notify_service "code.gitea.io/gitea/services/notify" runnerv1 "code.gitea.io/actions-proto-go/runner/v1" "code.gitea.io/actions-proto-go/runner/v1/runnerv1connect" @@ -174,6 +175,11 @@ func (s *Service) UpdateTask( return nil, status.Errorf(codes.Internal, "update task: %v", err) } + if task.Status.IsDone() { + // notify task completed + notify_service.CompletedWorkflowRun(ctx, task.Job.Run) + } + for k, v := range req.Msg.Outputs { if len(k) > 255 { log.Warn("Ignore the output of task %d because the key is too long: %q", task.ID, k) diff --git a/routers/api/actions/runner/utils.go b/routers/api/actions/runner/utils.go index 24432ab6b202d..d177050a51773 100644 --- a/routers/api/actions/runner/utils.go +++ b/routers/api/actions/runner/utils.go @@ -17,6 +17,7 @@ import ( secret_module "code.gitea.io/gitea/modules/secret" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/actions" + notify_service "code.gitea.io/gitea/services/notify" runnerv1 "code.gitea.io/actions-proto-go/runner/v1" "google.golang.org/protobuf/types/known/structpb" @@ -31,6 +32,9 @@ func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv return nil, false, nil } + // notify action in progress + notify_service.StartedWorkflowRun(ctx, t.Job.Run) + actions.CreateCommitStatus(ctx, t.Job) task := &runnerv1.Task{ diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index ea5abb0579206..fe7f2d76205f5 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -182,6 +182,7 @@ func ParseHookEvent(form forms.WebhookForm) *webhook_module.HookEvent { Wiki: form.Wiki, Repository: form.Repository, Package: form.Package, + WorkflowRun: form.WorkflowRun, }, BranchFilter: form.BranchFilter, } diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 7d5f6c6c0a3ce..2debe15b288cb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -23,6 +23,7 @@ import ( api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/services/convert" + notify_service "code.gitea.io/gitea/services/notify" "github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/model" @@ -273,6 +274,8 @@ func handleWorkflows( continue } + notify_service.RequestedWorkflowRun(ctx, run) + alljobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID}) if err != nil { log.Error("FindRunJobs: %v", err) diff --git a/services/convert/action.go b/services/convert/action.go new file mode 100644 index 0000000000000..a22ae527116c8 --- /dev/null +++ b/services/convert/action.go @@ -0,0 +1,31 @@ +package convert + +import ( + "context" + + models_actions "code.gitea.io/gitea/models/actions" + "code.gitea.io/gitea/models/perm" + access_model "code.gitea.io/gitea/models/perm/access" + api "code.gitea.io/gitea/modules/structs" +) + +// ToRepo converts an ActionRun to api.ActionRun +func ToActionRun(ctx context.Context, run *models_actions.ActionRun) *api.ActionRun { + return &api.ActionRun{ + ID: run.ID, + Title: run.Title, + Repo: ToRepo(ctx, run.Repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), + Owner: ToUser(ctx, run.Repo.Owner, nil), + TriggerUser: ToUser(ctx, run.TriggerUser, nil), + WorkflowID: run.WorkflowID, + Index: run.Index, + Ref: run.Ref, + CommitSHA: run.CommitSHA, + Status: run.Status.String(), + Version: run.Version, + Started: run.Started.FormatLong(), + Stopped: run.Stopped.FormatLong(), + Created: run.Created.FormatLong(), + Updated: run.Updated.FormatLong(), + } +} diff --git a/services/convert/artifact.go b/services/convert/artifact.go new file mode 100644 index 0000000000000..1f6e2f9730f7a --- /dev/null +++ b/services/convert/artifact.go @@ -0,0 +1,17 @@ +package convert + +import ( + "context" + + models_actions "code.gitea.io/gitea/models/actions" + api "code.gitea.io/gitea/modules/structs" +) + +// ToRepo converts an ActionRun to api.ActionRun +func ToArtifact(ctx context.Context, artifact *models_actions.ActionArtifact) *api.ArtifactPayload { + return &api.ArtifactPayload{ + ArtifactID: artifact.ID, + ArtifactName: artifact.ArtifactName, + RunID: artifact.RunID, + } +} diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 5df7ec8fd609a..dc7844c61a0e1 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -253,6 +253,7 @@ type WebhookForm struct { Wiki bool Repository bool Package bool + WorkflowRun bool Active bool BranchFilter string `binding:"GlobPattern"` AuthorizationHeader string diff --git a/services/notify/notifier.go b/services/notify/notifier.go index ed053a812a6fd..7f7fee52c864d 100644 --- a/services/notify/notifier.go +++ b/services/notify/notifier.go @@ -6,6 +6,7 @@ package notify import ( "context" + actions_model "code.gitea.io/gitea/models/actions" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -74,4 +75,8 @@ type Notifier interface { PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) + + RequestedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) + StartedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) + CompletedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) } diff --git a/services/notify/notify.go b/services/notify/notify.go index 16fbb6325d0e9..d200adab61f22 100644 --- a/services/notify/notify.go +++ b/services/notify/notify.go @@ -6,6 +6,7 @@ package notify import ( "context" + actions_model "code.gitea.io/gitea/models/actions" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -367,3 +368,21 @@ func ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) { notifier.ChangeDefaultBranch(ctx, repo) } } + +func RequestedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + for _, notifier := range notifiers { + notifier.RequestedWorkflowRun(ctx, run) + } +} + +func StartedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + for _, notifier := range notifiers { + notifier.StartedWorkflowRun(ctx, run) + } +} + +func CompletedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + for _, notifier := range notifiers { + notifier.CompletedWorkflowRun(ctx, run) + } +} diff --git a/services/notify/null.go b/services/notify/null.go index dddd421bef926..363d04c0a7515 100644 --- a/services/notify/null.go +++ b/services/notify/null.go @@ -6,6 +6,7 @@ package notify import ( "context" + actions_model "code.gitea.io/gitea/models/actions" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" @@ -208,3 +209,12 @@ func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, p // ChangeDefaultBranch places a place holder function func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) { } + +func (*NullNotifier) RequestedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { +} + +func (*NullNotifier) StartedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { +} + +func (*NullNotifier) CompletedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { +} diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 1ab14fd6a7e32..f9c2ee2cc7681 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -6,6 +6,7 @@ package webhook import ( "context" + actions_model "code.gitea.io/gitea/models/actions" issues_model "code.gitea.io/gitea/models/issues" packages_model "code.gitea.io/gitea/models/packages" "code.gitea.io/gitea/models/perm" @@ -77,6 +78,15 @@ func (m *webhookNotifier) IssueClearLabels(ctx context.Context, doer *user_model } } +func repositoryPayloadHook(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, user *user_model.User, action api.HookRepoAction) error { + return PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ + Action: action, + Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), + Organization: convert.ToUser(ctx, user, nil), + Sender: convert.ToUser(ctx, doer, nil), + }) +} + func (m *webhookNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer) @@ -94,12 +104,7 @@ func (m *webhookNotifier) ForkRepository(ctx context.Context, doer *user_model.U // Add to hook queue for created repo after session commit. if u.IsOrganization() { - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ - Action: api.HookRepoCreated, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Organization: convert.ToUser(ctx, u, nil), - Sender: convert.ToUser(ctx, doer, nil), - }); err != nil { + if err := repositoryPayloadHook(ctx, doer, repo, u, api.HookRepoCreated); err != nil { log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) } } @@ -107,35 +112,21 @@ func (m *webhookNotifier) ForkRepository(ctx context.Context, doer *user_model.U func (m *webhookNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ - Action: api.HookRepoCreated, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Organization: convert.ToUser(ctx, u, nil), - Sender: convert.ToUser(ctx, doer, nil), - }); err != nil { + if err := repositoryPayloadHook(ctx, doer, repo, u, api.HookRepoCreated); err != nil { log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) } } func (m *webhookNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ - Action: api.HookRepoDeleted, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Organization: convert.ToUser(ctx, repo.MustOwner(ctx), nil), - Sender: convert.ToUser(ctx, doer, nil), - }); err != nil { + u := repo.MustOwner(ctx) + if err := repositoryPayloadHook(ctx, doer, repo, u, api.HookRepoDeleted); err != nil { log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) } } func (m *webhookNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ - Action: api.HookRepoCreated, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Organization: convert.ToUser(ctx, u, nil), - Sender: convert.ToUser(ctx, doer, nil), - }); err != nil { + if err := repositoryPayloadHook(ctx, doer, repo, u, api.HookRepoCreated); err != nil { log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) } } @@ -459,10 +450,9 @@ func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.Us } } -func (m *webhookNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { - // Add to hook queue for created wiki page. +func wikiPageNotifier(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string, action api.HookWikiAction) { if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ - Action: api.HookWikiCreated, + Action: action, Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), Sender: convert.ToUser(ctx, doer, nil), Page: page, @@ -472,29 +462,19 @@ func (m *webhookNotifier) NewWikiPage(ctx context.Context, doer *user_model.User } } +func (m *webhookNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { + // Add to hook queue for created wiki page. + wikiPageNotifier(ctx, doer, repo, page, comment, api.HookWikiCreated) +} + func (m *webhookNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { // Add to hook queue for edit wiki page. - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ - Action: api.HookWikiEdited, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Sender: convert.ToUser(ctx, doer, nil), - Page: page, - Comment: comment, - }); err != nil { - log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) - } + wikiPageNotifier(ctx, doer, repo, page, comment, api.HookWikiEdited) } func (m *webhookNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { - // Add to hook queue for edit wiki page. - if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ - Action: api.HookWikiDeleted, - Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), - Sender: convert.ToUser(ctx, doer, nil), - Page: page, - }); err != nil { - log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) - } + // Add to hook queue for delete wiki page. + wikiPageNotifier(ctx, doer, repo, page, "", api.HookWikiDeleted) } func (m *webhookNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, @@ -887,3 +867,39 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo log.Error("PrepareWebhooks: %v", err) } } + +func notifyWorkflowRun(ctx context.Context, doer *user_model.User, run *actions_model.ActionRun, action api.HookWorkflowRunAction) { + artifacts := []api.ArtifactPayload{} + if action == api.HookWorkflowRunCompleted { + as, err := actions_model.ListArtifactsByRunID(ctx, run.ID) + if err != nil { + log.Error("Failed to get run artifacts: %v", err) + } + + for _, artifact := range as { + artifacts = append(artifacts, *convert.ToArtifact(ctx, artifact)) + } + } + + if err := PrepareWebhooks(ctx, EventSource{Repository: run.Repo}, webhook_module.HookEventWorkflowRun, &api.WorkflowRunPayload{ + Action: action, + Repository: convert.ToRepo(ctx, run.Repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), + Sender: convert.ToUser(ctx, doer, nil), + ActionRun: convert.ToActionRun(ctx, run), + Artifacts: &artifacts, + }); err != nil { + log.Error("PrepareWebhooks: %v", err) + } +} + +func (m *webhookNotifier) RequestedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + notifyWorkflowRun(ctx, run.TriggerUser, run, api.HookWorkflowRunRequested) +} + +func (m *webhookNotifier) StartedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + notifyWorkflowRun(ctx, run.TriggerUser, run, api.HookWorkflowRunInProgress) +} + +func (m *webhookNotifier) CompletedWorkflowRun(ctx context.Context, run *actions_model.ActionRun) { + notifyWorkflowRun(ctx, run.TriggerUser, run, api.HookWorkflowRunCompleted) +} diff --git a/templates/repo/settings/webhook/settings.tmpl b/templates/repo/settings/webhook/settings.tmpl index addf99d45aec5..0c9c82b58fbbe 100644 --- a/templates/repo/settings/webhook/settings.tmpl +++ b/templates/repo/settings/webhook/settings.tmpl @@ -109,6 +109,17 @@ + +
+
+
+ + + {{ctx.Locale.Tr "repo.settings.event_workflow_run_desc"}} +
+
+
+