Check disabled workflow when rerun jobs (#26535)
In GitHub, we can not rerun jobs if the workflow is disabled. --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
b3f7137174
commit
a4a567f29f
7 changed files with 77 additions and 101 deletions
|
@ -259,31 +259,35 @@ func ViewPost(ctx *context_module.Context) {
|
|||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func RerunOne(ctx *context_module.Context) {
|
||||
// Rerun will rerun jobs in the given run
|
||||
// jobIndex = 0 means rerun all jobs
|
||||
func Rerun(ctx *context_module.Context) {
|
||||
runIndex := ctx.ParamsInt64("run")
|
||||
jobIndex := ctx.ParamsInt64("job")
|
||||
|
||||
job, _ := getRunJobs(ctx, runIndex, jobIndex)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if err := rerunJob(ctx, job); err != nil {
|
||||
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, struct{}{})
|
||||
}
|
||||
// can not rerun job when workflow is disabled
|
||||
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
|
||||
cfg := cfgUnit.ActionsConfig()
|
||||
if cfg.IsWorkflowDisabled(run.WorkflowID) {
|
||||
ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled"))
|
||||
return
|
||||
}
|
||||
|
||||
func RerunAll(ctx *context_module.Context) {
|
||||
runIndex := ctx.ParamsInt64("run")
|
||||
|
||||
_, jobs := getRunJobs(ctx, runIndex, 0)
|
||||
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if jobIndex != 0 {
|
||||
jobs = []*actions_model.ActionRunJob{job}
|
||||
}
|
||||
|
||||
for _, j := range jobs {
|
||||
if err := rerunJob(ctx, j); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
|
|
|
@ -1211,14 +1211,14 @@ func registerRoutes(m *web.Route) {
|
|||
m.Combo("").
|
||||
Get(actions.View).
|
||||
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
|
||||
m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne)
|
||||
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
|
||||
m.Get("/logs", actions.Logs)
|
||||
})
|
||||
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
|
||||
m.Post("/approve", reqRepoActionsWriter, actions.Approve)
|
||||
m.Post("/artifacts", actions.ArtifactsView)
|
||||
m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView)
|
||||
m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll)
|
||||
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
|
||||
})
|
||||
}, reqRepoActionsReader, actions.MustEnableActions)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue