mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-17 05:05:24 +02:00
wip event
This commit is contained in:
parent
cb6b33c9cd
commit
edb24592fc
@ -470,6 +470,22 @@ func (p *CommitStatusPayload) JSONPayload() ([]byte, error) {
|
|||||||
return json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WorkflowRunPayload represents a payload information of workflow run event.
|
||||||
|
type WorkflowRunPayload struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Workflow *ActionWorkflow `json:"workflow"`
|
||||||
|
WorkflowRun *ActionWorkflowRun `json:"workflow_run"`
|
||||||
|
PullRequest *PullRequest `json:"pull_request,omitempty"`
|
||||||
|
Organization *Organization `json:"organization,omitempty"`
|
||||||
|
Repo *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload implements Payload
|
||||||
|
func (p *WorkflowRunPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
// WorkflowJobPayload represents a payload information of workflow job event.
|
// WorkflowJobPayload represents a payload information of workflow job event.
|
||||||
type WorkflowJobPayload struct {
|
type WorkflowJobPayload struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
|
@ -87,8 +87,20 @@ type ActionArtifact struct {
|
|||||||
// ActionWorkflowRun represents a WorkflowRun
|
// ActionWorkflowRun represents a WorkflowRun
|
||||||
type ActionWorkflowRun struct {
|
type ActionWorkflowRun struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
Event string `json:"event"`
|
||||||
|
RunAttempt int64 `json:"run_attempt"`
|
||||||
|
RunNumber int64 `json:"run_number"`
|
||||||
RepositoryID int64 `json:"repository_id"`
|
RepositoryID int64 `json:"repository_id"`
|
||||||
HeadSha string `json:"head_sha"`
|
HeadSha string `json:"head_sha"`
|
||||||
|
HeadBranch string `json:"head_branch,omitempty"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Conclusion string `json:"conclusion,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
StartedAt time.Time `json:"started_at,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
CompletedAt time.Time `json:"completed_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionArtifactsResponse returns ActionArtifacts
|
// ActionArtifactsResponse returns ActionArtifacts
|
||||||
|
@ -38,6 +38,7 @@ const (
|
|||||||
HookEventPullRequestReview HookEventType = "pull_request_review"
|
HookEventPullRequestReview HookEventType = "pull_request_review"
|
||||||
// Actions event only
|
// Actions event only
|
||||||
HookEventSchedule HookEventType = "schedule"
|
HookEventSchedule HookEventType = "schedule"
|
||||||
|
HookEventWorkflowRun HookEventType = "workflow_run"
|
||||||
HookEventWorkflowJob HookEventType = "workflow_job"
|
HookEventWorkflowJob HookEventType = "workflow_job"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -125,6 +125,9 @@ func CancelAbandonedJobs(ctx context.Context) error {
|
|||||||
if updated {
|
if updated {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = job.LoadAttributes(ctx)
|
||||||
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
|
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
|
||||||
|
if job.Run != nil {
|
||||||
|
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ package actions
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
packages_model "code.gitea.io/gitea/models/packages"
|
packages_model "code.gitea.io/gitea/models/packages"
|
||||||
perm_model "code.gitea.io/gitea/models/perm"
|
perm_model "code.gitea.io/gitea/models/perm"
|
||||||
@ -762,3 +763,13 @@ func (n *actionsNotifier) MigrateRepository(ctx context.Context, doer, u *user_m
|
|||||||
Sender: convert.ToUser(ctx, doer, nil),
|
Sender: convert.ToUser(ctx, doer, nil),
|
||||||
}).Notify(ctx)
|
}).Notify(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *actionsNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) {
|
||||||
|
run.Status.IsBlocked()
|
||||||
|
newNotifyInput(repo, sender, webhook_module.HookEventWorkflowRun).WithPayload(&api.WorkflowRunPayload{
|
||||||
|
Action: "queued",
|
||||||
|
Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeOwner}),
|
||||||
|
Organization: nil,
|
||||||
|
Sender: convert.ToUser(ctx, sender, nil),
|
||||||
|
}).Notify(ctx)
|
||||||
|
}
|
||||||
|
@ -79,5 +79,7 @@ type Notifier interface {
|
|||||||
|
|
||||||
CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus)
|
CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus)
|
||||||
|
|
||||||
|
WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun)
|
||||||
|
|
||||||
WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask)
|
WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask)
|
||||||
}
|
}
|
||||||
|
@ -376,6 +376,12 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.WorkflowRunStatusUpdate(ctx, repo, sender, run)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
|
func WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
|
||||||
for _, notifier := range notifiers {
|
for _, notifier := range notifiers {
|
||||||
notifier.WorkflowJobStatusUpdate(ctx, repo, sender, job, task)
|
notifier.WorkflowJobStatusUpdate(ctx, repo, sender, job, task)
|
||||||
|
@ -214,5 +214,8 @@ func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.R
|
|||||||
func (*NullNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) {
|
func (*NullNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*NullNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) {
|
||||||
|
}
|
||||||
|
|
||||||
func (*NullNotifier) WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
|
func (*NullNotifier) WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
|
||||||
}
|
}
|
||||||
|
@ -1030,6 +1030,45 @@ func (*webhookNotifier) WorkflowJobStatusUpdate(ctx context.Context, repo *repo_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*webhookNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) {
|
||||||
|
source := EventSource{
|
||||||
|
Repository: repo,
|
||||||
|
Owner: repo.Owner,
|
||||||
|
}
|
||||||
|
|
||||||
|
var org *api.Organization
|
||||||
|
if repo.Owner.IsOrganization() {
|
||||||
|
org = convert.ToOrganization(ctx, organization.OrgFromUser(repo.Owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
status, conclusion := toActionStatus(run.Status)
|
||||||
|
|
||||||
|
if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowRunPayload{
|
||||||
|
Action: status,
|
||||||
|
Workflow: nil,
|
||||||
|
WorkflowRun: &api.ActionWorkflowRun{
|
||||||
|
ID: run.ID,
|
||||||
|
RunNumber: run.Index,
|
||||||
|
HTMLURL: run.HTMLURL(),
|
||||||
|
// Missing api endpoint for this location, artifacts are available under a nested url
|
||||||
|
URL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(), run.ID),
|
||||||
|
Event: run.TriggerEvent,
|
||||||
|
RunAttempt: 0,
|
||||||
|
HeadSha: run.CommitSHA,
|
||||||
|
HeadBranch: git.RefName(run.Ref).BranchName(),
|
||||||
|
Status: status,
|
||||||
|
Conclusion: conclusion,
|
||||||
|
StartedAt: run.Started.AsTime().UTC(),
|
||||||
|
CompletedAt: run.Stopped.AsTime().UTC(),
|
||||||
|
},
|
||||||
|
Organization: org,
|
||||||
|
Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}),
|
||||||
|
Sender: convert.ToUser(ctx, sender, nil),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error("PrepareWebhooks: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func toActionStatus(status actions_model.Status) (string, string) {
|
func toActionStatus(status actions_model.Status) (string, string) {
|
||||||
var action string
|
var action string
|
||||||
var conclusion string
|
var conclusion string
|
||||||
|
@ -264,6 +264,15 @@
|
|||||||
<label>{{ctx.Locale.Tr "repo.settings.event_header_workflow"}}</label>
|
<label>{{ctx.Locale.Tr "repo.settings.event_header_workflow"}}</label>
|
||||||
</div>
|
</div>
|
||||||
<!-- Workflow Job Event -->
|
<!-- Workflow Job Event -->
|
||||||
|
<div class="seven wide column">
|
||||||
|
<div class="field">
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<input name="workflow_run" type="checkbox" {{if .Webhook.HookEvents.Get "workflow_run"}}checked{{end}}>
|
||||||
|
<label>{{ctx.Locale.Tr "repo.settings.event_workflow_run"}}</label>
|
||||||
|
<span class="help">{{ctx.Locale.Tr "repo.settings.event_workflow_run_desc"}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="seven wide column">
|
<div class="seven wide column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui checkbox">
|
<div class="ui checkbox">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user