Skip to content

Commit 555d64d

Browse files
authored
Always show the "rerun" button for action jobs (#33692)
And improve the mock code.
1 parent adf7018 commit 555d64d

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

routers/web/devtest/mock_actions.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ func generateMockStepsLog(logCur actions.LogCursor) (stepsLog []*actions.ViewSte
5252
return stepsLog
5353
}
5454

55+
func MockActionsView(ctx *context.Context) {
56+
ctx.Data["RunID"] = ctx.PathParam("run")
57+
ctx.Data["JobID"] = ctx.PathParam("job")
58+
ctx.HTML(http.StatusOK, "devtest/repo-action-view")
59+
}
60+
5561
func MockActionsRunsJobs(ctx *context.Context) {
56-
req := web.GetForm(ctx).(*actions.ViewRequest)
62+
runID := ctx.PathParamInt64("run")
5763

64+
req := web.GetForm(ctx).(*actions.ViewRequest)
5865
resp := &actions.ViewResponse{}
5966
resp.State.Run.TitleHTML = `mock run title <a href="/">link</a>`
6067
resp.State.Run.Status = actions_model.StatusRunning.String()
61-
resp.State.Run.CanCancel = true
68+
resp.State.Run.CanCancel = runID == 10
69+
resp.State.Run.CanApprove = runID == 20
70+
resp.State.Run.CanRerun = runID == 30
6271
resp.State.Run.CanDeleteArtifact = true
6372
resp.State.Run.WorkflowID = "workflow-id"
6473
resp.State.Run.WorkflowLink = "./workflow-link"
@@ -85,6 +94,29 @@ func MockActionsRunsJobs(ctx *context.Context) {
8594
Size: 1024 * 1024,
8695
Status: "completed",
8796
})
97+
98+
resp.State.Run.Jobs = append(resp.State.Run.Jobs, &actions.ViewJob{
99+
ID: runID * 10,
100+
Name: "job 100",
101+
Status: actions_model.StatusRunning.String(),
102+
CanRerun: true,
103+
Duration: "1h",
104+
})
105+
resp.State.Run.Jobs = append(resp.State.Run.Jobs, &actions.ViewJob{
106+
ID: runID*10 + 1,
107+
Name: "job 101",
108+
Status: actions_model.StatusWaiting.String(),
109+
CanRerun: false,
110+
Duration: "2h",
111+
})
112+
resp.State.Run.Jobs = append(resp.State.Run.Jobs, &actions.ViewJob{
113+
ID: runID*10 + 2,
114+
Name: "job 102",
115+
Status: actions_model.StatusFailure.String(),
116+
CanRerun: false,
117+
Duration: "3h",
118+
})
119+
88120
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, &actions.ViewJobStep{
89121
Summary: "step 0 (mock slow)",
90122
Duration: time.Hour.String(),

routers/web/web.go

+1
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ func registerRoutes(m *web.Router) {
16341634
m.Any("", devtest.List)
16351635
m.Any("/fetch-action-test", devtest.FetchActionTest)
16361636
m.Any("/{sub}", devtest.Tmpl)
1637+
m.Get("/repo-action-view/{run}/{job}", devtest.MockActionsView)
16371638
m.Post("/actions-mock/runs/{run}/jobs/{job}", web.Bind(actions.ViewRequest{}), devtest.MockActionsRunsJobs)
16381639
})
16391640
}

templates/devtest/repo-action-view.tmpl

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{{template "base/head" .}}
22
<div class="page-content">
3+
<div class="tw-flex tw-justify-center tw-items-center tw-gap-5">
4+
<a href="/devtest/repo-action-view/10/100">Run:CanCancel</a>
5+
<a href="/devtest/repo-action-view/20/200">Run:CanApprove</a>
6+
<a href="/devtest/repo-action-view/30/300">Run:CanRerun</a>
7+
</div>
38
{{template "repo/actions/view_component" (dict
4-
"RunIndex" 1
5-
"JobIndex" 2
9+
"RunIndex" (or .RunID 10)
10+
"JobIndex" (or .JobID 100)
611
"ActionsURL" (print AppSubUrl "/devtest/actions-mock")
712
)}}
813
</div>

web_src/js/components/RepoActionView.vue

+3-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export default defineComponent({
105105
intervalID: null as IntervalId | null,
106106
currentJobStepsStates: [] as Array<Record<string, any>>,
107107
artifacts: [] as Array<Record<string, any>>,
108-
onHoverRerunIndex: -1,
109108
menuVisible: false,
110109
isFullScreen: false,
111110
timeVisible: {
@@ -120,7 +119,7 @@ export default defineComponent({
120119
link: '',
121120
title: '',
122121
titleHTML: '',
123-
status: 'unknown' as RunStatus,
122+
status: '' as RunStatus, // do not show the status before initialized, otherwise it would show an incorrect "error" icon
124123
canCancel: false,
125124
canApprove: false,
126125
canRerun: false,
@@ -492,13 +491,13 @@ export default defineComponent({
492491
<div class="action-view-left">
493492
<div class="job-group-section">
494493
<div class="job-brief-list">
495-
<a class="job-brief-item" :href="run.link+'/jobs/'+index" :class="parseInt(jobIndex) === index ? 'selected' : ''" v-for="(job, index) in run.jobs" :key="job.id" @mouseenter="onHoverRerunIndex = job.id" @mouseleave="onHoverRerunIndex = -1">
494+
<a class="job-brief-item" :href="run.link+'/jobs/'+index" :class="parseInt(jobIndex) === index ? 'selected' : ''" v-for="(job, index) in run.jobs" :key="job.id">
496495
<div class="job-brief-item-left">
497496
<ActionRunStatus :locale-status="locale.status[job.status]" :status="job.status"/>
498497
<span class="job-brief-name tw-mx-2 gt-ellipsis">{{ job.name }}</span>
499498
</div>
500499
<span class="job-brief-item-right">
501-
<SvgIcon name="octicon-sync" role="button" :data-tooltip-content="locale.rerun" class="job-brief-rerun tw-mx-2 link-action" :data-url="`${run.link}/jobs/${index}/rerun`" v-if="job.canRerun && onHoverRerunIndex === job.id"/>
500+
<SvgIcon name="octicon-sync" role="button" :data-tooltip-content="locale.rerun" class="job-brief-rerun tw-mx-2 link-action" :data-url="`${run.link}/jobs/${index}/rerun`" v-if="job.canRerun"/>
502501
<span class="step-summary-duration">{{ job.duration }}</span>
503502
</span>
504503
</a>
@@ -721,11 +720,6 @@ export default defineComponent({
721720
722721
.job-brief-item .job-brief-rerun {
723722
cursor: pointer;
724-
transition: transform 0.2s;
725-
}
726-
727-
.job-brief-item .job-brief-rerun:hover {
728-
transform: scale(130%);
729723
}
730724
731725
.job-brief-item .job-brief-item-left {

0 commit comments

Comments
 (0)