mirror of
https://github.com/go-gitea/gitea
synced 2025-10-26 08:58:24 +00:00
chore(runner): support fetch detail stage data
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/core"
|
||||
bots_model "code.gitea.io/gitea/models/bots"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
||||
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
|
||||
@@ -90,6 +91,66 @@ func (s *Service) Request(
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Details fetches build details
|
||||
func (s *Service) Detail(
|
||||
ctx context.Context,
|
||||
req *connect.Request[runnerv1.DetailRequest],
|
||||
) (*connect.Response[runnerv1.DetailResponse], error) {
|
||||
log.Info("stag id %d", req.Msg.Stage.Id)
|
||||
|
||||
// fetch stage data
|
||||
stage, err := bots_model.GetStageByID(req.Msg.Stage.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stage.Machine = req.Msg.Stage.Machine
|
||||
stage.Status = core.StatusPending
|
||||
|
||||
count, err := bots_model.UpdateBuildStage(stage, "machine", "status")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count != 1 {
|
||||
return nil, core.ErrDataLock
|
||||
}
|
||||
|
||||
// fetch build data
|
||||
build, err := bots_model.GetBuildByID(stage.BuildID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// fetch repo data
|
||||
repo, err := repo_model.GetRepositoryByID(build.RepoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := connect.NewResponse(&runnerv1.DetailResponse{
|
||||
Stage: &runnerv1.Stage{
|
||||
Id: stage.ID,
|
||||
BuildId: stage.BuildID,
|
||||
Name: stage.Name,
|
||||
Kind: stage.Kind,
|
||||
Type: stage.Type,
|
||||
Status: string(stage.Status),
|
||||
Started: int64(stage.Started),
|
||||
Stopped: int64(stage.Stopped),
|
||||
Machine: stage.Machine,
|
||||
},
|
||||
Build: &runnerv1.Build{
|
||||
Id: build.ID,
|
||||
Name: build.Name,
|
||||
},
|
||||
Repo: &runnerv1.Repo{
|
||||
Id: repo.ID,
|
||||
Name: repo.Name,
|
||||
},
|
||||
})
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Update updates the build stage.
|
||||
func (s *Service) Update(
|
||||
ctx context.Context,
|
||||
|
||||
Reference in New Issue
Block a user