1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-05 09:44: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"
)
// Tag represents a repository tag
// ActionTask represents a ActionTask
type ActionTask struct {
ID int64 `json:"id"`
JobName string `json:"job_name"`
WorkflowID string `json:"workflow_id"`
Title string `json:"title"`
Status string `json:"status"`
Commit string `json:"commit"`
Duration string `json:"duration"`
Id int64 `json:"id"`
Name string `json:"name"`
HeadBranch string `json:"head_branch"`
HeadSha string `json:"head_sha"`
RunNumber int64 `json:"run_number"`
Event string `json:"event"`
DisplayTitle string `json:"display_title"`
Status string `json:"status"`
WorkflowID string `json:"workflow_id"`
Url string `json:"url"`
// swagger:strfmt date-time
Started time.Time `json:"started,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
// 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)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err)
ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
return
}
apiActionTasks := make([]*api.ActionTask, len(tasks))
res := new(api.ActionTaskResponse)
res.Entries = make([]*api.ActionTask, len(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 {
log.Warn("LoadAttributes of ActionTask: %v", err)
}
return &api.ActionTask{
ID: t.Job.Run.Index,
JobName: t.Job.Name,
WorkflowID: t.Job.Run.WorkflowID,
Title: t.Job.Run.Title,
Status: t.Status.String(),
Commit: t.CommitSHA,
Duration: t.Duration().String(),
Started: t.Started.AsLocalTime(),
Stopped: t.Stopped.AsLocalTime(),
Id: t.ID,
Name: t.Job.Name,
HeadBranch: t.Job.Run.PrettyRef(),
HeadSha: t.Job.CommitSHA,
RunNumber: t.Job.Run.Index,
Event: t.Job.Run.TriggerEvent,
DisplayTitle: t.Job.Run.Title,
Status: t.Status.String(),
WorkflowID: t.Job.Run.WorkflowID,
Url: t.GetRunLink(),
CreatedAt: t.Created.AsLocalTime(),
UpdatedAt: t.Updated.AsLocalTime(),
RunStartedAt: t.Started.AsLocalTime(),
}
}