aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/actions/view.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-12-06 12:04:16 +0800
committerGitHub <noreply@github.com>2024-12-06 12:04:16 +0800
commitf7f68e4cc02ca57b841e20e0975b8926bf5c3722 (patch)
tree0a1ee205a4db859238752e9ed698a13dddfbf7e9 /routers/web/repo/actions/view.go
parentff14ada9655660af15d615b2fbd090b861686cd2 (diff)
downloadgitea-f7f68e4cc02ca57b841e20e0975b8926bf5c3722.tar.gz
gitea-f7f68e4cc02ca57b841e20e0975b8926bf5c3722.zip
Refactor RepoActionView.vue, add `::group::` support (#32713)
1. make it able to "force reload", then the previous pending request won't block the new request 2. make it support `::group::` 3. add some TS types (but there are still many variables untyped, this PR is large enough, the remaining types could be added in the future)
Diffstat (limited to 'routers/web/repo/actions/view.go')
-rw-r--r--routers/web/repo/actions/view.go98
1 files changed, 46 insertions, 52 deletions
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index f86d4c6177..0f0d7d1ebd 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -66,15 +66,25 @@ func View(ctx *context_module.Context) {
ctx.HTML(http.StatusOK, tplViewActions)
}
+type LogCursor struct {
+ Step int `json:"step"`
+ Cursor int64 `json:"cursor"`
+ Expanded bool `json:"expanded"`
+}
+
type ViewRequest struct {
- LogCursors []struct {
- Step int `json:"step"`
- Cursor int64 `json:"cursor"`
- Expanded bool `json:"expanded"`
- } `json:"logCursors"`
+ LogCursors []LogCursor `json:"logCursors"`
+}
+
+type ArtifactsViewItem struct {
+ Name string `json:"name"`
+ Size int64 `json:"size"`
+ Status string `json:"status"`
}
type ViewResponse struct {
+ Artifacts []*ArtifactsViewItem `json:"artifacts"`
+
State struct {
Run struct {
Link string `json:"link"`
@@ -146,6 +156,25 @@ type ViewStepLogLine struct {
Timestamp float64 `json:"timestamp"`
}
+func getActionsViewArtifacts(ctx context.Context, repoID, runIndex int64) (artifactsViewItems []*ArtifactsViewItem, err error) {
+ run, err := actions_model.GetRunByIndex(ctx, repoID, runIndex)
+ if err != nil {
+ return nil, err
+ }
+ artifacts, err := actions_model.ListUploadedArtifactsMeta(ctx, run.ID)
+ if err != nil {
+ return nil, err
+ }
+ for _, art := range artifacts {
+ artifactsViewItems = append(artifactsViewItems, &ArtifactsViewItem{
+ Name: art.ArtifactName,
+ Size: art.FileSize,
+ Status: util.Iif(art.Status == actions_model.ArtifactStatusExpired, "expired", "completed"),
+ })
+ }
+ return artifactsViewItems, nil
+}
+
func ViewPost(ctx *context_module.Context) {
req := web.GetForm(ctx).(*ViewRequest)
runIndex := getRunIndex(ctx)
@@ -157,11 +186,19 @@ func ViewPost(ctx *context_module.Context) {
}
run := current.Run
if err := run.LoadAttributes(ctx); err != nil {
- ctx.Error(http.StatusInternalServerError, err.Error())
+ ctx.ServerError("run.LoadAttributes", err)
return
}
+ var err error
resp := &ViewResponse{}
+ resp.Artifacts, err = getActionsViewArtifacts(ctx, ctx.Repo.Repository.ID, runIndex)
+ if err != nil {
+ if !errors.Is(err, util.ErrNotExist) {
+ ctx.ServerError("getActionsViewArtifacts", err)
+ return
+ }
+ }
resp.State.Run.Title = run.Title
resp.State.Run.Link = run.Link()
@@ -205,12 +242,12 @@ func ViewPost(ctx *context_module.Context) {
var err error
task, err = actions_model.GetTaskByID(ctx, current.TaskID)
if err != nil {
- ctx.Error(http.StatusInternalServerError, err.Error())
+ ctx.ServerError("actions_model.GetTaskByID", err)
return
}
task.Job = current
if err := task.LoadAttributes(ctx); err != nil {
- ctx.Error(http.StatusInternalServerError, err.Error())
+ ctx.ServerError("task.LoadAttributes", err)
return
}
}
@@ -278,7 +315,7 @@ func ViewPost(ctx *context_module.Context) {
offset := task.LogIndexes[index]
logRows, err := actions.ReadLogs(ctx, task.LogInStorage, task.LogFilename, offset, length)
if err != nil {
- ctx.Error(http.StatusInternalServerError, err.Error())
+ ctx.ServerError("actions.ReadLogs", err)
return
}
@@ -555,49 +592,6 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
return jobs[0], jobs
}
-type ArtifactsViewResponse struct {
- Artifacts []*ArtifactsViewItem `json:"artifacts"`
-}
-
-type ArtifactsViewItem struct {
- Name string `json:"name"`
- Size int64 `json:"size"`
- Status string `json:"status"`
-}
-
-func ArtifactsView(ctx *context_module.Context) {
- runIndex := getRunIndex(ctx)
- run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
- if err != nil {
- if errors.Is(err, util.ErrNotExist) {
- ctx.Error(http.StatusNotFound, err.Error())
- return
- }
- ctx.Error(http.StatusInternalServerError, err.Error())
- return
- }
- artifacts, err := actions_model.ListUploadedArtifactsMeta(ctx, run.ID)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, err.Error())
- return
- }
- artifactsResponse := ArtifactsViewResponse{
- Artifacts: make([]*ArtifactsViewItem, 0, len(artifacts)),
- }
- for _, art := range artifacts {
- status := "completed"
- if art.Status == actions_model.ArtifactStatusExpired {
- status = "expired"
- }
- artifactsResponse.Artifacts = append(artifactsResponse.Artifacts, &ArtifactsViewItem{
- Name: art.ArtifactName,
- Size: art.FileSize,
- Status: status,
- })
- }
- ctx.JSON(http.StatusOK, artifactsResponse)
-}
-
func ArtifactsDeleteView(ctx *context_module.Context) {
if !ctx.Repo.CanWrite(unit.TypeActions) {
ctx.Error(http.StatusForbidden, "no permission")