1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-05 17:54:26 +00:00

align with GitHub Actions

This commit is contained in:
chesterip 2023-08-23 10:13:39 -04:00
parent 8f787dfe66
commit 5ebefc85ca
3 changed files with 52 additions and 23 deletions

View File

@ -7,17 +7,28 @@ import (
"time" "time"
) )
// Tag represents a repository tag // ActionTask represents a ActionTask
type ActionTask struct { type ActionTask struct {
ID int64 `json:"id"` Id int64 `json:"id"`
JobName string `json:"job_name"` Name string `json:"name"`
WorkflowID string `json:"workflow_id"` HeadBranch string `json:"head_branch"`
Title string `json:"title"` HeadSha string `json:"head_sha"`
Status string `json:"status"` RunNumber int64 `json:"run_number"`
Commit string `json:"commit"` Event string `json:"event"`
Duration string `json:"duration"` DisplayTitle string `json:"display_title"`
Status string `json:"status"`
WorkflowID string `json:"workflow_id"`
Url string `json:"url"`
// swagger:strfmt date-time // swagger:strfmt date-time
Started time.Time `json:"started,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
// swagger:strfmt date-time // swagger:strfmt date-time
Stopped time.Time `json:"stopped,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
// swagger:strfmt date-time
RunStartedAt time.Time `json:"run_started_at,omitempty"`
}
// ActionTaskResponse returns a ActionTask
type ActionTaskResponse struct {
Entries []*ActionTask `json:"workflow_runs"`
TotalCount int64 `json:"total_count"`
} }

View File

@ -56,14 +56,27 @@ func ListActionTasks(ctx *context.APIContext) {
} }
tasks, err := actions_model.FindTasks(ctx, opts) tasks, err := actions_model.FindTasks(ctx, opts)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err) ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
return return
} }
apiActionTasks := make([]*api.ActionTask, len(tasks)) res := new(api.ActionTaskResponse)
res.Entries = make([]*api.ActionTask, len(tasks))
for i := range tasks { for i := range tasks {
apiActionTasks[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i])
} }
ctx.JSON(http.StatusOK, &apiActionTasks) opts = actions_model.FindTaskOptions{
RepoID: ctx.Repo.Repository.ID,
Status: actions_model.StatusUnknown, // Unknown means all
IDOrderDesc: true,
}
res.TotalCount, err = actions_model.CountTasks(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
return
}
ctx.JSON(http.StatusOK, &res)
} }

View File

@ -185,16 +185,21 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m
if err := t.LoadAttributes(ctx); err != nil { if err := t.LoadAttributes(ctx); err != nil {
log.Warn("LoadAttributes of ActionTask: %v", err) log.Warn("LoadAttributes of ActionTask: %v", err)
} }
return &api.ActionTask{ return &api.ActionTask{
ID: t.Job.Run.Index, Id: t.ID,
JobName: t.Job.Name, Name: t.Job.Name,
WorkflowID: t.Job.Run.WorkflowID, HeadBranch: t.Job.Run.PrettyRef(),
Title: t.Job.Run.Title, HeadSha: t.Job.CommitSHA,
Status: t.Status.String(), RunNumber: t.Job.Run.Index,
Commit: t.CommitSHA, Event: t.Job.Run.TriggerEvent,
Duration: t.Duration().String(), DisplayTitle: t.Job.Run.Title,
Started: t.Started.AsLocalTime(), Status: t.Status.String(),
Stopped: t.Stopped.AsLocalTime(), WorkflowID: t.Job.Run.WorkflowID,
Url: t.GetRunLink(),
CreatedAt: t.Created.AsLocalTime(),
UpdatedAt: t.Updated.AsLocalTime(),
RunStartedAt: t.Started.AsLocalTime(),
} }
} }