Skip to content

Commit 5987f00

Browse files
yp05327silverwindwxiaoguang
authored
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 ![image](https://user-images.githubusercontent.com/18380374/234736083-dea9b333-ec11-4095-a113-763f3716fba7.png) ![image](https://user-images.githubusercontent.com/18380374/234736107-d657d19c-f70a-42f4-985f-156a8c7efb7a.png) ![image](https://user-images.githubusercontent.com/18380374/234736160-9ad372df-7089-4d18-9bab-48bca3f01878.png) --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 18fc4f5 commit 5987f00

File tree

4 files changed

+54
-25
lines changed

4 files changed

+54
-25
lines changed

routers/web/repo/actions/view.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type ViewResponse struct {
5555
Status string `json:"status"`
5656
CanCancel bool `json:"canCancel"`
5757
CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
58+
CanRerun bool `json:"canRerun"`
5859
Done bool `json:"done"`
5960
Jobs []*ViewJob `json:"jobs"`
6061
Commit ViewCommit `json:"commit"`
@@ -136,6 +137,7 @@ func ViewPost(ctx *context_module.Context) {
136137
resp.State.Run.Link = run.Link()
137138
resp.State.Run.CanCancel = !run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions)
138139
resp.State.Run.CanApprove = run.NeedApproval && ctx.Repo.CanWrite(unit.TypeActions)
140+
resp.State.Run.CanRerun = run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions)
139141
resp.State.Run.Done = run.Status.IsDone()
140142
resp.State.Run.Jobs = make([]*ViewJob, 0, len(jobs)) // marshal to '[]' instead fo 'null' in json
141143
resp.State.Run.Status = run.Status.String()
@@ -238,18 +240,45 @@ func ViewPost(ctx *context_module.Context) {
238240
ctx.JSON(http.StatusOK, resp)
239241
}
240242

241-
func Rerun(ctx *context_module.Context) {
243+
func RerunOne(ctx *context_module.Context) {
242244
runIndex := ctx.ParamsInt64("run")
243245
jobIndex := ctx.ParamsInt64("job")
244246

245247
job, _ := getRunJobs(ctx, runIndex, jobIndex)
246248
if ctx.Written() {
247249
return
248250
}
251+
252+
if err := rerunJob(ctx, job); err != nil {
253+
ctx.Error(http.StatusInternalServerError, err.Error())
254+
return
255+
}
256+
257+
ctx.JSON(http.StatusOK, struct{}{})
258+
}
259+
260+
func RerunAll(ctx *context_module.Context) {
261+
runIndex := ctx.ParamsInt64("run")
262+
263+
_, jobs := getRunJobs(ctx, runIndex, 0)
264+
if ctx.Written() {
265+
return
266+
}
267+
268+
for _, j := range jobs {
269+
if err := rerunJob(ctx, j); err != nil {
270+
ctx.Error(http.StatusInternalServerError, err.Error())
271+
return
272+
}
273+
}
274+
275+
ctx.JSON(http.StatusOK, struct{}{})
276+
}
277+
278+
func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) error {
249279
status := job.Status
250280
if !status.IsDone() {
251-
ctx.JSON(http.StatusOK, struct{}{})
252-
return
281+
return nil
253282
}
254283

255284
job.TaskID = 0
@@ -261,13 +290,11 @@ func Rerun(ctx *context_module.Context) {
261290
_, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped")
262291
return err
263292
}); err != nil {
264-
ctx.Error(http.StatusInternalServerError, err.Error())
265-
return
293+
return err
266294
}
267295

268296
actions_service.CreateCommitStatus(ctx, job)
269-
270-
ctx.JSON(http.StatusOK, struct{}{})
297+
return nil
271298
}
272299

