mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-23 13:55:53 +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
|
// ActionWorkflowJob represents a WorkflowJob
|
||||||
type ActionWorkflowJob struct {
|
type ActionWorkflowJob struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HtmlURL string `json:"html_url"`
|
||||||
RunID int64 `json:"run_id"`
|
RunID int64 `json:"run_id"`
|
||||||
RunURL string `json:"run_url"`
|
RunURL string `json:"run_url"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -221,7 +221,7 @@ func (s *Service) UpdateTask(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if task.Status.IsDone() {
|
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 {
|
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)
|
actions_service.CreateCommitStatus(ctx, job)
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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
|
return nil
|
||||||
}
|
}
|
||||||
@ -559,7 +559,7 @@ func Cancel(ctx *context_module.Context) {
|
|||||||
|
|
||||||
for _, job := range updatedjobs {
|
for _, job := range updatedjobs {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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{}{})
|
ctx.JSON(http.StatusOK, struct{}{})
|
||||||
@ -605,7 +605,7 @@ func Approve(ctx *context_module.Context) {
|
|||||||
|
|
||||||
for _, job := range updatedjobs {
|
for _, job := range updatedjobs {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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{}{})
|
ctx.JSON(http.StatusOK, struct{}{})
|
||||||
|
@ -71,7 +71,7 @@ func stopTasks(ctx context.Context, opts actions_model.FindTaskOptions) error {
|
|||||||
CreateCommitStatus(ctx, jobs...)
|
CreateCommitStatus(ctx, jobs...)
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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
|
return nil
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ func CancelAbandonedJobs(ctx context.Context) error {
|
|||||||
CreateCommitStatus(ctx, job)
|
CreateCommitStatus(ctx, job)
|
||||||
if updated {
|
if updated {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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...)
|
CreateCommitStatus(ctx, jobs...)
|
||||||
for _, job := range updatedjobs {
|
for _, job := range updatedjobs {
|
||||||
_ = job.LoadAttributes(ctx)
|
_ = 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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ func handleWorkflows(
|
|||||||
}
|
}
|
||||||
CreateCommitStatus(ctx, alljobs...)
|
CreateCommitStatus(ctx, alljobs...)
|
||||||
for _, job := range 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
|
return nil
|
||||||
|
@ -158,7 +158,7 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
|
|||||||
log.Error("LoadAttributes: %v", err)
|
log.Error("LoadAttributes: %v", err)
|
||||||
}
|
}
|
||||||
for _, job := range allJobs {
|
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
|
// Return nil if no errors occurred
|
||||||
|
@ -77,7 +77,7 @@ func PickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
|
|||||||
}
|
}
|
||||||
|
|
||||||
CreateCommitStatus(ctx, job)
|
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
|
return task, true, nil
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
|
|||||||
}
|
}
|
||||||
CreateCommitStatus(ctx, allJobs...)
|
CreateCommitStatus(ctx, allJobs...)
|
||||||
for _, job := range allJobs {
|
for _, job := range allJobs {
|
||||||
notifier.CreateWorkflowJob(ctx, repo, doer, job, nil)
|
notifier.WorkflowJobStatusUpdate(ctx, repo, doer, job, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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)
|
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 {
|
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) 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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"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{
|
source := EventSource{
|
||||||
Repository: repo,
|
Repository: repo,
|
||||||
Owner: repo.Owner,
|
Owner: repo.Owner,
|
||||||
@ -961,6 +962,19 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.
|
|||||||
return
|
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)
|
status, conclusion := toActionStatus(job.Status)
|
||||||
var runnerID int64
|
var runnerID int64
|
||||||
var runnerName string
|
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{
|
if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowJobPayload{
|
||||||
Action: status,
|
Action: status,
|
||||||
WorkflowJob: &api.ActionWorkflowJob{
|
WorkflowJob: &api.ActionWorkflowJob{
|
||||||
ID: job.ID,
|
ID: job.ID,
|
||||||
RunID: job.RunID,
|
// missing api endpoint for this location
|
||||||
RunURL: job.Run.HTMLURL(),
|
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,
|
Name: job.Name,
|
||||||
Labels: job.RunsOn,
|
Labels: job.RunsOn,
|
||||||
RunAttempt: job.Attempt,
|
RunAttempt: job.Attempt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user