Rename notifier to WorkflowJobStatusUpdate

* add URL field
* add HTMLURL field
* fix run_url to return api url instead of html url
This commit is contained in:
Christopher Homberger 2025-02-25 12:25:36 +01:00
parent ab8bab918a
commit 618f044d4e
13 changed files with 39 additions and 19 deletions

View File

@ -112,6 +112,8 @@ type ActionWorkflowStep struct {
// ActionWorkflowJob represents a WorkflowJob
type ActionWorkflowJob struct {
ID int64 `json:"id"`
URL string `json:"url"`
HtmlURL string `json:"html_url"`
RunID int64 `json:"run_id"`
RunURL string `json:"run_url"`
Name string `json:"name"`

View File

@ -221,7 +221,7 @@ func (s *Service) UpdateTask(
}
if task.Status.IsDone() {
notifier.CreateWorkflowJob(ctx, task.Job.Run.Repo, task.Job.Run.TriggerUser, task.Job, task)
notifier.WorkflowJobStatusUpdate(ctx, task.Job.Run.Repo, task.Job.Run.TriggerUser, task.Job, task)
}
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {

View File

@ -460,7 +460,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
actions_service.CreateCommitStatus(ctx, job)
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
return nil
}
@ -559,7 +559,7 @@ func Cancel(ctx *context_module.Context) {
for _, job := range updatedjobs {
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
}
ctx.JSON(http.StatusOK, struct{}{})
@ -605,7 +605,7 @@ func Approve(ctx *context_module.Context) {
for _, job := range updatedjobs {
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
}
ctx.JSON(http.StatusOK, struct{}{})

View File

@ -71,7 +71,7 @@ func stopTasks(ctx context.Context, opts actions_model.FindTaskOptions) error {
CreateCommitStatus(ctx, jobs...)
for _, job := range jobs {
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
}
return nil
}
@ -103,7 +103,7 @@ func CancelAbandonedJobs(ctx context.Context) error {
CreateCommitStatus(ctx, job)
if updated {
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
}
}

View File

@ -76,7 +76,7 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
CreateCommitStatus(ctx, jobs...)
for _, job := range updatedjobs {
_ = job.LoadAttributes(ctx)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
}
return nil
}

View File

@ -365,7 +365,7 @@ func handleWorkflows(
}
CreateCommitStatus(ctx, alljobs...)
for _, job := range alljobs {
notifier.CreateWorkflowJob(ctx, input.Repo, input.Doer, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, input.Repo, input.Doer, job, nil)
}
}
return nil

View File

@ -158,7 +158,7 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
log.Error("LoadAttributes: %v", err)
}
for _, job := range allJobs {
notifier.CreateWorkflowJob(ctx, run.Repo, run.TriggerUser, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, run.Repo, run.TriggerUser, job, nil)
}
// Return nil if no errors occurred

View File

@ -77,7 +77,7 @@ func PickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
}
CreateCommitStatus(ctx, job)
notifier.CreateWorkflowJob(ctx, job.Run.Repo, job.Run.TriggerUser, job, actionTask)
notifier.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, actionTask)
return task, true, nil
}

View File

@ -278,7 +278,7 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
}
CreateCommitStatus(ctx, allJobs...)
for _, job := range allJobs {
notifier.CreateWorkflowJob(ctx, repo, doer, job, nil)
notifier.WorkflowJobStatusUpdate(ctx, repo, doer, job, nil)
}
return nil

View File

@ -79,5 +79,5 @@ type Notifier interface {
CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus)
CreateWorkflowJob(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)
}

View File

@ -376,8 +376,8 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit
}
}
func CreateWorkflowJob(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 {
notifier.CreateWorkflowJob(ctx, repo, sender, job, task)
notifier.WorkflowJobStatusUpdate(ctx, repo, sender, job, task)
}
}

View File

@ -214,5 +214,5 @@ 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) CreateWorkflowJob(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) {
}

View File

@ -5,6 +5,7 @@ package webhook
import (
"context"
"fmt"
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
@ -944,7 +945,7 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
}
}
func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
func (*webhookNotifier) WorkflowJobStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, job *actions_model.ActionRunJob, task *actions_model.ActionTask) {
source := EventSource{
Repository: repo,
Owner: repo.Owner,
@ -961,6 +962,19 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.
return
}
jobIndex := 0
jobs, err := actions_model.GetRunJobsByRunID(ctx, job.RunID)
if err != nil {
log.Error("Error loading getting run jobs: %v", err)
return
}
for i, j := range jobs {
if j.ID == job.ID {
jobIndex = i
break
}
}
status, conclusion := toActionStatus(job.Status)
var runnerID int64
var runnerName string
@ -987,9 +1001,13 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.
if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowJobPayload{
Action: status,
WorkflowJob: &api.ActionWorkflowJob{
ID: job.ID,
RunID: job.RunID,
RunURL: job.Run.HTMLURL(),
ID: job.ID,
// missing api endpoint for this location
URL: fmt.Sprintf("%s/actions/runs/%d/jobs/%d", repo.APIURL(), job.RunID, job.ID),
HtmlURL: fmt.Sprintf("%s/jobs/%d", job.Run.HTMLURL(), jobIndex),
RunID: job.RunID,
// Missing api endpoint for this location, artifacts are available under a nested url
RunURL: fmt.Sprintf("%s/actions/runs/%d", repo.APIURL(), job.RunID),
Name: job.Name,
Labels: job.RunsOn,
RunAttempt: job.Attempt,