mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 17:05:45 +02:00
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:
parent
ab8bab918a
commit
618f044d4e
@ -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"`
|
||||
|
@ -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 {
|
||||
|
@ -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{}{})
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user