Skip to content

Add rerun workflow button and refactor to use SVG octicons #24350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -242,30 +244,40 @@ func Rerun(ctx *context_module.Context) {
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")

job, _ := getRunJobs(ctx, runIndex, jobIndex)
targetJob, allJobs := getRunJobs(ctx, runIndex, jobIndex)
if ctx.Written() {
return
}
status := job.Status
if !status.IsDone() {
ctx.JSON(http.StatusOK, struct{}{})
return

var rerunJobs []*actions_model.ActionRunJob
if jobIndex < 0 {
rerunJobs = allJobs
} else {
rerunJobs = append(rerunJobs, targetJob)
}

job.TaskID = 0
job.Status = actions_model.StatusWaiting
job.Started = 0
job.Stopped = 0
for _, job := range rerunJobs {
status := job.Status
if !status.IsDone() {
ctx.JSON(http.StatusOK, struct{}{})
return
}

if err := db.WithTx(ctx, func(ctx context.Context) error {
_, 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
}
job.TaskID = 0
job.Status = actions_model.StatusWaiting
job.Started = 0
job.Stopped = 0

actions_service.CreateCommitStatus(ctx, job)
if err := db.WithTx(ctx, func(ctx context.Context) error {
_, 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
}

actions_service.CreateCommitStatus(ctx, job)
}

ctx.JSON(http.StatusOK, struct{}{})
}
Expand Down
33 changes: 16 additions & 17 deletions web_src/js/components/RepoActionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
<div class="action-title">
{{ run.title }}
</div>
<button class="run_approve" @click="approveRun()" v-if="run.canApprove">
<i class="play circle outline icon"/>
<button class="action-control-button text green" @click="approveRun()" v-if="run.canApprove">
<SvgIcon name="octicon-play" :size="20"/>
</button>
<button class="run_cancel" @click="cancelRun()" v-else-if="run.canCancel">
<i class="stop circle outline icon"/>
<button class="action-control-button text red" @click="cancelRun()" v-else-if="run.canCancel">
<SvgIcon name="octicon-x-circle-fill" :size="20"/>
</button>
<button class="action-control-button text green" @click="rerun()" v-else-if="run.canRerun">
<SvgIcon name="octicon-sync" :size="20"/>
</button>
</div>
<div class="action-commit-summary">
Expand Down Expand Up @@ -106,6 +109,7 @@ const sfc = {
status: '',
canCancel: false,
canApprove: false,
canRerun: false,
done: false,
jobs: [
// {
Expand Down Expand Up @@ -193,6 +197,11 @@ const sfc = {
await this.fetchPost(`${jobLink}/rerun`);
window.location.href = jobLink;
},
// rerun workflow
rerun() {
this.fetchPost(`${this.run.link}/jobs/-1/rerun`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0 already used? If no, I guess 0 seems better. If yes, I'd like to use /job/current/rerun.

The -1 is used for "undefined" in many places.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, 0 is alredy used. Why not ${this.run.link}/rerun?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wolfogre
if use this link, jobindex will be 0, it is same to the event of ‘rerun the first job of this workflow’

@wxiaoguang
It is defined as job index, 0 means the first job of this workflow.
There are two inputs, run index and job index, i don’t know why use index instead of id.
if job index is -1, it means this input is undefined, we will get only one valid input.
Then gitea will rerun all jobs.
maybe use id instead of index is the best way to fix this problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may misunderstood, I mean ${this.run.link}/rerun, not ${jobLink}/rerun

Copy link
Contributor Author

@yp05327 yp05327 Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
runIndex is as same as Id, but it is not global ActionRun.Id, it is an runId belongs to a repo.
But jobIndex is actually the index of the job list:

if jobIndex >= 0 && jobIndex < int64(len(jobs)) {
return jobs[jobIndex], jobs
}
return jobs[0], jobs

Maybe use global ActionRunJob.Id instead of jobIndex is better? It starts at 1, then we can use 0.
Or any other advises?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert into ${this.run.link}/rerun now. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this resolved?

window.location.href = `${this.run.link}`;
},
// cancel a run
cancelRun() {
this.fetchPost(`${this.run.link}/cancel`);
Expand Down Expand Up @@ -366,26 +375,16 @@ export function ansiLogToHTML(line) {
margin: 0 20px 20px 20px;
}

.action-view-header .run_cancel {
border: none;
color: var(--color-red);
background-color: transparent;
outline: none;
cursor: pointer;
transition: transform 0.2s;
}

.action-view-header .run_approve {
.action-view-header .action-control-button {
border: none;
color: var(--color-green);
background-color: transparent;
outline: none;
cursor: pointer;
transition: transform 0.2s;
display: flex;
}

.action-view-header .run_cancel:hover,
.action-view-header .run_approve:hover {
.action-view-header .action-control-button:hover {
transform: scale(130%);
}

Expand Down
2 changes: 2 additions & 0 deletions web_src/js/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import octiconLock from '../../public/img/svg/octicon-lock.svg';
import octiconMilestone from '../../public/img/svg/octicon-milestone.svg';
import octiconMirror from '../../public/img/svg/octicon-mirror.svg';
import octiconProject from '../../public/img/svg/octicon-project.svg';
import octiconPlay from '../../public/img/svg/octicon-play.svg';
import octiconRepo from '../../public/img/svg/octicon-repo.svg';
import octiconRepoForked from '../../public/img/svg/octicon-repo-forked.svg';
import octiconRepoTemplate from '../../public/img/svg/octicon-repo-template.svg';
Expand Down Expand Up @@ -69,6 +70,7 @@ const svgs = {
'octicon-milestone': octiconMilestone,
'octicon-mirror': octiconMirror,
'octicon-project': octiconProject,
'octicon-play': octiconPlay,
'octicon-repo': octiconRepo,
'octicon-repo-forked': octiconRepoForked,
'octicon-repo-template': octiconRepoTemplate,
Expand Down