mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-04 20:46:45 +02:00
Rename to pipeline
in DB and JSONs (#1296)
Closes #1282 Follow-up to #1224, addresses #745 - changes JSON fields - adds migration to rename columns - fixes some comments
This commit is contained in:
parent
1114595078
commit
f88c70b55e
@ -32,9 +32,9 @@ type State struct {
|
|||||||
type Info struct {
|
type Info struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Repo string `json:"repository"`
|
Repo string `json:"repository"`
|
||||||
Pipeline string `json:"build_number"`
|
Pipeline string `json:"pipeline_number"`
|
||||||
Started time.Time `json:"build_started"`
|
Started time.Time `json:"pipeline_started"`
|
||||||
Timeout time.Duration `json:"build_timeout"`
|
Timeout time.Duration `json:"pipeline_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Add(id string, timeout time.Duration, repo, pipeline string) {
|
func (s *State) Add(id string, timeout time.Duration, repo, pipeline string) {
|
||||||
|
@ -36,5 +36,5 @@ type Config struct {
|
|||||||
// PipelineConfig is the n:n relation between Pipeline and Config
|
// PipelineConfig is the n:n relation between Pipeline and Config
|
||||||
type PipelineConfig struct {
|
type PipelineConfig struct {
|
||||||
ConfigID int64 `json:"-" xorm:"UNIQUE(s) NOT NULL 'config_id'"`
|
ConfigID int64 `json:"-" xorm:"UNIQUE(s) NOT NULL 'config_id'"`
|
||||||
PipelineID int64 `json:"-" xorm:"UNIQUE(s) NOT NULL 'build_id'"`
|
PipelineID int64 `json:"-" xorm:"UNIQUE(s) NOT NULL 'pipeline_id'"`
|
||||||
}
|
}
|
||||||
|
@ -21,5 +21,5 @@ type EventType string
|
|||||||
// Event represents a pipeline event.
|
// Event represents a pipeline event.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Repo Repo `json:"repo"`
|
Repo Repo `json:"repo"`
|
||||||
Pipeline Pipeline `json:"build"`
|
Pipeline Pipeline `json:"pipeline"`
|
||||||
}
|
}
|
||||||
|
@ -23,20 +23,20 @@ type Feed struct {
|
|||||||
Name string `json:"name" xorm:"repo_name"`
|
Name string `json:"name" xorm:"repo_name"`
|
||||||
FullName string `json:"full_name" xorm:"repo_full_name"`
|
FullName string `json:"full_name" xorm:"repo_full_name"`
|
||||||
|
|
||||||
Number int64 `json:"number,omitempty" xorm:"build_number"`
|
Number int64 `json:"number,omitempty" xorm:"pipeline_number"`
|
||||||
Event string `json:"event,omitempty" xorm:"build_event"`
|
Event string `json:"event,omitempty" xorm:"pipeline_event"`
|
||||||
Status string `json:"status,omitempty" xorm:"build_status"`
|
Status string `json:"status,omitempty" xorm:"pipeline_status"`
|
||||||
Created int64 `json:"created_at,omitempty" xorm:"build_created"`
|
Created int64 `json:"created_at,omitempty" xorm:"pipeline_created"`
|
||||||
Started int64 `json:"started_at,omitempty" xorm:"build_started"`
|
Started int64 `json:"started_at,omitempty" xorm:"pipeline_started"`
|
||||||
Finished int64 `json:"finished_at,omitempty" xorm:"build_finished"`
|
Finished int64 `json:"finished_at,omitempty" xorm:"pipeline_finished"`
|
||||||
Commit string `json:"commit,omitempty" xorm:"build_commit"`
|
Commit string `json:"commit,omitempty" xorm:"pipeline_commit"`
|
||||||
Branch string `json:"branch,omitempty" xorm:"build_branch"`
|
Branch string `json:"branch,omitempty" xorm:"pipeline_branch"`
|
||||||
Ref string `json:"ref,omitempty" xorm:"build_ref"`
|
Ref string `json:"ref,omitempty" xorm:"pipeline_ref"`
|
||||||
Refspec string `json:"refspec,omitempty" xorm:"build_refspec"`
|
Refspec string `json:"refspec,omitempty" xorm:"pipeline_refspec"`
|
||||||
Remote string `json:"remote,omitempty" xorm:"build_remote"`
|
Remote string `json:"remote,omitempty" xorm:"pipeline_remote"`
|
||||||
Title string `json:"title,omitempty" xorm:"build_title"`
|
Title string `json:"title,omitempty" xorm:"pipeline_title"`
|
||||||
Message string `json:"message,omitempty" xorm:"build_message"`
|
Message string `json:"message,omitempty" xorm:"pipeline_message"`
|
||||||
Author string `json:"author,omitempty" xorm:"build_author"`
|
Author string `json:"author,omitempty" xorm:"pipeline_author"`
|
||||||
Avatar string `json:"author_avatar,omitempty" xorm:"build_avatar"`
|
Avatar string `json:"author_avatar,omitempty" xorm:"pipeline_avatar"`
|
||||||
Email string `json:"author_email,omitempty" xorm:"build_email"`
|
Email string `json:"author_email,omitempty" xorm:"pipeline_email"`
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ type FileStore interface {
|
|||||||
// File represents a pipeline artifact.
|
// File represents a pipeline artifact.
|
||||||
type File struct {
|
type File struct {
|
||||||
ID int64 `json:"id" xorm:"pk autoincr 'file_id'"`
|
ID int64 `json:"id" xorm:"pk autoincr 'file_id'"`
|
||||||
PipelineID int64 `json:"-" xorm:"INDEX 'file_build_id'"`
|
PipelineID int64 `json:"-" xorm:"INDEX 'file_pipeline_id'"`
|
||||||
ProcID int64 `json:"proc_id" xorm:"UNIQUE(s) INDEX 'file_proc_id'"`
|
ProcID int64 `json:"proc_id" xorm:"UNIQUE(s) INDEX 'file_proc_id'"`
|
||||||
PID int `json:"pid" xorm:"file_pid"`
|
PID int `json:"pid" xorm:"file_pid"`
|
||||||
Name string `json:"name" xorm:"UNIQUE(s) file_name"`
|
Name string `json:"name" xorm:"UNIQUE(s) file_name"`
|
||||||
|
@ -17,37 +17,37 @@ package model
|
|||||||
|
|
||||||
// swagger:model pipeline
|
// swagger:model pipeline
|
||||||
type Pipeline struct {
|
type Pipeline struct {
|
||||||
ID int64 `json:"id" xorm:"pk autoincr 'build_id'"`
|
ID int64 `json:"id" xorm:"pk autoincr 'pipeline_id'"`
|
||||||
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'build_repo_id'"`
|
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'pipeline_repo_id'"`
|
||||||
Number int64 `json:"number" xorm:"UNIQUE(s) 'build_number'"`
|
Number int64 `json:"number" xorm:"UNIQUE(s) 'pipeline_number'"`
|
||||||
Author string `json:"author" xorm:"INDEX 'build_author'"`
|
Author string `json:"author" xorm:"INDEX 'pipeline_author'"`
|
||||||
ConfigID int64 `json:"-" xorm:"build_config_id"`
|
ConfigID int64 `json:"-" xorm:"pipeline_config_id"`
|
||||||
Parent int64 `json:"parent" xorm:"build_parent"`
|
Parent int64 `json:"parent" xorm:"pipeline_parent"`
|
||||||
Event WebhookEvent `json:"event" xorm:"build_event"`
|
Event WebhookEvent `json:"event" xorm:"pipeline_event"`
|
||||||
Status StatusValue `json:"status" xorm:"INDEX 'build_status'"`
|
Status StatusValue `json:"status" xorm:"INDEX 'pipeline_status'"`
|
||||||
Error string `json:"error" xorm:"build_error"`
|
Error string `json:"error" xorm:"pipeline_error"`
|
||||||
Enqueued int64 `json:"enqueued_at" xorm:"build_enqueued"`
|
Enqueued int64 `json:"enqueued_at" xorm:"pipeline_enqueued"`
|
||||||
Created int64 `json:"created_at" xorm:"build_created"`
|
Created int64 `json:"created_at" xorm:"pipeline_created"`
|
||||||
Updated int64 `json:"updated_at" xorm:"updated NOT NULL DEFAULT 0 'updated'"`
|
Updated int64 `json:"updated_at" xorm:"updated NOT NULL DEFAULT 0 'updated'"`
|
||||||
Started int64 `json:"started_at" xorm:"build_started"`
|
Started int64 `json:"started_at" xorm:"pipeline_started"`
|
||||||
Finished int64 `json:"finished_at" xorm:"build_finished"`
|
Finished int64 `json:"finished_at" xorm:"pipeline_finished"`
|
||||||
Deploy string `json:"deploy_to" xorm:"build_deploy"`
|
Deploy string `json:"deploy_to" xorm:"pipeline_deploy"`
|
||||||
Commit string `json:"commit" xorm:"build_commit"`
|
Commit string `json:"commit" xorm:"pipeline_commit"`
|
||||||
Branch string `json:"branch" xorm:"build_branch"`
|
Branch string `json:"branch" xorm:"pipeline_branch"`
|
||||||
Ref string `json:"ref" xorm:"build_ref"`
|
Ref string `json:"ref" xorm:"pipeline_ref"`
|
||||||
Refspec string `json:"refspec" xorm:"build_refspec"`
|
Refspec string `json:"refspec" xorm:"pipeline_refspec"`
|
||||||
Remote string `json:"remote" xorm:"build_remote"`
|
Remote string `json:"remote" xorm:"pipeline_remote"`
|
||||||
Title string `json:"title" xorm:"build_title"`
|
Title string `json:"title" xorm:"pipeline_title"`
|
||||||
Message string `json:"message" xorm:"TEXT 'build_message'"`
|
Message string `json:"message" xorm:"TEXT 'pipeline_message'"`
|
||||||
Timestamp int64 `json:"timestamp" xorm:"build_timestamp"`
|
Timestamp int64 `json:"timestamp" xorm:"pipeline_timestamp"`
|
||||||
Sender string `json:"sender" xorm:"build_sender"` // uses reported user for webhooks and name of cron for cron pipelines
|
Sender string `json:"sender" xorm:"pipeline_sender"` // uses reported user for webhooks and name of cron for cron pipelines
|
||||||
Avatar string `json:"author_avatar" xorm:"build_avatar"`
|
Avatar string `json:"author_avatar" xorm:"pipeline_avatar"`
|
||||||
Email string `json:"author_email" xorm:"build_email"`
|
Email string `json:"author_email" xorm:"pipeline_email"`
|
||||||
Link string `json:"link_url" xorm:"build_link"`
|
Link string `json:"link_url" xorm:"pipeline_link"`
|
||||||
Signed bool `json:"signed" xorm:"build_signed"` // deprecate
|
Signed bool `json:"signed" xorm:"pipeline_signed"` // deprecate
|
||||||
Verified bool `json:"verified" xorm:"build_verified"` // deprecate
|
Verified bool `json:"verified" xorm:"pipeline_verified"` // deprecate
|
||||||
Reviewer string `json:"reviewed_by" xorm:"build_reviewer"`
|
Reviewer string `json:"reviewed_by" xorm:"pipeline_reviewer"`
|
||||||
Reviewed int64 `json:"reviewed_at" xorm:"build_reviewed"`
|
Reviewed int64 `json:"reviewed_at" xorm:"pipeline_reviewed"`
|
||||||
Procs []*Proc `json:"procs,omitempty" xorm:"-"`
|
Procs []*Proc `json:"procs,omitempty" xorm:"-"`
|
||||||
Files []*File `json:"files,omitempty" xorm:"-"`
|
Files []*File `json:"files,omitempty" xorm:"-"`
|
||||||
ChangedFiles []string `json:"changed_files,omitempty" xorm:"json 'changed_files'"`
|
ChangedFiles []string `json:"changed_files,omitempty" xorm:"json 'changed_files'"`
|
||||||
|
@ -32,7 +32,7 @@ type ProcStore interface {
|
|||||||
// swagger:model proc
|
// swagger:model proc
|
||||||
type Proc struct {
|
type Proc struct {
|
||||||
ID int64 `json:"id" xorm:"pk autoincr 'proc_id'"`
|
ID int64 `json:"id" xorm:"pk autoincr 'proc_id'"`
|
||||||
PipelineID int64 `json:"build_id" xorm:"UNIQUE(s) INDEX 'proc_build_id'"`
|
PipelineID int64 `json:"pipeline_id" xorm:"UNIQUE(s) INDEX 'proc_pipeline_id'"`
|
||||||
PID int `json:"pid" xorm:"UNIQUE(s) 'proc_pid'"`
|
PID int `json:"pid" xorm:"UNIQUE(s) 'proc_pid'"`
|
||||||
PPID int `json:"ppid" xorm:"proc_ppid"`
|
PPID int `json:"ppid" xorm:"proc_ppid"`
|
||||||
PGID int `json:"pgid" xorm:"proc_pgid"`
|
PGID int `json:"pgid" xorm:"proc_pgid"`
|
||||||
|
@ -37,7 +37,7 @@ type config struct {
|
|||||||
|
|
||||||
type requestStructure struct {
|
type requestStructure struct {
|
||||||
Repo *model.Repo `json:"repo"`
|
Repo *model.Repo `json:"repo"`
|
||||||
Pipeline *model.Pipeline `json:"build"`
|
Pipeline *model.Pipeline `json:"pipeline"`
|
||||||
Configuration []*config `json:"configs"`
|
Configuration []*config `json:"configs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ func TestFetchFromConfigService(t *testing.T) {
|
|||||||
|
|
||||||
type incoming struct {
|
type incoming struct {
|
||||||
Repo *model.Repo `json:"repo"`
|
Repo *model.Repo `json:"repo"`
|
||||||
Build *model.Pipeline `json:"build"`
|
Build *model.Pipeline `json:"pipeline"`
|
||||||
Configuration []*config `json:"config"`
|
Configuration []*config `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func (s storage) ConfigsForPipeline(pipelineID int64) ([]*model.Config, error) {
|
|||||||
return configs, s.engine.
|
return configs, s.engine.
|
||||||
Table("config").
|
Table("config").
|
||||||
Join("LEFT", "pipeline_config", "config.config_id = pipeline_config.config_id").
|
Join("LEFT", "pipeline_config", "config.config_id = pipeline_config.config_id").
|
||||||
Where("pipeline_config.build_id = ?", pipelineID).
|
Where("pipeline_config.pipeline_id = ?", pipelineID).
|
||||||
Find(&configs)
|
Find(&configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,22 +41,22 @@ func (s storage) ConfigFindIdentical(repoID int64, hash string) (*model.Config,
|
|||||||
func (s storage) ConfigFindApproved(config *model.Config) (bool, error) {
|
func (s storage) ConfigFindApproved(config *model.Config) (bool, error) {
|
||||||
/* TODO: use builder (do not behave same as pure sql, fix that)
|
/* TODO: use builder (do not behave same as pure sql, fix that)
|
||||||
return s.engine.Table(new(model.Pipeline)).
|
return s.engine.Table(new(model.Pipeline)).
|
||||||
Join("INNER", "pipeline_config", "pipelines.build_id = pipeline_config.build_id" ).
|
Join("INNER", "pipeline_config", "pipelines.pipeline_id = pipeline_config.pipeline_id" ).
|
||||||
Where(builder.Eq{"pipelines.build_repo_id": config.RepoID}).
|
Where(builder.Eq{"pipelines.pipeline_repo_id": config.RepoID}).
|
||||||
And(builder.Eq{"pipeline_config.config_id": config.ID}).
|
And(builder.Eq{"pipeline_config.config_id": config.ID}).
|
||||||
And(builder.In("pipelines.build_status", "blocked", "pending")).
|
And(builder.In("pipelines.pipeline_status", "blocked", "pending")).
|
||||||
Exist(new(model.Pipeline))
|
Exist(new(model.Pipeline))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
c, err := s.engine.SQL(`
|
c, err := s.engine.SQL(`
|
||||||
SELECT build_id FROM pipelines
|
SELECT pipeline_id FROM pipelines
|
||||||
WHERE build_repo_id = ?
|
WHERE pipeline_repo_id = ?
|
||||||
AND build_id in (
|
AND pipeline_id in (
|
||||||
SELECT build_id
|
SELECT pipeline_id
|
||||||
FROM pipeline_config
|
FROM pipeline_config
|
||||||
WHERE pipeline_config.config_id = ?
|
WHERE pipeline_config.config_id = ?
|
||||||
)
|
)
|
||||||
AND build_status NOT IN ('blocked', 'pending')
|
AND pipeline_status NOT IN ('blocked', 'pending')
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, config.RepoID, config.ID).Count()
|
`, config.RepoID, config.ID).Count()
|
||||||
return c > 0, err
|
return c > 0, err
|
||||||
|
@ -27,27 +27,27 @@ SELECT
|
|||||||
repo_owner
|
repo_owner
|
||||||
,repo_name
|
,repo_name
|
||||||
,repo_full_name
|
,repo_full_name
|
||||||
,build_number
|
,pipeline_number
|
||||||
,build_event
|
,pipeline_event
|
||||||
,build_status
|
,pipeline_status
|
||||||
,build_created
|
,pipeline_created
|
||||||
,build_started
|
,pipeline_started
|
||||||
,build_finished
|
,pipeline_finished
|
||||||
,build_commit
|
,pipeline_commit
|
||||||
,build_branch
|
,pipeline_branch
|
||||||
,build_ref
|
,pipeline_ref
|
||||||
,build_refspec
|
,pipeline_refspec
|
||||||
,build_remote
|
,pipeline_remote
|
||||||
,build_title
|
,pipeline_title
|
||||||
,build_message
|
,pipeline_message
|
||||||
,build_author
|
,pipeline_author
|
||||||
,build_email
|
,pipeline_email
|
||||||
,build_avatar
|
,pipeline_avatar
|
||||||
FROM
|
FROM
|
||||||
pipelines p
|
pipelines p
|
||||||
,repos r
|
,repos r
|
||||||
WHERE p.build_repo_id = r.repo_id
|
WHERE p.pipeline_repo_id = r.repo_id
|
||||||
AND p.build_status IN ('pending','running')
|
AND p.pipeline_status IN ('pending','running')
|
||||||
`).Find(&feed)
|
`).Find(&feed)
|
||||||
return feed, err
|
return feed, err
|
||||||
}
|
}
|
||||||
@ -60,28 +60,28 @@ SELECT
|
|||||||
repo_owner
|
repo_owner
|
||||||
,repo_name
|
,repo_name
|
||||||
,repo_full_name
|
,repo_full_name
|
||||||
,build_number
|
,pipeline_number
|
||||||
,build_event
|
,pipeline_event
|
||||||
,build_status
|
,pipeline_status
|
||||||
,build_created
|
,pipeline_created
|
||||||
,build_started
|
,pipeline_started
|
||||||
,build_finished
|
,pipeline_finished
|
||||||
,build_commit
|
,pipeline_commit
|
||||||
,build_branch
|
,pipeline_branch
|
||||||
,build_ref
|
,pipeline_ref
|
||||||
,build_refspec
|
,pipeline_refspec
|
||||||
,build_remote
|
,pipeline_remote
|
||||||
,build_title
|
,pipeline_title
|
||||||
,build_message
|
,pipeline_message
|
||||||
,build_author
|
,pipeline_author
|
||||||
,build_email
|
,pipeline_email
|
||||||
,build_avatar
|
,pipeline_avatar
|
||||||
FROM repos
|
FROM repos
|
||||||
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
||||||
INNER JOIN pipelines ON pipelines.build_repo_id = repos.repo_id
|
INNER JOIN pipelines ON pipelines.pipeline_repo_id = repos.repo_id
|
||||||
WHERE perms.perm_user_id = ?
|
WHERE perms.perm_user_id = ?
|
||||||
AND (perms.perm_push = ? OR perms.perm_admin = ?)
|
AND (perms.perm_push = ? OR perms.perm_admin = ?)
|
||||||
ORDER BY build_id DESC
|
ORDER BY pipeline_id DESC
|
||||||
LIMIT 50
|
LIMIT 50
|
||||||
`, user.ID, true, true).Find(&feed)
|
`, user.ID, true, true).Find(&feed)
|
||||||
}
|
}
|
||||||
@ -94,26 +94,26 @@ SELECT
|
|||||||
repo_owner
|
repo_owner
|
||||||
,repo_name
|
,repo_name
|
||||||
,repo_full_name
|
,repo_full_name
|
||||||
,build_number
|
,pipeline_number
|
||||||
,build_event
|
,pipeline_event
|
||||||
,build_status
|
,pipeline_status
|
||||||
,build_created
|
,pipeline_created
|
||||||
,build_started
|
,pipeline_started
|
||||||
,build_finished
|
,pipeline_finished
|
||||||
,build_commit
|
,pipeline_commit
|
||||||
,build_branch
|
,pipeline_branch
|
||||||
,build_ref
|
,pipeline_ref
|
||||||
,build_refspec
|
,pipeline_refspec
|
||||||
,build_remote
|
,pipeline_remote
|
||||||
,build_title
|
,pipeline_title
|
||||||
,build_message
|
,pipeline_message
|
||||||
,build_author
|
,pipeline_author
|
||||||
,build_email
|
,pipeline_email
|
||||||
,build_avatar
|
,pipeline_avatar
|
||||||
FROM repos LEFT OUTER JOIN pipelines ON build_id = (
|
FROM repos LEFT OUTER JOIN pipelines ON pipeline_id = (
|
||||||
SELECT build_id FROM pipelines
|
SELECT pipeline_id FROM pipelines
|
||||||
WHERE pipelines.build_repo_id = repos.repo_id
|
WHERE pipelines.pipeline_repo_id = repos.repo_id
|
||||||
ORDER BY build_id DESC
|
ORDER BY pipeline_id DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
)
|
)
|
||||||
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
func (s storage) FileList(pipeline *model.Pipeline) ([]*model.File, error) {
|
func (s storage) FileList(pipeline *model.Pipeline) ([]*model.File, error) {
|
||||||
files := make([]*model.File, 0, perPage)
|
files := make([]*model.File, 0, perPage)
|
||||||
return files, s.engine.Where("file_build_id = ?", pipeline.ID).Find(&files)
|
return files, s.engine.Where("file_pipeline_id = ?", pipeline.ID).Find(&files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) FileFind(proc *model.Proc, name string) (*model.File, error) {
|
func (s storage) FileFind(proc *model.Proc, name string) (*model.File, error) {
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
// Copyright 2022 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type oldBuildColumn struct {
|
||||||
|
table string
|
||||||
|
columns []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var renameColumnsBuildsToPipeline = task{
|
||||||
|
name: "rename-columns-builds-to-pipeline",
|
||||||
|
required: true,
|
||||||
|
fn: func(sess *xorm.Session) error {
|
||||||
|
var oldColumns []*oldBuildColumn
|
||||||
|
|
||||||
|
oldColumns = append(oldColumns, &oldBuildColumn{
|
||||||
|
table: "pipelines",
|
||||||
|
columns: []string{
|
||||||
|
"build_id",
|
||||||
|
"build_repo_id",
|
||||||
|
"build_number",
|
||||||
|
"build_author",
|
||||||
|
"build_config_id",
|
||||||
|
"build_parent",
|
||||||
|
"build_event",
|
||||||
|
"build_status",
|
||||||
|
"build_error",
|
||||||
|
"build_enqueued",
|
||||||
|
"build_created",
|
||||||
|
"build_started",
|
||||||
|
"build_finished",
|
||||||
|
"build_deploy",
|
||||||
|
"build_commit",
|
||||||
|
"build_branch",
|
||||||
|
"build_ref",
|
||||||
|
"build_refspec",
|
||||||
|
"build_remote",
|
||||||
|
"build_title",
|
||||||
|
"build_message",
|
||||||
|
"build_timestamp",
|
||||||
|
"build_sender",
|
||||||
|
"build_avatar",
|
||||||
|
"build_email",
|
||||||
|
"build_link",
|
||||||
|
"build_signed",
|
||||||
|
"build_verified",
|
||||||
|
"build_reviewer",
|
||||||
|
"build_reviewed",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
oldColumns = append(oldColumns, &oldBuildColumn{
|
||||||
|
table: "pipeline_config",
|
||||||
|
columns: []string{"build_id"},
|
||||||
|
})
|
||||||
|
|
||||||
|
oldColumns = append(oldColumns, &oldBuildColumn{
|
||||||
|
table: "files",
|
||||||
|
columns: []string{"file_build_id"},
|
||||||
|
})
|
||||||
|
|
||||||
|
oldColumns = append(oldColumns, &oldBuildColumn{
|
||||||
|
table: "procs",
|
||||||
|
columns: []string{"proc_build_id"},
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, table := range oldColumns {
|
||||||
|
for _, column := range table.columns {
|
||||||
|
err := renameColumn(sess, table.table, column, strings.Replace(column, "build_", "pipeline_", 1))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@ -248,6 +248,19 @@ func alterColumnNull(sess *xorm.Session, table, column string, null bool) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renameColumn(sess *xorm.Session, table, column, newName string) error {
|
||||||
|
dialect := sess.Engine().Dialect().URI().DBType
|
||||||
|
switch dialect {
|
||||||
|
case schemas.MYSQL,
|
||||||
|
schemas.POSTGRES,
|
||||||
|
schemas.SQLITE:
|
||||||
|
_, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` RENAME COLUMN `%s` TO `%s`;", table, column, newName))
|
||||||
|
return err
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("dialect '%s' not supported", dialect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
whitespaces = regexp.MustCompile(`\s+`)
|
whitespaces = regexp.MustCompile(`\s+`)
|
||||||
columnSeparator = regexp.MustCompile(`\s?,\s?`)
|
columnSeparator = regexp.MustCompile(`\s?,\s?`)
|
||||||
|
@ -37,6 +37,7 @@ var migrationTasks = []*task{
|
|||||||
&alterTableSecretsAddUserCol,
|
&alterTableSecretsAddUserCol,
|
||||||
&lowercaseSecretNames,
|
&lowercaseSecretNames,
|
||||||
&renameBuildsToPipeline,
|
&renameBuildsToPipeline,
|
||||||
|
&renameColumnsBuildsToPipeline,
|
||||||
}
|
}
|
||||||
|
|
||||||
var allBeans = []interface{}{
|
var allBeans = []interface{}{
|
||||||
@ -116,6 +117,10 @@ func Migrate(e *xorm.Engine) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := e.ClearCache(allBeans...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return syncAll(e)
|
return syncAll(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func (s storage) GetPipelineLast(repo *model.Repo, branch string) (*model.Pipeli
|
|||||||
Branch: branch,
|
Branch: branch,
|
||||||
Event: model.EventPush,
|
Event: model.EventPush,
|
||||||
}
|
}
|
||||||
return pipeline, wrapGet(s.engine.Desc("build_number").Get(pipeline))
|
return pipeline, wrapGet(s.engine.Desc("pipeline_number").Get(pipeline))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) GetPipelineLastBefore(repo *model.Repo, branch string, num int64) (*model.Pipeline, error) {
|
func (s storage) GetPipelineLastBefore(repo *model.Repo, branch string, num int64) (*model.Pipeline, error) {
|
||||||
@ -67,15 +67,15 @@ func (s storage) GetPipelineLastBefore(repo *model.Repo, branch string, num int6
|
|||||||
Branch: branch,
|
Branch: branch,
|
||||||
}
|
}
|
||||||
return pipeline, wrapGet(s.engine.
|
return pipeline, wrapGet(s.engine.
|
||||||
Desc("build_number").
|
Desc("pipeline_number").
|
||||||
Where("build_id < ?", num).
|
Where("pipeline_id < ?", num).
|
||||||
Get(pipeline))
|
Get(pipeline))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) GetPipelineList(repo *model.Repo, page int) ([]*model.Pipeline, error) {
|
func (s storage) GetPipelineList(repo *model.Repo, page int) ([]*model.Pipeline, error) {
|
||||||
pipelines := make([]*model.Pipeline, 0, perPage)
|
pipelines := make([]*model.Pipeline, 0, perPage)
|
||||||
return pipelines, s.engine.Where("build_repo_id = ?", repo.ID).
|
return pipelines, s.engine.Where("pipeline_repo_id = ?", repo.ID).
|
||||||
Desc("build_number").
|
Desc("pipeline_number").
|
||||||
Limit(perPage, perPage*(page-1)).
|
Limit(perPage, perPage*(page-1)).
|
||||||
Find(&pipelines)
|
Find(&pipelines)
|
||||||
}
|
}
|
||||||
@ -84,9 +84,9 @@ func (s storage) GetPipelineList(repo *model.Repo, page int) ([]*model.Pipeline,
|
|||||||
func (s storage) GetActivePipelineList(repo *model.Repo, page int) ([]*model.Pipeline, error) {
|
func (s storage) GetActivePipelineList(repo *model.Repo, page int) ([]*model.Pipeline, error) {
|
||||||
pipelines := make([]*model.Pipeline, 0, perPage)
|
pipelines := make([]*model.Pipeline, 0, perPage)
|
||||||
query := s.engine.
|
query := s.engine.
|
||||||
Where("build_repo_id = ?", repo.ID).
|
Where("pipeline_repo_id = ?", repo.ID).
|
||||||
In("build_status", model.StatusPending, model.StatusRunning, model.StatusBlocked).
|
In("pipeline_status", model.StatusPending, model.StatusRunning, model.StatusBlocked).
|
||||||
Desc("build_number")
|
Desc("pipeline_number")
|
||||||
if page > 0 {
|
if page > 0 {
|
||||||
query = query.Limit(perPage, perPage*(page-1))
|
query = query.Limit(perPage, perPage*(page-1))
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (s storage) CreatePipeline(pipeline *model.Pipeline, procList ...*model.Pro
|
|||||||
|
|
||||||
// calc pipeline number
|
// calc pipeline number
|
||||||
var number int64
|
var number int64
|
||||||
if _, err := sess.SQL("SELECT MAX(build_number) FROM `pipelines` WHERE build_repo_id = ?", pipeline.RepoID).Get(&number); err != nil {
|
if _, err := sess.SQL("SELECT MAX(pipeline_number) FROM `pipelines` WHERE pipeline_repo_id = ?", pipeline.RepoID).Get(&number); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pipeline.Number = number + 1
|
pipeline.Number = number + 1
|
||||||
@ -147,7 +147,7 @@ func deletePipeline(sess *xorm.Session, pipelineID int64) error {
|
|||||||
// delete related procs
|
// delete related procs
|
||||||
for startProcs := 0; ; startProcs += perPage {
|
for startProcs := 0; ; startProcs += perPage {
|
||||||
procIDs := make([]int64, 0, perPage)
|
procIDs := make([]int64, 0, perPage)
|
||||||
if err := sess.Limit(perPage, startProcs).Table("procs").Cols("proc_id").Where("proc_build_id = ?", pipelineID).Find(&procIDs); err != nil {
|
if err := sess.Limit(perPage, startProcs).Table("procs").Cols("proc_id").Where("proc_pipeline_id = ?", pipelineID).Find(&procIDs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(procIDs) == 0 {
|
if len(procIDs) == 0 {
|
||||||
@ -160,7 +160,7 @@ func deletePipeline(sess *xorm.Session, pipelineID int64) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := sess.Where("build_id = ?", pipelineID).Delete(new(model.PipelineConfig)); err != nil {
|
if _, err := sess.Where("pipeline_id = ?", pipelineID).Delete(new(model.PipelineConfig)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := sess.ID(pipelineID).Delete(new(model.Pipeline))
|
_, err := sess.ID(pipelineID).Delete(new(model.Pipeline))
|
||||||
|
@ -45,7 +45,7 @@ func (s storage) ProcChild(pipeline *model.Pipeline, ppid int, child string) (*m
|
|||||||
func (s storage) ProcList(pipeline *model.Pipeline) ([]*model.Proc, error) {
|
func (s storage) ProcList(pipeline *model.Pipeline) ([]*model.Proc, error) {
|
||||||
procList := make([]*model.Proc, 0, perPage)
|
procList := make([]*model.Proc, 0, perPage)
|
||||||
return procList, s.engine.
|
return procList, s.engine.
|
||||||
Where("proc_build_id = ?", pipeline.ID).
|
Where("proc_pipeline_id = ?", pipeline.ID).
|
||||||
OrderBy("proc_pid").
|
OrderBy("proc_pid").
|
||||||
Find(&procList)
|
Find(&procList)
|
||||||
}
|
}
|
||||||
@ -79,11 +79,11 @@ func (s storage) ProcClear(pipeline *model.Pipeline) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Where("file_build_id = ?", pipeline.ID).Delete(new(model.File)); err != nil {
|
if _, err := sess.Where("file_pipeline_id = ?", pipeline.ID).Delete(new(model.File)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Where("proc_build_id = ?", pipeline.ID).Delete(new(model.Proc)); err != nil {
|
if _, err := sess.Where("proc_pipeline_id = ?", pipeline.ID).Delete(new(model.Proc)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func (s storage) DeleteRepo(repo *model.Repo) error {
|
|||||||
// delete related pipelines
|
// delete related pipelines
|
||||||
for startPipelines := 0; ; startPipelines += batchSize {
|
for startPipelines := 0; ; startPipelines += batchSize {
|
||||||
pipelineIDs := make([]int64, 0, batchSize)
|
pipelineIDs := make([]int64, 0, batchSize)
|
||||||
if err := sess.Limit(batchSize, startPipelines).Table("pipelines").Cols("build_id").Where("build_repo_id = ?", repo.ID).Find(&pipelineIDs); err != nil {
|
if err := sess.Limit(batchSize, startPipelines).Table("pipelines").Cols("pipeline_id").Where("pipeline_repo_id = ?", repo.ID).Find(&pipelineIDs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(pipelineIDs) == 0 {
|
if len(pipelineIDs) == 0 {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import BuildStore from '~/store/pipelines';
|
import PipelineStore from '~/store/pipelines';
|
||||||
import RepoStore from '~/store/repos';
|
import RepoStore from '~/store/repos';
|
||||||
import { repoSlug } from '~/utils/helpers';
|
import { repoSlug } from '~/utils/helpers';
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ export default () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const repoStore = RepoStore();
|
const repoStore = RepoStore();
|
||||||
const buildStore = BuildStore();
|
const pipelineStore = PipelineStore();
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
@ -24,19 +24,19 @@ export default () => {
|
|||||||
const { repo } = data;
|
const { repo } = data;
|
||||||
repoStore.setRepo(repo);
|
repoStore.setRepo(repo);
|
||||||
|
|
||||||
// contains build update
|
// contains pipeline update
|
||||||
if (!data.pipeline) {
|
if (!data.pipeline) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { pipeline } = data;
|
const { pipeline } = data;
|
||||||
buildStore.setPipeline(repo.owner, repo.name, pipeline);
|
pipelineStore.setPipeline(repo.owner, repo.name, pipeline);
|
||||||
buildStore.setPipelineFeedItem({ ...pipeline, name: repo.name, owner: repo.owner, full_name: repoSlug(repo) });
|
pipelineStore.setPipelineFeedItem({ ...pipeline, name: repo.name, owner: repo.owner, full_name: repoSlug(repo) });
|
||||||
|
|
||||||
// contains proc update
|
// contains proc update
|
||||||
if (!data.proc) {
|
if (!data.proc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { proc } = data;
|
const { proc } = data;
|
||||||
buildStore.setProc(repo.owner, repo.name, pipeline.number, proc);
|
pipelineStore.setProc(repo.owner, repo.name, pipeline.number, proc);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ type RepoListOptions = {
|
|||||||
flush?: boolean;
|
flush?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type BuildOptions = {
|
type PipelineOptions = {
|
||||||
branch: string;
|
branch: string;
|
||||||
variables: Record<string, string>;
|
variables: Record<string, string>;
|
||||||
};
|
};
|
||||||
@ -58,7 +58,7 @@ export default class WoodpeckerClient extends ApiClient {
|
|||||||
return this._post(`/api/repos/${owner}/${repo}/repair`);
|
return this._post(`/api/repos/${owner}/${repo}/repair`);
|
||||||
}
|
}
|
||||||
|
|
||||||
createPipeline(owner: string, repo: string, options: BuildOptions): Promise<Pipeline> {
|
createPipeline(owner: string, repo: string, options: PipelineOptions): Promise<Pipeline> {
|
||||||
return this._post(`/api/repos/${owner}/${repo}/pipelines`, options) as Promise<Pipeline>;
|
return this._post(`/api/repos/${owner}/${repo}/pipelines`, options) as Promise<Pipeline>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
// A build for a repository.
|
// A pipeline for a repository.
|
||||||
export type Pipeline = {
|
export type Pipeline = {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
// The build number.
|
// The pipeline number.
|
||||||
// This number is specified within the context of the repository the build belongs to and is unique within that.
|
// This number is specified within the context of the repository the pipeline belongs to and is unique within that.
|
||||||
number: number;
|
number: number;
|
||||||
|
|
||||||
parent: number;
|
parent: number;
|
||||||
|
|
||||||
event: 'push' | 'tag' | 'pull_request' | 'deployment' | 'cron' | 'manual';
|
event: 'push' | 'tag' | 'pull_request' | 'deployment' | 'cron' | 'manual';
|
||||||
|
|
||||||
// The current status of the build.
|
// The current status of the pipeline.
|
||||||
status: PipelineStatus;
|
status: PipelineStatus;
|
||||||
|
|
||||||
error: string;
|
error: string;
|
||||||
|
|
||||||
// When the build request was received.
|
// When the pipeline request was received.
|
||||||
created_at: number;
|
created_at: number;
|
||||||
|
|
||||||
// When the build was updated last time in database.
|
// When the pipeline was updated last time in database.
|
||||||
updated_at: number;
|
updated_at: number;
|
||||||
|
|
||||||
// When the build was enqueued.
|
// When the pipeline was enqueued.
|
||||||
enqueued_at: number;
|
enqueued_at: number;
|
||||||
|
|
||||||
// When the build began execution.
|
// When the pipeline began execution.
|
||||||
started_at: number;
|
started_at: number;
|
||||||
|
|
||||||
// When the build was finished.
|
// When the pipeline was finished.
|
||||||
finished_at: number;
|
finished_at: number;
|
||||||
|
|
||||||
// Where the deployment should go.
|
// Where the deployment should go.
|
||||||
deploy_to: string;
|
deploy_to: string;
|
||||||
|
|
||||||
// The commit for the build.
|
// The commit for the pipeline.
|
||||||
commit: string;
|
commit: string;
|
||||||
|
|
||||||
// The branch the commit was pushed to.
|
// The branch the commit was pushed to.
|
||||||
@ -68,7 +68,7 @@ export type Pipeline = {
|
|||||||
author_email: string;
|
author_email: string;
|
||||||
|
|
||||||
// The link to view the repository.
|
// The link to view the repository.
|
||||||
// This link will point to the repository state associated with the build's commit.
|
// This link will point to the repository state associated with the pipeline's commit.
|
||||||
link_url: string;
|
link_url: string;
|
||||||
|
|
||||||
signed: boolean;
|
signed: boolean;
|
||||||
@ -79,8 +79,8 @@ export type Pipeline = {
|
|||||||
|
|
||||||
reviewed_at: number;
|
reviewed_at: number;
|
||||||
|
|
||||||
// The jobs associated with this build.
|
// The jobs associated with this pipeline.
|
||||||
// A build will have multiple jobs if a matrix build was used or if a rebuild was requested.
|
// A pipeline will have multiple jobs if a matrix pipeline was used or if a rebuild was requested.
|
||||||
procs?: PipelineProc[];
|
procs?: PipelineProc[];
|
||||||
|
|
||||||
changed_files?: string[];
|
changed_files?: string[];
|
||||||
@ -100,7 +100,7 @@ export type PipelineStatus =
|
|||||||
|
|
||||||
export type PipelineProc = {
|
export type PipelineProc = {
|
||||||
id: number;
|
id: number;
|
||||||
build_id: number;
|
pipeline_id: number;
|
||||||
pid: number;
|
pid: number;
|
||||||
ppid: number;
|
ppid: number;
|
||||||
pgid: number;
|
pgid: number;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// A config for a build.
|
// A config for a pipeline.
|
||||||
export type PipelineConfig = {
|
export type PipelineConfig = {
|
||||||
hash: string;
|
hash: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -35,16 +35,16 @@ export type Repo = {
|
|||||||
// Whether the repository is publicly visible.
|
// Whether the repository is publicly visible.
|
||||||
private: boolean;
|
private: boolean;
|
||||||
|
|
||||||
// Whether the repository has trusted access for builds.
|
// Whether the repository has trusted access for pipelines.
|
||||||
// If the repository is trusted then the host network can be used and
|
// If the repository is trusted then the host network can be used and
|
||||||
// volumes can be created.
|
// volumes can be created.
|
||||||
trusted: boolean;
|
trusted: boolean;
|
||||||
|
|
||||||
// x-dart-type: Duration
|
// x-dart-type: Duration
|
||||||
// The amount of time in minutes before the build is killed.
|
// The amount of time in minutes before the pipeline is killed.
|
||||||
timeout: number;
|
timeout: number;
|
||||||
|
|
||||||
// Whether pull requests should trigger a build.
|
// Whether pull requests should trigger a pipeline.
|
||||||
allow_pr: boolean;
|
allow_pr: boolean;
|
||||||
|
|
||||||
config_file: string;
|
config_file: string;
|
||||||
|
@ -54,7 +54,7 @@ type (
|
|||||||
Timeout *int64 `json:"timeout,omitempty"`
|
Timeout *int64 `json:"timeout,omitempty"`
|
||||||
Visibility *string `json:"visibility"`
|
Visibility *string `json:"visibility"`
|
||||||
AllowPull *bool `json:"allow_pr,omitempty"`
|
AllowPull *bool `json:"allow_pr,omitempty"`
|
||||||
PipelineCounter *int `json:"build_counter,omitempty"`
|
PipelineCounter *int `json:"pipeline_counter,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipeline defines a pipeline object.
|
// Pipeline defines a pipeline object.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user