mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add rerun workflow button and refactor to use SVG octicons (#24350)
Changes: - Add rerun workflow button. Then users can rerun the whole workflow by only one-click. - Refactor to use SVG octicons in RepoActionView.vue    --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -55,6 +55,7 @@ type ViewResponse struct {
 | 
			
		||||
			Status     string     `json:"status"`
 | 
			
		||||
			CanCancel  bool       `json:"canCancel"`
 | 
			
		||||
			CanApprove bool       `json:"canApprove"` // the run needs an approval and the doer has permission to approve
 | 
			
		||||
			CanRerun   bool       `json:"canRerun"`
 | 
			
		||||
			Done       bool       `json:"done"`
 | 
			
		||||
			Jobs       []*ViewJob `json:"jobs"`
 | 
			
		||||
			Commit     ViewCommit `json:"commit"`
 | 
			
		||||
@@ -136,6 +137,7 @@ func ViewPost(ctx *context_module.Context) {
 | 
			
		||||
	resp.State.Run.Link = run.Link()
 | 
			
		||||
	resp.State.Run.CanCancel = !run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions)
 | 
			
		||||
	resp.State.Run.CanApprove = run.NeedApproval && ctx.Repo.CanWrite(unit.TypeActions)
 | 
			
		||||
	resp.State.Run.CanRerun = run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions)
 | 
			
		||||
	resp.State.Run.Done = run.Status.IsDone()
 | 
			
		||||
	resp.State.Run.Jobs = make([]*ViewJob, 0, len(jobs)) // marshal to '[]' instead fo 'null' in json
 | 
			
		||||
	resp.State.Run.Status = run.Status.String()
 | 
			
		||||
@@ -238,7 +240,7 @@ func ViewPost(ctx *context_module.Context) {
 | 
			
		||||
	ctx.JSON(http.StatusOK, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Rerun(ctx *context_module.Context) {
 | 
			
		||||
func RerunOne(ctx *context_module.Context) {
 | 
			
		||||
	runIndex := ctx.ParamsInt64("run")
 | 
			
		||||
	jobIndex := ctx.ParamsInt64("job")
 | 
			
		||||
 | 
			
		||||
@@ -246,10 +248,37 @@ func Rerun(ctx *context_module.Context) {
 | 
			
		||||
	if ctx.Written() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := rerunJob(ctx, job); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.JSON(http.StatusOK, struct{}{})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RerunAll(ctx *context_module.Context) {
 | 
			
		||||
	runIndex := ctx.ParamsInt64("run")
 | 
			
		||||
 | 
			
		||||
	_, jobs := getRunJobs(ctx, runIndex, 0)
 | 
			
		||||
	if ctx.Written() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, j := range jobs {
 | 
			
		||||
		if err := rerunJob(ctx, j); err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, err.Error())
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.JSON(http.StatusOK, struct{}{})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) error {
 | 
			
		||||
	status := job.Status
 | 
			
		||||
	if !status.IsDone() {
 | 
			
		||||
		ctx.JSON(http.StatusOK, struct{}{})
 | 
			
		||||
		return
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	job.TaskID = 0
 | 
			
		||||
@@ -261,13 +290,11 @@ func Rerun(ctx *context_module.Context) {
 | 
			
		||||
		_, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped")
 | 
			
		||||
		return err
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, err.Error())
 | 
			
		||||
		return
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	actions_service.CreateCommitStatus(ctx, job)
 | 
			
		||||
 | 
			
		||||
	ctx.JSON(http.StatusOK, struct{}{})
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Cancel(ctx *context_module.Context) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user