mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 17:05:45 +02:00
chore(model): create build, stage, step and logs table
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
e05f224d19
commit
e07d416366
@ -85,7 +85,7 @@ func (Build) TableName() string {
|
||||
}
|
||||
|
||||
func (t *Build) HTMLURL() string {
|
||||
return fmt.Sprintf("")
|
||||
return ""
|
||||
}
|
||||
|
||||
func updateRepoBuildsNumbers(ctx context.Context, repo *repo_model.Repository) error {
|
||||
@ -132,18 +132,18 @@ func InsertBuild(t *Build, workflowsStatuses map[string]map[string]BuildStatus)
|
||||
return err
|
||||
}
|
||||
|
||||
var buildJobs []BuildJob
|
||||
var buildStages []BuildStage
|
||||
for filename, workflow := range workflowsStatuses {
|
||||
for job, status := range workflow {
|
||||
buildJobs = append(buildJobs, BuildJob{
|
||||
buildStages = append(buildStages, BuildStage{
|
||||
BuildID: t.ID,
|
||||
Filename: filename,
|
||||
Jobname: job,
|
||||
Name: job,
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
}
|
||||
if err := db.Insert(ctx, buildJobs); err != nil {
|
||||
if err := db.Insert(ctx, buildStages); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -13,11 +13,10 @@ import (
|
||||
|
||||
// BuildLog represents a build's log, every build has a standalone table
|
||||
type BuildLog struct {
|
||||
ID int64
|
||||
BuildJobID int64 `xorm:"index"`
|
||||
LineNumber int
|
||||
Content string `xorm:"LONGTEXT"`
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
ID int64
|
||||
StepID int64 `xorm:"index"`
|
||||
Content string `xorm:"BINARY"`
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -37,7 +36,7 @@ func CreateBuildLog(buildID int64) error {
|
||||
|
||||
func GetBuildLogs(buildID, jobID int64) (logs []BuildLog, err error) {
|
||||
err = db.GetEngine(db.DefaultContext).Table(GetBuildLogTableName(buildID)).
|
||||
Where("build_job_id=?", jobID).
|
||||
Where("build_step_id=?", jobID).
|
||||
Find(&logs)
|
||||
return
|
||||
}
|
||||
|
@ -9,33 +9,38 @@ import (
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
type BuildJob struct {
|
||||
type BuildStage struct {
|
||||
ID int64
|
||||
BuildID int64 `xorm:"index"`
|
||||
Number int64
|
||||
Name string
|
||||
Kind string
|
||||
Type string
|
||||
Filename string
|
||||
Jobname string
|
||||
Status BuildStatus
|
||||
Started timeutil.TimeStamp
|
||||
Stopped timeutil.TimeStamp
|
||||
LogToFile bool // read log from database or from storage
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
}
|
||||
|
||||
func (bj BuildJob) TableName() string {
|
||||
return "bots_build_job"
|
||||
func (bj BuildStage) TableName() string {
|
||||
return "bots_build_stage"
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(BuildJob))
|
||||
db.RegisterModel(new(BuildStage))
|
||||
}
|
||||
|
||||
func GetBuildWorkflows(buildID int64) (map[string]map[string]*BuildJob, error) {
|
||||
jobs := make(map[string]map[string]*BuildJob)
|
||||
err := db.GetEngine(db.DefaultContext).Iterate(new(BuildJob), func(idx int, bean interface{}) error {
|
||||
job := bean.(*BuildJob)
|
||||
func GetBuildWorkflows(buildID int64) (map[string]map[string]*BuildStage, error) {
|
||||
jobs := make(map[string]map[string]*BuildStage)
|
||||
err := db.GetEngine(db.DefaultContext).Iterate(new(BuildStage), func(idx int, bean interface{}) error {
|
||||
job := bean.(*BuildStage)
|
||||
_, ok := jobs[job.Filename]
|
||||
if !ok {
|
||||
jobs[job.Filename] = make(map[string]*BuildJob)
|
||||
jobs[job.Filename] = make(map[string]*BuildStage)
|
||||
}
|
||||
jobs[job.Filename][job.Jobname] = job
|
||||
jobs[job.Filename][job.Name] = job
|
||||
return nil
|
||||
})
|
||||
return jobs, err
|
31
models/bots/build_step.go
Normal file
31
models/bots/build_step.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package bots
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
type BuildStep struct {
|
||||
ID int64
|
||||
StageID int64 `xorm:"index"`
|
||||
Number int64
|
||||
Name string
|
||||
Kind string
|
||||
Type string
|
||||
Status BuildStatus
|
||||
Started timeutil.TimeStamp
|
||||
Stopped timeutil.TimeStamp
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
}
|
||||
|
||||
func (bj BuildStep) TableName() string {
|
||||
return "bots_build_step"
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(BuildStep))
|
||||
}
|
@ -77,8 +77,6 @@ func (runners RunnerList) LoadAttributes(ctx context.Context) error {
|
||||
if err := runners.LoadOwners(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := runners.LoadRepos(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return runners.LoadRepos(ctx)
|
||||
}
|
||||
|
@ -10,11 +10,14 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
pingv1 "gitea.com/gitea/proto-go/ping/v1"
|
||||
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
|
||||
|
||||
"github.com/bufbuild/connect-go"
|
||||
)
|
||||
|
||||
type Service struct{}
|
||||
type Service struct {
|
||||
pingv1connect.UnimplementedPingServiceHandler
|
||||
}
|
||||
|
||||
func (s *Service) Ping(
|
||||
ctx context.Context,
|
||||
@ -22,10 +25,9 @@ func (s *Service) Ping(
|
||||
) (*connect.Response[pingv1.PingResponse], error) {
|
||||
log.Info("Content-Type: %s", req.Header().Get("Content-Type"))
|
||||
log.Info("User-Agent: %s", req.Header().Get("User-Agent"))
|
||||
log.Info("X-Gitea-Token: %s", req.Header().Get("X-Gitea-Token"))
|
||||
log.Info("X-Runner-Token: %s", req.Header().Get("X-Runner-Token"))
|
||||
res := connect.NewResponse(&pingv1.PingResponse{
|
||||
Data: fmt.Sprintf("Hello, %s!", req.Msg.Data),
|
||||
})
|
||||
res.Header().Set("Gitea-Version", "v1")
|
||||
return res, nil
|
||||
}
|
||||
|
@ -118,14 +118,14 @@ func GetBuildJobLogs(ctx *context.Context) {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
var buildJob *bots_model.BuildJob
|
||||
var buildJob *bots_model.BuildStage
|
||||
wf := ctx.Params("workflow")
|
||||
jobname := ctx.Params("jobname")
|
||||
LOOP_WORKFLOWS:
|
||||
for workflow, jobs := range workflows {
|
||||
if workflow == wf {
|
||||
for _, job := range jobs {
|
||||
if jobname == job.Jobname {
|
||||
if jobname == job.Name {
|
||||
buildJob = job
|
||||
break LOOP_WORKFLOWS
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user