mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:41:27 +01:00
[UI] Actions: Link to Workflow in View
This commit is contained in:
parent
2f5b266cca
commit
1668904513
5 changed files with 54 additions and 15 deletions
|
@ -3627,6 +3627,7 @@ runs.all_workflows = All Workflows
|
||||||
runs.commit = Commit
|
runs.commit = Commit
|
||||||
runs.scheduled = Scheduled
|
runs.scheduled = Scheduled
|
||||||
runs.pushed_by = pushed by
|
runs.pushed_by = pushed by
|
||||||
|
runs.workflow = Workflow
|
||||||
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
|
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
|
||||||
runs.no_matching_online_runner_helper = No matching online runner with label: %s
|
runs.no_matching_online_runner_helper = No matching online runner with label: %s
|
||||||
runs.actor = Actor
|
runs.actor = Actor
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package actions
|
package actions
|
||||||
|
@ -35,13 +36,19 @@ func View(ctx *context_module.Context) {
|
||||||
ctx.Data["PageIsActions"] = true
|
ctx.Data["PageIsActions"] = true
|
||||||
runIndex := ctx.ParamsInt64("run")
|
runIndex := ctx.ParamsInt64("run")
|
||||||
jobIndex := ctx.ParamsInt64("job")
|
jobIndex := ctx.ParamsInt64("job")
|
||||||
|
|
||||||
|
job, _ := getRunJobs(ctx, runIndex, jobIndex)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
workflowName := job.Run.WorkflowID
|
||||||
|
|
||||||
ctx.Data["RunIndex"] = runIndex
|
ctx.Data["RunIndex"] = runIndex
|
||||||
ctx.Data["JobIndex"] = jobIndex
|
ctx.Data["JobIndex"] = jobIndex
|
||||||
ctx.Data["ActionsURL"] = ctx.Repo.RepoLink + "/actions"
|
ctx.Data["ActionsURL"] = ctx.Repo.RepoLink + "/actions"
|
||||||
|
ctx.Data["WorkflowName"] = workflowName
|
||||||
if getRunJobs(ctx, runIndex, jobIndex); ctx.Written() {
|
ctx.Data["WorkflowURL"] = ctx.Repo.RepoLink + "/actions?workflow=" + workflowName
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplViewActions)
|
ctx.HTML(http.StatusOK, tplViewActions)
|
||||||
}
|
}
|
||||||
|
@ -130,6 +137,7 @@ type ViewJob struct {
|
||||||
type ViewCommit struct {
|
type ViewCommit struct {
|
||||||
LocaleCommit string `json:"localeCommit"`
|
LocaleCommit string `json:"localeCommit"`
|
||||||
LocalePushedBy string `json:"localePushedBy"`
|
LocalePushedBy string `json:"localePushedBy"`
|
||||||
|
LocaleWorkflow string `json:"localeWorkflow"`
|
||||||
ShortSha string `json:"shortSHA"`
|
ShortSha string `json:"shortSHA"`
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Pusher ViewUser `json:"pusher"`
|
Pusher ViewUser `json:"pusher"`
|
||||||
|
@ -211,6 +219,7 @@ func ViewPost(ctx *context_module.Context) {
|
||||||
resp.State.Run.Commit = ViewCommit{
|
resp.State.Run.Commit = ViewCommit{
|
||||||
LocaleCommit: ctx.Locale.TrString("actions.runs.commit"),
|
LocaleCommit: ctx.Locale.TrString("actions.runs.commit"),
|
||||||
LocalePushedBy: ctx.Locale.TrString("actions.runs.pushed_by"),
|
LocalePushedBy: ctx.Locale.TrString("actions.runs.pushed_by"),
|
||||||
|
LocaleWorkflow: ctx.Locale.TrString("actions.runs.workflow"),
|
||||||
ShortSha: base.ShortSha(run.CommitSHA),
|
ShortSha: base.ShortSha(run.CommitSHA),
|
||||||
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),
|
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),
|
||||||
Pusher: pusher,
|
Pusher: pusher,
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
data-run-index="{{.RunIndex}}"
|
data-run-index="{{.RunIndex}}"
|
||||||
data-job-index="{{.JobIndex}}"
|
data-job-index="{{.JobIndex}}"
|
||||||
data-actions-url="{{.ActionsURL}}"
|
data-actions-url="{{.ActionsURL}}"
|
||||||
|
data-workflow-name="{{.WorkflowName}}"
|
||||||
|
data-workflow-url="{{.WorkflowURL}}"
|
||||||
data-locale-approve="{{ctx.Locale.Tr "repo.diff.review.approve"}}"
|
data-locale-approve="{{ctx.Locale.Tr "repo.diff.review.approve"}}"
|
||||||
data-locale-cancel="{{ctx.Locale.Tr "cancel"}}"
|
data-locale-cancel="{{ctx.Locale.Tr "cancel"}}"
|
||||||
data-locale-rerun="{{ctx.Locale.Tr "rerun"}}"
|
data-locale-rerun="{{ctx.Locale.Tr "rerun"}}"
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
// create the repo
|
// create the repo
|
||||||
repo, _, f := CreateDeclarativeRepo(t, user2, "",
|
repo, _, f := CreateDeclarativeRepo(t, user2, "actionsTestRepo",
|
||||||
[]unit_model.Type{unit_model.TypeActions}, nil,
|
[]unit_model.Type{unit_model.TypeActions}, nil,
|
||||||
[]*files_service.ChangeRepoFile{
|
[]*files_service.ChangeRepoFile{
|
||||||
{
|
{
|
||||||
|
@ -44,17 +44,17 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
||||||
)
|
)
|
||||||
defer f()
|
defer f()
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
getWorkflowRunRedirectURI := func(workflow string) string {
|
||||||
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/%s/runs/latest", repo.HTMLURL(), workflow))
|
||||||
|
resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
||||||
|
|
||||||
|
return resp.Header().Get("Location")
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("valid workflows", func(t *testing.T) {
|
t.Run("valid workflows", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
// helpers
|
|
||||||
getWorkflowRunRedirectURI := func(workflow string) string {
|
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/%s/runs/latest", repo.HTMLURL(), workflow))
|
|
||||||
resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
|
||||||
|
|
||||||
return resp.Header().Get("Location")
|
|
||||||
}
|
|
||||||
|
|
||||||
// two runs have been created
|
// two runs have been created
|
||||||
assert.Equal(t, 2, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
assert.Equal(t, 2, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||||
|
|
||||||
|
@ -77,6 +77,24 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
||||||
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
|
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("check if workflow page shows file name", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
// Get the redirect URI
|
||||||
|
workflow := "workflow-1.yml"
|
||||||
|
workflowOneURI := getWorkflowRunRedirectURI(workflow)
|
||||||
|
|
||||||
|
// Fetch the page that shows information about the run initiated by "workflow-1.yml".
|
||||||
|
// routers/web/repo/actions/view.go: data-workflow-url is constructed using data-workflow-name.
|
||||||
|
req := NewRequest(t, "GET", workflowOneURI)
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
|
// Verify that URL of the workflow is shown correctly.
|
||||||
|
rightURL := fmt.Sprintf("/user2/actionsTestRepo/actions?workflow=%s", workflow)
|
||||||
|
htmlDoc.AssertElement(t, fmt.Sprintf("#repo-action-view[data-workflow-url=\"%s\"]", rightURL), true)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("existing workflow, non-existent branch", func(t *testing.T) {
|
t.Run("existing workflow, non-existent branch", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ const sfc = {
|
||||||
runIndex: String,
|
runIndex: String,
|
||||||
jobIndex: String,
|
jobIndex: String,
|
||||||
actionsURL: String,
|
actionsURL: String,
|
||||||
|
workflowName: String,
|
||||||
|
workflowURL: String,
|
||||||
locale: Object,
|
locale: Object,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -56,6 +58,7 @@ const sfc = {
|
||||||
commit: {
|
commit: {
|
||||||
localeCommit: '',
|
localeCommit: '',
|
||||||
localePushedBy: '',
|
localePushedBy: '',
|
||||||
|
localeWorkflow: '',
|
||||||
shortSHA: '',
|
shortSHA: '',
|
||||||
link: '',
|
link: '',
|
||||||
pusher: {
|
pusher: {
|
||||||
|
@ -324,6 +327,8 @@ export function initRepositoryActionView() {
|
||||||
runIndex: el.getAttribute('data-run-index'),
|
runIndex: el.getAttribute('data-run-index'),
|
||||||
jobIndex: el.getAttribute('data-job-index'),
|
jobIndex: el.getAttribute('data-job-index'),
|
||||||
actionsURL: el.getAttribute('data-actions-url'),
|
actionsURL: el.getAttribute('data-actions-url'),
|
||||||
|
workflowName: el.getAttribute('data-workflow-name'),
|
||||||
|
workflowURL: el.getAttribute('data-workflow-url'),
|
||||||
locale: {
|
locale: {
|
||||||
approve: el.getAttribute('data-locale-approve'),
|
approve: el.getAttribute('data-locale-approve'),
|
||||||
cancel: el.getAttribute('data-locale-cancel'),
|
cancel: el.getAttribute('data-locale-cancel'),
|
||||||
|
@ -369,7 +374,7 @@ export function initRepositoryActionView() {
|
||||||
{{ locale.rerun_all }}
|
{{ locale.rerun_all }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="action-commit-summary">
|
<div class="action-summary">
|
||||||
{{ run.commit.localeCommit }}
|
{{ run.commit.localeCommit }}
|
||||||
<a class="muted" :href="run.commit.link">{{ run.commit.shortSHA }}</a>
|
<a class="muted" :href="run.commit.link">{{ run.commit.shortSHA }}</a>
|
||||||
{{ run.commit.localePushedBy }}
|
{{ run.commit.localePushedBy }}
|
||||||
|
@ -378,6 +383,10 @@ export function initRepositoryActionView() {
|
||||||
<a :href="run.commit.branch.link">{{ run.commit.branch.name }}</a>
|
<a :href="run.commit.branch.link">{{ run.commit.branch.name }}</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="action-summary">
|
||||||
|
{{ run.commit.localeWorkflow }}
|
||||||
|
<a class="muted" :href="workflowURL">{{ workflowName }}</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="action-view-body">
|
<div class="action-view-body">
|
||||||
<div class="action-view-left">
|
<div class="action-view-left">
|
||||||
|
@ -500,7 +509,7 @@ export function initRepositoryActionView() {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.action-commit-summary {
|
.action-summary {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
margin: 0 0 0 28px;
|
margin: 0 0 0 28px;
|
||||||
|
|
Loading…
Reference in a new issue