Merge pull request '[UI] Actions: Link to Workflow in View' (#1866) from n0toose/forgejo:forgejo-add-workflow-link into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1866 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
d0e5af7079
6 changed files with 62 additions and 19 deletions
|
@ -22,12 +22,21 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func GetWorkflowRunRedirectURI(t *testing.T, repoURL, workflow string) string {
|
||||
t.Helper()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/%s/runs/latest", repoURL, workflow))
|
||||
resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
||||
|
||||
return resp.Header().Get("Location")
|
||||
}
|
||||
|
||||
func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// create the repo
|
||||
repo, _, f := CreateDeclarativeRepo(t, user2, "",
|
||||
repo, _, f := CreateDeclarativeRepo(t, user2, "actionsTestRepo",
|
||||
[]unit_model.Type{unit_model.TypeActions}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
|
@ -44,23 +53,17 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
|||
)
|
||||
defer f()
|
||||
|
||||
repoURL := repo.HTMLURL()
|
||||
|
||||
t.Run("valid workflows", func(t *testing.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
|
||||
assert.Equal(t, 2, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||
|
||||
// Get the redirect URIs for both workflows
|
||||
workflowOneURI := getWorkflowRunRedirectURI("workflow-1.yml")
|
||||
workflowTwoURI := getWorkflowRunRedirectURI("workflow-2.yml")
|
||||
workflowOneURI := GetWorkflowRunRedirectURI(t, repoURL, "workflow-1.yml")
|
||||
workflowTwoURI := GetWorkflowRunRedirectURI(t, repoURL, "workflow-2.yml")
|
||||
|
||||
// Verify that the two are different.
|
||||
assert.NotEqual(t, workflowOneURI, workflowTwoURI)
|
||||
|
@ -77,17 +80,35 @@ func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
|||
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(t, repoURL, 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.
|
||||
expectedURL := fmt.Sprintf("/user2/actionsTestRepo/actions?workflow=%s", workflow)
|
||||
htmlDoc.AssertElement(t, fmt.Sprintf("#repo-action-view[data-workflow-url=\"%s\"]", expectedURL), true)
|
||||
})
|
||||
|
||||
t.Run("existing workflow, non-existent branch", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-1.yml/runs/latest?branch=foobar", repo.HTMLURL()))
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-1.yml/runs/latest?branch=foobar", repoURL))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
|
||||
t.Run("non-existing workflow", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-3.yml/runs/latest", repo.HTMLURL()))
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-3.yml/runs/latest", repoURL))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue