From 80dae172614c5e7ffde4260397aabc7da8e72378 Mon Sep 17 00:00:00 2001 From: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Date: Sun, 3 Aug 2025 11:30:41 +0800 Subject: [PATCH 1/4] update --- routers/api/v1/repo/action.go | 28 +++++++++++++------ .../api_actions_delete_run_test.go | 4 +++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 99eef2f53b7df..caaf68404743e 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -1132,18 +1132,23 @@ func GetWorkflowRun(ctx *context.APIContext) { // "$ref": "#/responses/notFound" runID := ctx.PathParamInt64("run") - job, _, err := db.GetByID[actions_model.ActionRun](ctx, runID) + job, has, err := db.GetByID[actions_model.ActionRun](ctx, runID) + if err != nil { + ctx.APIErrorInternal(err) + return + } - if err != nil || job.RepoID != ctx.Repo.Repository.ID { - ctx.APIError(http.StatusNotFound, util.ErrNotExist) + if !has || job.RepoID != ctx.Repo.Repository.ID { + ctx.APIErrorNotFound(util.ErrNotExist) + return } - convertedArtifact, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job) + convertedRun, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job) if err != nil { ctx.APIErrorInternal(err) return } - ctx.JSON(http.StatusOK, convertedArtifact) + ctx.JSON(http.StatusOK, convertedRun) } // ListWorkflowRunJobs Lists all jobs for a workflow run. @@ -1237,10 +1242,15 @@ func GetWorkflowJob(ctx *context.APIContext) { // "$ref": "#/responses/notFound" jobID := ctx.PathParamInt64("job_id") - job, _, err := db.GetByID[actions_model.ActionRunJob](ctx, jobID) + job, has, err := db.GetByID[actions_model.ActionRunJob](ctx, jobID) + if err != nil { + ctx.APIErrorInternal(err) + return + } - if err != nil || job.RepoID != ctx.Repo.Repository.ID { + if !has || job.RepoID != ctx.Repo.Repository.ID { ctx.APIError(http.StatusNotFound, util.ErrNotExist) + return } convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, job) @@ -1251,7 +1261,7 @@ func GetWorkflowJob(ctx *context.APIContext) { ctx.JSON(http.StatusOK, convertedWorkflowJob) } -// GetArtifacts Lists all artifacts for a repository. +// GetArtifactsOfRun Lists all artifacts for a repository. func GetArtifactsOfRun(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/runs/{run}/artifacts repository getArtifactsOfRun // --- @@ -1354,7 +1364,7 @@ func DeleteActionRun(ctx *context.APIContext) { runID := ctx.PathParamInt64("run") run, err := actions_model.GetRunByRepoAndID(ctx, ctx.Repo.Repository.ID, runID) if errors.Is(err, util.ErrNotExist) { - ctx.APIError(http.StatusNotFound, err) + ctx.APIErrorNotFound(err) return } else if err != nil { ctx.APIErrorInternal(err) diff --git a/tests/integration/api_actions_delete_run_test.go b/tests/integration/api_actions_delete_run_test.go index 5b41702c57da5..a1ed95b579ac5 100644 --- a/tests/integration/api_actions_delete_run_test.go +++ b/tests/integration/api_actions_delete_run_test.go @@ -36,6 +36,10 @@ func TestAPIActionsDeleteRun(t *testing.T) { session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNotFound) + testAPIActionsDeleteRunListArtifacts(t, repo, token, 2) testAPIActionsDeleteRunListTasks(t, repo, token, true) testAPIActionsDeleteRun(t, repo, token, http.StatusNoContent) From 209eb598b56ed4b42c5470edccd4dae8c1ee11f1 Mon Sep 17 00:00:00 2001 From: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Date: Sun, 3 Aug 2025 13:29:35 +0800 Subject: [PATCH 2/4] update --- routers/api/v1/repo/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index caaf68404743e..25aabe6dd2792 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -1249,7 +1249,7 @@ func GetWorkflowJob(ctx *context.APIContext) { } if !has || job.RepoID != ctx.Repo.Repository.ID { - ctx.APIError(http.StatusNotFound, util.ErrNotExist) + ctx.APIErrorNotFound(util.ErrNotExist) return } From 84ecf9f565b4f9cf97ea94a4445f34e87aa00751 Mon Sep 17 00:00:00 2001 From: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:00:39 +0800 Subject: [PATCH 3/4] update --- tests/integration/api_actions_delete_run_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/api_actions_delete_run_test.go b/tests/integration/api_actions_delete_run_test.go index a1ed95b579ac5..e5d083b981144 100644 --- a/tests/integration/api_actions_delete_run_test.go +++ b/tests/integration/api_actions_delete_run_test.go @@ -36,7 +36,10 @@ func TestAPIActionsDeleteRun(t *testing.T) { session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802802", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNotFound) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())). AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) From 3d469c0aec7f7be9e9feda30327a43d4909422a6 Mon Sep 17 00:00:00 2001 From: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Date: Mon, 4 Aug 2025 16:08:45 +0800 Subject: [PATCH 4/4] update test case --- ...te_run_test.go => api_actions_run_test.go} | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) rename tests/integration/{api_actions_delete_run_test.go => api_actions_run_test.go} (73%) diff --git a/tests/integration/api_actions_delete_run_test.go b/tests/integration/api_actions_run_test.go similarity index 73% rename from tests/integration/api_actions_delete_run_test.go rename to tests/integration/api_actions_run_test.go index e5d083b981144..a0292f8f8b58f 100644 --- a/tests/integration/api_actions_delete_run_test.go +++ b/tests/integration/api_actions_run_test.go @@ -18,17 +18,26 @@ import ( "github.com/stretchr/testify/assert" ) -func TestAPIActionsDeleteRunCheckPermission(t *testing.T) { +func TestAPIActionsGetWorkflowRun(t *testing.T) { defer prepareTestEnvActionsArtifacts(t)() - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - testAPIActionsDeleteRun(t, repo, token, http.StatusNotFound) + + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802802", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNotFound) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNotFound) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/803", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusOK) } -func TestAPIActionsDeleteRun(t *testing.T) { +func TestAPIActionsGetWorkflowJob(t *testing.T) { defer prepareTestEnvActionsArtifacts(t)() repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) @@ -36,12 +45,34 @@ func TestAPIActionsDeleteRun(t *testing.T) { session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802802", repo.FullName())). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/198198", repo.FullName())). AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/198", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusOK) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/196", repo.FullName())). AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) +} + +func TestAPIActionsDeleteRunCheckPermission(t *testing.T) { + defer prepareTestEnvActionsArtifacts(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + session := loginUser(t, user.Name) + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) + testAPIActionsDeleteRun(t, repo, token, http.StatusNotFound) +} + +func TestAPIActionsDeleteRun(t *testing.T) { + defer prepareTestEnvActionsArtifacts(t)() + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + session := loginUser(t, user.Name) + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) testAPIActionsDeleteRunListArtifacts(t, repo, token, 2) testAPIActionsDeleteRunListTasks(t, repo, token, true)