mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-07 12:58:46 +00:00
parent
920d62c0a7
commit
becd15f743
@ -1132,18 +1132,23 @@ func GetWorkflowRun(ctx *context.APIContext) {
|
|||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
runID := ctx.PathParamInt64("run")
|
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 || job.RepoID != ctx.Repo.Repository.ID {
|
|
||||||
ctx.APIError(http.StatusNotFound, util.ErrNotExist)
|
|
||||||
}
|
|
||||||
|
|
||||||
convertedArtifact, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.APIErrorInternal(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convertedArtifact)
|
|
||||||
|
if !has || job.RepoID != ctx.Repo.Repository.ID {
|
||||||
|
ctx.APIErrorNotFound(util.ErrNotExist)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
convertedRun, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job)
|
||||||
|
if err != nil {
|
||||||
|
ctx.APIErrorInternal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, convertedRun)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListWorkflowRunJobs Lists all jobs for a workflow run.
|
// ListWorkflowRunJobs Lists all jobs for a workflow run.
|
||||||
@ -1237,10 +1242,15 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
|||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
jobID := ctx.PathParamInt64("job_id")
|
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)
|
ctx.APIErrorNotFound(util.ErrNotExist)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, job)
|
convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, job)
|
||||||
@ -1251,7 +1261,7 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
|||||||
ctx.JSON(http.StatusOK, convertedWorkflowJob)
|
ctx.JSON(http.StatusOK, convertedWorkflowJob)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArtifacts Lists all artifacts for a repository.
|
// GetArtifactsOfRun Lists all artifacts for a repository.
|
||||||
func GetArtifactsOfRun(ctx *context.APIContext) {
|
func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/actions/runs/{run}/artifacts repository getArtifactsOfRun
|
// 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")
|
runID := ctx.PathParamInt64("run")
|
||||||
run, err := actions_model.GetRunByRepoAndID(ctx, ctx.Repo.Repository.ID, runID)
|
run, err := actions_model.GetRunByRepoAndID(ctx, ctx.Repo.Repository.ID, runID)
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.APIError(http.StatusNotFound, err)
|
ctx.APIErrorNotFound(err)
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
ctx.APIErrorInternal(err)
|
ctx.APIErrorInternal(err)
|
||||||
|
@ -18,6 +18,44 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestAPIActionsGetWorkflowRun(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)
|
||||||
|
|
||||||
|
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 TestAPIActionsGetWorkflowJob(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)
|
||||||
|
|
||||||
|
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/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) {
|
func TestAPIActionsDeleteRunCheckPermission(t *testing.T) {
|
||||||
defer prepareTestEnvActionsArtifacts(t)()
|
defer prepareTestEnvActionsArtifacts(t)()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user