273300
func Cancel(ctx *context_module.Context) {

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,10 +1186,11 @@ func registerRoutes(m *web.Route) {
11861186
m.Combo("").
11871187
Get(actions.View).
11881188
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
1189-
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
1189+
m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne)
11901190
})
11911191
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
11921192
m.Post("/approve", reqRepoActionsWriter, actions.Approve)
1193+
m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll)
11931194
})
11941195
}, reqRepoActionsReader, actions.MustEnableActions)
11951196

web_src/js/components/RepoActionView.vue

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
<div class="action-title">
77
{{ run.title }}
88
</div>
9-
<button class="run_approve" @click="approveRun()" v-if="run.canApprove">
10-
<i class="play circle outline icon"/>
9+
<button class="action-control-button text green" @click="approveRun()" v-if="run.canApprove">
10+
<SvgIcon name="octicon-play" :size="20"/>
1111
</button>
12-
<button class="run_cancel" @click="cancelRun()" v-else-if="run.canCancel">
13-
<i class="stop circle outline icon"/>
12+
<button class="action-control-button text red" @click="cancelRun()" v-else-if="run.canCancel">
13+
<SvgIcon name="octicon-x-circle-fill" :size="20"/>
14+
</button>
15+
<button class="action-control-button text green" @click="rerun()" v-else-if="run.canRerun">
16+
<SvgIcon name="octicon-sync" :size="20"/>
1417
</button>
1518
</div>
1619
<div class="action-commit-summary">
@@ -106,6 +109,7 @@ const sfc = {
106109
status: '',
107110
canCancel: false,
108111
canApprove: false,
112+
canRerun: false,
109113
done: false,
110114
jobs: [
111115
// {
@@ -193,6 +197,11 @@ const sfc = {
193197
await this.fetchPost(`${jobLink}/rerun`);
194198
window.location.href = jobLink;
195199
},
200+
// rerun workflow
201+
async rerun() {
202+
await this.fetchPost(`${this.run.link}/rerun`);
203+
window.location.href = this.run.link;
204+
},
196205
// cancel a run
197206
cancelRun() {
198207
this.fetchPost(`${this.run.link}/cancel`);
@@ -366,26 +375,16 @@ export function ansiLogToHTML(line) {
366375
margin: 0 20px 20px 20px;
367376
}
368377
369-
.action-view-header .run_cancel {
370-
border: none;
371-
color: var(--color-red);
372-
background-color: transparent;
373-
outline: none;
374-
cursor: pointer;
375-
transition: transform 0.2s;
376-
}
377-
378-
.action-view-header .run_approve {
378+
.action-view-header .action-control-button {
379379
border: none;
380-
color: var(--color-green);
381380
background-color: transparent;
382381
outline: none;
383382
cursor: pointer;
384383
transition: transform 0.2s;
384+
display: flex;
385385
}
386386
387-
.action-view-header .run_cancel:hover,
388-
.action-view-header .run_approve:hover {
387+
.action-view-header .action-control-button:hover {
389388
transform: scale(130%);
390389
}
391390

web_src/js/svg.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import octiconLink from '../../public/img/svg/octicon-link.svg';
1818
import octiconLock from '../../public/img/svg/octicon-lock.svg';
1919
import octiconMilestone from '../../public/img/svg/octicon-milestone.svg';
2020
import octiconMirror from '../../public/img/svg/octicon-mirror.svg';
21+
import octiconPlay from '../../public/img/svg/octicon-play.svg';
2122
import octiconProject from '../../public/img/svg/octicon-project.svg';
2223
import octiconRepo from '../../public/img/svg/octicon-repo.svg';
2324
import octiconRepoForked from '../../public/img/svg/octicon-repo-forked.svg';
@@ -79,6 +80,7 @@ const svgs = {
7980
'octicon-milestone': octiconMilestone,
8081
'octicon-mirror': octiconMirror,
8182
'octicon-organization': octiconOrganization,
83+
'octicon-play': octiconPlay,
8284
'octicon-plus': octiconPlus,
8385
'octicon-project': octiconProject,
8486
'octicon-repo': octiconRepo,

0 commit comments

Comments
 (0)