From 51617e7f8637aa8e93564b96040a83b25c31d421 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 22 Nov 2021 12:55:13 +0100 Subject: [PATCH] Rename struct field and add new types into server/model's (#523) Resolve some todos in server/model: * Move persistent queue into its own package * Create Types: StatusValue, SCMKind, RepoVisibly * Rename struct Repo fields: SCMKind, IsSCMPrivate --- cli/repo/repo_info.go | 4 +- cmd/server/setup.go | 2 +- server/api/hook.go | 2 +- server/api/repo.go | 14 ++-- server/grpc/rpc.go | 14 ++-- server/model/build.go | 66 +++++++++---------- server/model/const.go | 45 +++++++------ server/model/perm.go | 19 +++--- server/model/proc.go | 2 +- server/model/repo.go | 46 ++++++------- server/queue/README.md | 12 ---- server/queue/fifo.go | 6 +- .../{model/queue.go => queue/persistent.go} | 30 ++++----- server/queue/queue.go | 4 +- server/remote/bitbucket/convert.go | 24 +++---- server/remote/bitbucket/convert_test.go | 4 +- server/remote/bitbucketserver/convert.go | 16 ++--- server/remote/bitbucketserver/convert_test.go | 4 +- server/remote/bitbucketserver/parse.go | 2 +- server/remote/coding/coding.go | 36 +++++----- server/remote/coding/coding_test.go | 22 +++---- server/remote/coding/hook.go | 2 +- server/remote/coding/hook_test.go | 10 +-- server/remote/gitea/gitea.go | 4 +- server/remote/gitea/gitea_test.go | 2 +- server/remote/gitea/helper.go | 18 ++--- server/remote/gitea/helper_test.go | 2 +- server/remote/github/convert.go | 42 ++++++------ server/remote/github/convert_test.go | 6 +- server/remote/github/github_test.go | 16 ++--- server/remote/gitlab/convert.go | 18 ++--- server/remote/gitlab/gitlab_test.go | 2 +- server/remote/gitlab/status.go | 4 +- server/remote/gogs/gogs_test.go | 2 +- server/remote/gogs/helper.go | 18 ++--- server/remote/gogs/helper_test.go | 2 +- server/shared/buildStatus.go | 2 +- server/shared/procBuilder.go | 8 +-- server/store/datastore/feed_test.go | 4 +- server/store/datastore/proc_test.go | 2 +- 40 files changed, 267 insertions(+), 271 deletions(-) delete mode 100644 server/queue/README.md rename server/{model/queue.go => queue/persistent.go} (80%) diff --git a/cli/repo/repo_info.go b/cli/repo/repo_info.go index ee4d66179..78b23a36e 100644 --- a/cli/repo/repo_info.go +++ b/cli/repo/repo_info.go @@ -47,10 +47,10 @@ func repoInfo(c *cli.Context) error { // template for repo information var tmplRepoInfo = `Owner: {{ .Owner }} Repo: {{ .Name }} -Type: {{ .Kind }} +Type: {{ .SCMKind }} Config: {{ .Config }} Visibility: {{ .Visibility }} -Private: {{ .IsPrivate }} +Private: {{ .IsSCMPrivate }} Trusted: {{ .IsTrusted }} Gated: {{ .IsGated }} Remote: {{ .Clone }} diff --git a/cmd/server/setup.go b/cmd/server/setup.go index 8e2e745e8..471441f3c 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -154,7 +154,7 @@ func fallbackSqlite3File(path string) (string, error) { } func setupQueue(c *cli.Context, s store.Store) queue.Queue { - return model.WithTaskStore(queue.New(), s) + return queue.WithTaskStore(queue.New(), s) } func setupSecretService(c *cli.Context, s store.Store) model.SecretService { diff --git a/server/api/hook.go b/server/api/hook.go index 061ee07a8..1e6de75a3 100644 --- a/server/api/hook.go +++ b/server/api/hook.go @@ -371,7 +371,7 @@ func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, - "private": strconv.FormatBool(repo.IsPrivate), + "private": strconv.FormatBool(repo.IsSCMPrivate), }, } buildCopy := *build diff --git a/server/api/repo.go b/server/api/repo.go index 855518623..96a220fe8 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -48,7 +48,7 @@ func PostRepo(c *gin.Context) { if repo.Visibility == "" { repo.Visibility = model.VisibilityPublic - if repo.IsPrivate { + if repo.IsSCMPrivate { repo.Visibility = model.VisibilityPrivate } } @@ -130,8 +130,8 @@ func PatchRepo(c *gin.Context) { } if in.Visibility != nil { switch *in.Visibility { - case model.VisibilityInternal, model.VisibilityPrivate, model.VisibilityPublic: - repo.Visibility = *in.Visibility + case string(model.VisibilityInternal), string(model.VisibilityPrivate), string(model.VisibilityPublic): + repo.Visibility = model.RepoVisibly(*in.Visibility) default: c.String(400, "Invalid visibility type") return @@ -256,8 +256,8 @@ func RepairRepo(c *gin.Context) { repo.Avatar = from.Avatar repo.Link = from.Link repo.Clone = from.Clone - repo.IsPrivate = from.IsPrivate - if repo.IsPrivate != from.IsPrivate { + repo.IsSCMPrivate = from.IsSCMPrivate + if repo.IsSCMPrivate != from.IsSCMPrivate { repo.ResetVisibility() } store_.UpdateRepo(repo) @@ -301,8 +301,8 @@ func MoveRepo(c *gin.Context) { repo.Avatar = from.Avatar repo.Link = from.Link repo.Clone = from.Clone - repo.IsPrivate = from.IsPrivate - if repo.IsPrivate != from.IsPrivate { + repo.IsSCMPrivate = from.IsSCMPrivate + if repo.IsSCMPrivate != from.IsSCMPrivate { repo.ResetVisibility() } diff --git a/server/grpc/rpc.go b/server/grpc/rpc.go index c5e7d0f53..57513bb8a 100644 --- a/server/grpc/rpc.go +++ b/server/grpc/rpc.go @@ -144,7 +144,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error { message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, - "private": strconv.FormatBool(repo.IsPrivate), + "private": strconv.FormatBool(repo.IsSCMPrivate), }, } message.Data, _ = json.Marshal(model.Event{ @@ -272,7 +272,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error { message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, - "private": strconv.FormatBool(repo.IsPrivate), + "private": strconv.FormatBool(repo.IsSCMPrivate), }, } message.Data, _ = json.Marshal(model.Event{ @@ -349,11 +349,11 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error { s.notify(c, repo, build, procs) if build.Status == model.StatusSuccess || build.Status == model.StatusFailure { - s.buildCount.WithLabelValues(repo.FullName, build.Branch, build.Status, "total").Inc() - s.buildTime.WithLabelValues(repo.FullName, build.Branch, build.Status, "total").Set(float64(build.Finished - build.Started)) + s.buildCount.WithLabelValues(repo.FullName, build.Branch, string(build.Status), "total").Inc() + s.buildTime.WithLabelValues(repo.FullName, build.Branch, string(build.Status), "total").Set(float64(build.Finished - build.Started)) } if isMultiPipeline(procs) { - s.buildTime.WithLabelValues(repo.FullName, build.Branch, proc.State, proc.Name).Set(float64(proc.Stopped - proc.Started)) + s.buildTime.WithLabelValues(repo.FullName, build.Branch, string(proc.State), proc.Name).Set(float64(proc.Stopped - proc.Started)) } return nil @@ -398,7 +398,7 @@ func isThereRunningStage(procs []*model.Proc) bool { return false } -func buildStatus(procs []*model.Proc) string { +func buildStatus(procs []*model.Proc) model.StatusValue { status := model.StatusSuccess for _, p := range procs { @@ -434,7 +434,7 @@ func (s *RPC) notify(c context.Context, repo *model.Repo, build *model.Build, pr message := pubsub.Message{ Labels: map[string]string{ "repo": repo.FullName, - "private": strconv.FormatBool(repo.IsPrivate), + "private": strconv.FormatBool(repo.IsSCMPrivate), }, } message.Data, _ = json.Marshal(model.Event{ diff --git a/server/model/build.go b/server/model/build.go index ae31e6077..0922618c2 100644 --- a/server/model/build.go +++ b/server/model/build.go @@ -17,39 +17,39 @@ package model // swagger:model build type Build struct { - ID int64 `json:"id" xorm:"pk autoincr 'build_id'"` - RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'build_repo_id'"` - Number int64 `json:"number" xorm:"UNIQUE(s) 'build_number'"` - Author string `json:"author" xorm:"INDEX 'build_author'"` - ConfigID int64 `json:"-" xorm:"build_config_id"` - Parent int64 `json:"parent" xorm:"build_parent"` - Event string `json:"event" xorm:"build_event"` - Status string `json:"status" xorm:"INDEX 'build_status'"` - Error string `json:"error" xorm:"build_error"` - Enqueued int64 `json:"enqueued_at" xorm:"build_enqueued"` - Created int64 `json:"created_at" xorm:"build_created"` - Started int64 `json:"started_at" xorm:"build_started"` - Finished int64 `json:"finished_at" xorm:"build_finished"` - Deploy string `json:"deploy_to" xorm:"build_deploy"` - Commit string `json:"commit" xorm:"build_commit"` - Branch string `json:"branch" xorm:"build_branch"` - Ref string `json:"ref" xorm:"build_ref"` - Refspec string `json:"refspec" xorm:"build_refspec"` - Remote string `json:"remote" xorm:"build_remote"` - Title string `json:"title" xorm:"build_title"` - Message string `json:"message" xorm:"build_message"` - Timestamp int64 `json:"timestamp" xorm:"build_timestamp"` - Sender string `json:"sender" xorm:"build_sender"` - Avatar string `json:"author_avatar" xorm:"build_avatar"` - Email string `json:"author_email" xorm:"build_email"` - Link string `json:"link_url" xorm:"build_link"` - Signed bool `json:"signed" xorm:"build_signed"` // deprecate - Verified bool `json:"verified" xorm:"build_verified"` // deprecate - Reviewer string `json:"reviewed_by" xorm:"build_reviewer"` - Reviewed int64 `json:"reviewed_at" xorm:"build_reviewed"` - Procs []*Proc `json:"procs,omitempty" xorm:"-"` - Files []*File `json:"files,omitempty" xorm:"-"` - ChangedFiles []string `json:"changed_files,omitempty" xorm:"json 'changed_files'"` + ID int64 `json:"id" xorm:"pk autoincr 'build_id'"` + RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'build_repo_id'"` + Number int64 `json:"number" xorm:"UNIQUE(s) 'build_number'"` + Author string `json:"author" xorm:"INDEX 'build_author'"` + ConfigID int64 `json:"-" xorm:"build_config_id"` + Parent int64 `json:"parent" xorm:"build_parent"` + Event string `json:"event" xorm:"build_event"` + Status StatusValue `json:"status" xorm:"INDEX 'build_status'"` + Error string `json:"error" xorm:"build_error"` + Enqueued int64 `json:"enqueued_at" xorm:"build_enqueued"` + Created int64 `json:"created_at" xorm:"build_created"` + Started int64 `json:"started_at" xorm:"build_started"` + Finished int64 `json:"finished_at" xorm:"build_finished"` + Deploy string `json:"deploy_to" xorm:"build_deploy"` + Commit string `json:"commit" xorm:"build_commit"` + Branch string `json:"branch" xorm:"build_branch"` + Ref string `json:"ref" xorm:"build_ref"` + Refspec string `json:"refspec" xorm:"build_refspec"` + Remote string `json:"remote" xorm:"build_remote"` + Title string `json:"title" xorm:"build_title"` + Message string `json:"message" xorm:"build_message"` + Timestamp int64 `json:"timestamp" xorm:"build_timestamp"` + Sender string `json:"sender" xorm:"build_sender"` + Avatar string `json:"author_avatar" xorm:"build_avatar"` + Email string `json:"author_email" xorm:"build_email"` + Link string `json:"link_url" xorm:"build_link"` + Signed bool `json:"signed" xorm:"build_signed"` // deprecate + Verified bool `json:"verified" xorm:"build_verified"` // deprecate + Reviewer string `json:"reviewed_by" xorm:"build_reviewer"` + Reviewed int64 `json:"reviewed_at" xorm:"build_reviewed"` + Procs []*Proc `json:"procs,omitempty" xorm:"-"` + Files []*File `json:"files,omitempty" xorm:"-"` + ChangedFiles []string `json:"changed_files,omitempty" xorm:"json 'changed_files'"` } // TableName return database table name for xorm diff --git a/server/model/const.go b/server/model/const.go index f550eb287..ae3258bd5 100644 --- a/server/model/const.go +++ b/server/model/const.go @@ -21,29 +21,36 @@ const ( EventDeploy = "deployment" ) -// TODO: type StatusValue string +// StatusValue represent pipeline states woodpecker know +type StatusValue string const ( - StatusSkipped = "skipped" - StatusPending = "pending" - StatusRunning = "running" - StatusSuccess = "success" - StatusFailure = "failure" - StatusKilled = "killed" - StatusError = "error" - StatusBlocked = "blocked" - StatusDeclined = "declined" + StatusSkipped StatusValue = "skipped" + StatusPending StatusValue = "pending" + StatusRunning StatusValue = "running" + StatusSuccess StatusValue = "success" + StatusFailure StatusValue = "failure" + StatusKilled StatusValue = "killed" + StatusError StatusValue = "error" + StatusBlocked StatusValue = "blocked" + StatusDeclined StatusValue = "declined" ) -const ( - RepoGit = "git" - RepoHg = "hg" - RepoFossil = "fossil" - RepoPerforce = "perforce" -) +// SCMKind represent different version control systems +type SCMKind string const ( - VisibilityPublic = "public" - VisibilityPrivate = "private" - VisibilityInternal = "internal" + RepoGit SCMKind = "git" + RepoHg SCMKind = "hg" + RepoFossil SCMKind = "fossil" + RepoPerforce SCMKind = "perforce" +) + +// RepoVisibly represent to wat state a repo in woodpecker is visible to others +type RepoVisibly string + +const ( + VisibilityPublic RepoVisibly = "public" + VisibilityPrivate RepoVisibly = "private" + VisibilityInternal RepoVisibly = "internal" ) diff --git a/server/model/perm.go b/server/model/perm.go index 13bc6a685..2d2abd7b1 100644 --- a/server/model/perm.go +++ b/server/model/perm.go @@ -25,16 +25,15 @@ type PermStore interface { // Perm defines a repository permission for an individual user. type Perm struct { - UserID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_user_id'"` - RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_repo_id'"` - Repo string `json:"-" xorm:"-"` // TODO: better caching (use type *Repo) - Pull bool `json:"pull" xorm:"perm_pull"` - Push bool `json:"push" xorm:"perm_push"` - Admin bool `json:"admin" xorm:"perm_admin"` - Synced int64 `json:"synced" xorm:"perm_synced"` - // TODO: after xorm switch make followup pull that utilize created & updated - // Created int64 `json:"created" xorm:"created"` - // Updated int64 `json:"updated" xorm:"updated"` + UserID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_user_id'"` + RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_repo_id'"` + Repo string `json:"-" xorm:"-"` // TODO: better caching (use type *Repo) + Pull bool `json:"pull" xorm:"perm_pull"` + Push bool `json:"push" xorm:"perm_push"` + Admin bool `json:"admin" xorm:"perm_admin"` + Synced int64 `json:"synced" xorm:"perm_synced"` + Created int64 `json:"created" xorm:"created"` + Updated int64 `json:"updated" xorm:"updated"` } // TableName return database table name for xorm diff --git a/server/model/proc.go b/server/model/proc.go index aca90be4f..89f3a7332 100644 --- a/server/model/proc.go +++ b/server/model/proc.go @@ -37,7 +37,7 @@ type Proc struct { PPID int `json:"ppid" xorm:"proc_ppid"` PGID int `json:"pgid" xorm:"proc_pgid"` Name string `json:"name" xorm:"proc_name"` - State string `json:"state" xorm:"proc_state"` + State StatusValue `json:"state" xorm:"proc_state"` Error string `json:"error,omitempty" xorm:"VARCHAR(500) proc_error"` ExitCode int `json:"exit_code" xorm:"proc_exit_code"` Started int64 `json:"start_time,omitempty" xorm:"proc_started"` diff --git a/server/model/repo.go b/server/model/repo.go index 4f725c4ea..6a154c6d4 100644 --- a/server/model/repo.go +++ b/server/model/repo.go @@ -24,24 +24,24 @@ import ( // // swagger:model repo type Repo struct { - ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"` - UserID int64 `json:"-" xorm:"repo_user_id"` - Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"` - Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"` - FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_name'"` - Avatar string `json:"avatar_url,omitempty" xorm:"varchar(500) 'repo_avatar'"` - Link string `json:"link_url,omitempty" xorm:"varchar(1000) 'repo_link'"` - Clone string `json:"clone_url,omitempty" xorm:"varchar(1000) 'repo_clone'"` - Branch string `json:"default_branch,omitempty" xorm:"varchar(500) 'repo_branch'"` - Kind string `json:"scm,omitempty" xorm:"varchar(50) 'repo_scm'"` // TODO: rename to `SCMKind` - Timeout int64 `json:"timeout,omitempty" xorm:"repo_timeout"` - Visibility string `json:"visibility" xorm:"varchar(10) 'repo_visibility'"` - IsPrivate bool `json:"private" xorm:"repo_private"` // TODO: Rename to `IsSCMPrivate` - IsTrusted bool `json:"trusted" xorm:"repo_trusted"` - IsStarred bool `json:"starred,omitempty" xorm:"-"` - IsGated bool `json:"gated" xorm:"repo_gated"` - IsActive bool `json:"active" xorm:"repo_active"` - AllowPull bool `json:"allow_pr" xorm:"repo_allow_pr"` + ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"` + UserID int64 `json:"-" xorm:"repo_user_id"` + Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"` + Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"` + FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_name'"` + Avatar string `json:"avatar_url,omitempty" xorm:"varchar(500) 'repo_avatar'"` + Link string `json:"link_url,omitempty" xorm:"varchar(1000) 'repo_link'"` + Clone string `json:"clone_url,omitempty" xorm:"varchar(1000) 'repo_clone'"` + Branch string `json:"default_branch,omitempty" xorm:"varchar(500) 'repo_branch'"` + SCMKind SCMKind `json:"scm,omitempty" xorm:"varchar(50) 'repo_scm'"` + Timeout int64 `json:"timeout,omitempty" xorm:"repo_timeout"` + Visibility RepoVisibly `json:"visibility" xorm:"varchar(10) 'repo_visibility'"` + IsSCMPrivate bool `json:"private" xorm:"repo_private"` + IsTrusted bool `json:"trusted" xorm:"repo_trusted"` + IsStarred bool `json:"starred,omitempty" xorm:"-"` + IsGated bool `json:"gated" xorm:"repo_gated"` + IsActive bool `json:"active" xorm:"repo_active"` + AllowPull bool `json:"allow_pr" xorm:"repo_allow_pr"` // Counter is used as index to determine new build numbers Counter int64 `json:"last_build" xorm:"NOT NULL DEFAULT 0 'repo_counter'"` Config string `json:"config_file" xorm:"varchar(500) 'repo_config_path'"` @@ -56,7 +56,7 @@ func (Repo) TableName() string { func (r *Repo) ResetVisibility() { r.Visibility = VisibilityPublic - if r.IsPrivate { + if r.IsSCMPrivate { r.Visibility = VisibilityPrivate } } @@ -77,17 +77,17 @@ func ParseRepo(str string) (user, repo string, err error) { func (r *Repo) Update(from *Repo) { r.Avatar = from.Avatar r.Link = from.Link - r.Kind = from.Kind + r.SCMKind = from.SCMKind r.Clone = from.Clone r.Branch = from.Branch - if from.IsPrivate != r.IsPrivate { - if from.IsPrivate { + if from.IsSCMPrivate != r.IsSCMPrivate { + if from.IsSCMPrivate { r.Visibility = VisibilityPrivate } else { r.Visibility = VisibilityPublic } } - r.IsPrivate = from.IsPrivate + r.IsSCMPrivate = from.IsSCMPrivate } // RepoPatch represents a repository patch object. diff --git a/server/queue/README.md b/server/queue/README.md deleted file mode 100644 index 5a3619a48..000000000 --- a/server/queue/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# queue package - -Go package provides a common interface for working with task queues. - -## History - -This was originally published in: https://github.com/cncd/queue -Then it was included in: https://github.com/drone-ci/drone/cncd/queue - -## Documentation: - -https://godoc.org/github.com/woodpecker-ci/woodpecker/server/queue diff --git a/server/queue/fifo.go b/server/queue/fifo.go index dae761df0..cc7a3e432 100644 --- a/server/queue/fifo.go +++ b/server/queue/fifo.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/woodpecker-ci/woodpecker/server/model" + "github.com/rs/zerolog/log" ) @@ -97,8 +99,8 @@ func (q *fifo) Poll(c context.Context, f Filter) (*Task, error) { } // Done signals that the item is done executing. -func (q *fifo) Done(c context.Context, id string, exitStatus string) error { - return q.finished([]string{id}, exitStatus, nil) +func (q *fifo) Done(c context.Context, id string, exitStatus model.StatusValue) error { + return q.finished([]string{id}, string(exitStatus), nil) } // Error signals that the item is done executing with error. diff --git a/server/model/queue.go b/server/queue/persistent.go similarity index 80% rename from server/model/queue.go rename to server/queue/persistent.go index 94ead8724..2205b3c1a 100644 --- a/server/model/queue.go +++ b/server/queue/persistent.go @@ -13,25 +13,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -package model +package queue import ( "context" "github.com/rs/zerolog/log" - "github.com/woodpecker-ci/woodpecker/server/queue" + "github.com/woodpecker-ci/woodpecker/server/model" ) -// TODO: move code to "github.com/woodpecker-ci/woodpecker/server/queue" - // WithTaskStore returns a queue that is backed by the TaskStore. This // ensures the task Queue can be restored when the system starts. -func WithTaskStore(q queue.Queue, s TaskStore) queue.Queue { +func WithTaskStore(q Queue, s model.TaskStore) Queue { tasks, _ := s.TaskList() - var toEnqueue []*queue.Task + var toEnqueue []*Task for _, task := range tasks { - toEnqueue = append(toEnqueue, &queue.Task{ + toEnqueue = append(toEnqueue, &Task{ ID: task.ID, Data: task.Data, Labels: task.Labels, @@ -45,13 +43,13 @@ func WithTaskStore(q queue.Queue, s TaskStore) queue.Queue { } type persistentQueue struct { - queue.Queue - store TaskStore + Queue + store model.TaskStore } // Push pushes a task to the tail of this queue. -func (q *persistentQueue) Push(c context.Context, task *queue.Task) error { - q.store.TaskInsert(&Task{ +func (q *persistentQueue) Push(c context.Context, task *Task) error { + q.store.TaskInsert(&model.Task{ ID: task.ID, Data: task.Data, Labels: task.Labels, @@ -65,10 +63,10 @@ func (q *persistentQueue) Push(c context.Context, task *queue.Task) error { return err } -// Push pushes multiple tasks to the tail of this queue. -func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*queue.Task) error { +// PushAtOnce pushes multiple tasks to the tail of this queue. +func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*Task) error { for _, task := range tasks { - q.store.TaskInsert(&Task{ + q.store.TaskInsert(&model.Task{ ID: task.ID, Data: task.Data, Labels: task.Labels, @@ -86,7 +84,7 @@ func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*queue.Task) err } // Poll retrieves and removes a task head of this queue. -func (q *persistentQueue) Poll(c context.Context, f queue.Filter) (*queue.Task, error) { +func (q *persistentQueue) Poll(c context.Context, f Filter) (*Task, error) { task, err := q.Queue.Poll(c, f) if task != nil { log.Debug().Msgf("pull queue item: %s: remove from backup", task.ID) @@ -108,7 +106,7 @@ func (q *persistentQueue) Evict(c context.Context, id string) error { return err } -// Evict removes a pending task from the queue. +// EvictAtOnce removes a pending task from the queue. func (q *persistentQueue) EvictAtOnce(c context.Context, ids []string) error { err := q.Queue.EvictAtOnce(c, ids) if err == nil { diff --git a/server/queue/queue.go b/server/queue/queue.go index 7d2f18c69..afb557278 100644 --- a/server/queue/queue.go +++ b/server/queue/queue.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "strings" + + "github.com/woodpecker-ci/woodpecker/server/model" ) var ( @@ -144,7 +146,7 @@ type Queue interface { Extend(c context.Context, id string) error // Done signals the task is complete. - Done(c context.Context, exitStatus string, id string) error + Done(c context.Context, id string, exitStatus model.StatusValue) error // Error signals the task is complete with errors. Error(c context.Context, id string, err error) error diff --git a/server/remote/bitbucket/convert.go b/server/remote/bitbucket/convert.go index 98f1e67ee..c5a13a11a 100644 --- a/server/remote/bitbucket/convert.go +++ b/server/remote/bitbucket/convert.go @@ -43,7 +43,7 @@ const ( // convertStatus is a helper function used to convert a Woodpecker status to a // Bitbucket commit status. -func convertStatus(status string) string { +func convertStatus(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning, model.StatusBlocked: return statusPending @@ -56,7 +56,7 @@ func convertStatus(status string) string { // convertDesc is a helper function used to convert a Woodpecker status to a // Bitbucket status description. -func convertDesc(status string) string { +func convertDesc(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning: return descPending @@ -77,17 +77,17 @@ func convertDesc(status string) string { // structure to the common Woodpecker repository structure. func convertRepo(from *internal.Repo) *model.Repo { repo := model.Repo{ - Clone: cloneLink(from), - Owner: strings.Split(from.FullName, "/")[0], - Name: strings.Split(from.FullName, "/")[1], - FullName: from.FullName, - Link: from.Links.Html.Href, - IsPrivate: from.IsPrivate, - Avatar: from.Owner.Links.Avatar.Href, - Kind: from.Scm, - Branch: "master", + Clone: cloneLink(from), + Owner: strings.Split(from.FullName, "/")[0], + Name: strings.Split(from.FullName, "/")[1], + FullName: from.FullName, + Link: from.Links.Html.Href, + IsSCMPrivate: from.IsPrivate, + Avatar: from.Owner.Links.Avatar.Href, + SCMKind: model.SCMKind(from.Scm), + Branch: "master", } - if repo.Kind == model.RepoHg { + if repo.SCMKind == model.RepoHg { repo.Branch = "default" } return &repo diff --git a/server/remote/bitbucket/convert_test.go b/server/remote/bitbucket/convert_test.go index 53ff07dc9..6491cf785 100644 --- a/server/remote/bitbucket/convert_test.go +++ b/server/remote/bitbucket/convert_test.go @@ -78,8 +78,8 @@ func Test_helper(t *testing.T) { g.Assert(to.Owner).Equal("octocat") g.Assert(to.Name).Equal("hello-world") g.Assert(to.Branch).Equal("default") - g.Assert(to.Kind).Equal(from.Scm) - g.Assert(to.IsPrivate).Equal(from.IsPrivate) + g.Assert(string(to.SCMKind)).Equal(from.Scm) + g.Assert(to.IsSCMPrivate).Equal(from.IsPrivate) g.Assert(to.Clone).Equal(from.Links.Html.Href) g.Assert(to.Link).Equal(from.Links.Html.Href) }) diff --git a/server/remote/bitbucketserver/convert.go b/server/remote/bitbucketserver/convert.go index 7ce609acb..2089ad1da 100644 --- a/server/remote/bitbucketserver/convert.go +++ b/server/remote/bitbucketserver/convert.go @@ -43,7 +43,7 @@ const ( // convertStatus is a helper function used to convert a Woodpecker status to a // Bitbucket commit status. -func convertStatus(status string) string { +func convertStatus(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning: return statusPending @@ -56,7 +56,7 @@ func convertStatus(status string) string { // convertDesc is a helper function used to convert a Woodpecker status to a // Bitbucket status description. -func convertDesc(status string) string { +func convertDesc(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning: return descPending @@ -74,12 +74,12 @@ func convertDesc(status string) string { func convertRepo(from *internal.Repo) *model.Repo { repo := model.Repo{ - Name: from.Slug, - Owner: from.Project.Key, - Branch: "master", - Kind: model.RepoGit, - IsPrivate: true, // Since we have to use Netrc it has to always be private :/ - FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug), + Name: from.Slug, + Owner: from.Project.Key, + Branch: "master", + SCMKind: model.RepoGit, + IsSCMPrivate: true, // Since we have to use Netrc it has to always be private :/ + FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug), } for _, item := range from.Links.Clone { diff --git a/server/remote/bitbucketserver/convert_test.go b/server/remote/bitbucketserver/convert_test.go index be50adbdb..f8a01fb8e 100644 --- a/server/remote/bitbucketserver/convert_test.go +++ b/server/remote/bitbucketserver/convert_test.go @@ -53,8 +53,8 @@ func Test_helper(t *testing.T) { g.Assert(to.Owner).Equal("octocat") g.Assert(to.Name).Equal("hello-world") g.Assert(to.Branch).Equal("master") - g.Assert(to.Kind).Equal(model.RepoGit) - g.Assert(to.IsPrivate).Equal(true) + g.Assert(to.SCMKind).Equal(model.RepoGit) + g.Assert(to.IsSCMPrivate).Equal(true) g.Assert(to.Clone).Equal("https://server.org/foo/bar.git") g.Assert(to.Link).Equal("https://server.org/foo/bar") }) diff --git a/server/remote/bitbucketserver/parse.go b/server/remote/bitbucketserver/parse.go index 6f92c43f3..1940a050d 100644 --- a/server/remote/bitbucketserver/parse.go +++ b/server/remote/bitbucketserver/parse.go @@ -36,7 +36,7 @@ func parseHook(r *http.Request, baseURL string) (*model.Repo, *model.Build, erro Owner: hook.Repository.Project.Key, FullName: fmt.Sprintf("%s/%s", hook.Repository.Project.Key, hook.Repository.Slug), Branch: "master", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } return repo, build, nil diff --git a/server/remote/coding/coding.go b/server/remote/coding/coding.go index 6b92d7343..9f3824e87 100644 --- a/server/remote/coding/coding.go +++ b/server/remote/coding/coding.go @@ -169,15 +169,15 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, owner, name string) (* return nil, err } return &model.Repo{ - Owner: project.Owner, - Name: project.Name, - FullName: projectFullName(project.Owner, project.Name), - Avatar: c.resourceLink(project.Icon), - Link: c.resourceLink(project.DepotPath), - Kind: model.RepoGit, - Clone: project.HttpsURL, - Branch: depot.DefaultBranch, - IsPrivate: !project.IsPublic, + Owner: project.Owner, + Name: project.Name, + FullName: projectFullName(project.Owner, project.Name), + Avatar: c.resourceLink(project.Icon), + Link: c.resourceLink(project.DepotPath), + SCMKind: model.RepoGit, + Clone: project.HttpsURL, + Branch: depot.DefaultBranch, + IsSCMPrivate: !project.IsPublic, }, nil } @@ -196,15 +196,15 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error return nil, err } repo := &model.Repo{ - Owner: project.Owner, - Name: project.Name, - FullName: projectFullName(project.Owner, project.Name), - Avatar: c.resourceLink(project.Icon), - Link: c.resourceLink(project.DepotPath), - Kind: model.RepoGit, - Clone: project.HttpsURL, - Branch: depot.DefaultBranch, - IsPrivate: !project.IsPublic, + Owner: project.Owner, + Name: project.Name, + FullName: projectFullName(project.Owner, project.Name), + Avatar: c.resourceLink(project.Icon), + Link: c.resourceLink(project.DepotPath), + SCMKind: model.RepoGit, + Clone: project.HttpsURL, + Branch: depot.DefaultBranch, + IsSCMPrivate: !project.IsPublic, } repos = append(repos, repo) } diff --git a/server/remote/coding/coding_test.go b/server/remote/coding/coding_test.go index 4b02b3eea..d958905c3 100644 --- a/server/remote/coding/coding_test.go +++ b/server/remote/coding/coding_test.go @@ -116,10 +116,10 @@ func Test_coding(t *testing.T) { g.Assert(repo.FullName).Equal(fakeRepo.FullName) g.Assert(repo.Avatar).Equal(s.URL + fakeRepo.Avatar) g.Assert(repo.Link).Equal(s.URL + fakeRepo.Link) - g.Assert(repo.Kind).Equal(fakeRepo.Kind) + g.Assert(repo.SCMKind).Equal(fakeRepo.SCMKind) g.Assert(repo.Clone).Equal(fakeRepo.Clone) g.Assert(repo.Branch).Equal(fakeRepo.Branch) - g.Assert(repo.IsPrivate).Equal(fakeRepo.IsPrivate) + g.Assert(repo.IsSCMPrivate).Equal(fakeRepo.IsSCMPrivate) }) g.It("Should handle not found errors", func() { _, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name) @@ -257,15 +257,15 @@ var ( } fakeRepo = &model.Repo{ - Owner: "demo1", - Name: "test1", - FullName: "demo1/test1", - Avatar: "/static/project_icon/scenery-5.png", - Link: "/u/gilala/p/abp/git", - Kind: model.RepoGit, - Clone: "https://git.coding.net/demo1/test1.git", - Branch: "master", - IsPrivate: true, + Owner: "demo1", + Name: "test1", + FullName: "demo1/test1", + Avatar: "/static/project_icon/scenery-5.png", + Link: "/u/gilala/p/abp/git", + SCMKind: model.RepoGit, + Clone: "https://git.coding.net/demo1/test1.git", + Branch: "master", + IsSCMPrivate: true, } fakeRepoNotFound = &model.Repo{ diff --git a/server/remote/coding/hook.go b/server/remote/coding/hook.go index f04c3b372..1964d33b7 100644 --- a/server/remote/coding/hook.go +++ b/server/remote/coding/hook.go @@ -141,7 +141,7 @@ func convertRepository(repo *Repository) (*model.Repo, error) { Name: repo.Name, FullName: projectFullName(repo.Owner.GlobalKey, repo.Name), Link: repo.WebURL, - Kind: model.RepoGit, + SCMKind: model.RepoGit, }, nil } diff --git a/server/remote/coding/hook_test.go b/server/remote/coding/hook_test.go index 71d59f6f8..41d566355 100644 --- a/server/remote/coding/hook_test.go +++ b/server/remote/coding/hook_test.go @@ -46,7 +46,7 @@ func Test_hook(t *testing.T) { Name: "test1", FullName: "demo1/test1", Link: "https://coding.net/u/demo1/p/test1", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } build := &model.Build{ @@ -99,7 +99,7 @@ func Test_hook(t *testing.T) { Name: "test_project", FullName: "kelvin/test_project", Link: "https://coding.net/u/kelvin/p/test_project", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } actual, err := convertRepository(repository) g.Assert(err).IsNil() @@ -113,7 +113,7 @@ func Test_hook(t *testing.T) { Name: "test1", FullName: "demo1/test1", Link: "https://coding.net/u/demo1/p/test1", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } build := &model.Build{ @@ -149,7 +149,7 @@ func Test_hook(t *testing.T) { Name: "test2", FullName: "demo1/test2", Link: "https://coding.net/u/demo1/p/test2", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } build := &model.Build{ @@ -179,7 +179,7 @@ func Test_hook(t *testing.T) { Name: "test1", FullName: "demo1/test1", Link: "https://coding.net/u/demo1/p/test1", - Kind: model.RepoGit, + SCMKind: model.RepoGit, } build := &model.Build{ diff --git a/server/remote/gitea/gitea.go b/server/remote/gitea/gitea.go index 0d7bded2f..925286df0 100644 --- a/server/remote/gitea/gitea.go +++ b/server/remote/gitea/gitea.go @@ -472,7 +472,7 @@ const ( // getStatus is a helper function that converts a Woodpecker // status to a Gitea status. -func getStatus(status string) gitea.StatusState { +func getStatus(status model.StatusValue) gitea.StatusState { switch status { case model.StatusPending, model.StatusBlocked: return gitea.StatusPending @@ -493,7 +493,7 @@ func getStatus(status string) gitea.StatusState { // getDesc is a helper function that generates a description // message for the build based on the status. -func getDesc(status string) string { +func getDesc(status model.StatusValue) string { switch status { case model.StatusPending: return DescPending diff --git a/server/remote/gitea/gitea_test.go b/server/remote/gitea/gitea_test.go index ecc00d544..79a430674 100644 --- a/server/remote/gitea/gitea_test.go +++ b/server/remote/gitea/gitea_test.go @@ -97,7 +97,7 @@ func Test_gitea(t *testing.T) { g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name) - g.Assert(repo.IsPrivate).IsTrue() + g.Assert(repo.IsSCMPrivate).IsTrue() g.Assert(repo.Clone).Equal("http://localhost/test_name/repo_name.git") g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name") }) diff --git a/server/remote/gitea/helper.go b/server/remote/gitea/helper.go index 56bdaa2fe..6d189f14f 100644 --- a/server/remote/gitea/helper.go +++ b/server/remote/gitea/helper.go @@ -39,15 +39,15 @@ func toRepo(from *gitea.Repository, privateMode bool) *model.Repo { private = true } return &model.Repo{ - Kind: model.RepoGit, - Name: name, - Owner: from.Owner.UserName, - FullName: from.FullName, - Avatar: avatar, - Link: from.HTMLURL, - IsPrivate: private, - Clone: from.CloneURL, - Branch: from.DefaultBranch, + SCMKind: model.RepoGit, + Name: name, + Owner: from.Owner.UserName, + FullName: from.FullName, + Avatar: avatar, + Link: from.HTMLURL, + IsSCMPrivate: private, + Clone: from.CloneURL, + Branch: from.DefaultBranch, } } diff --git a/server/remote/gitea/helper_test.go b/server/remote/gitea/helper_test.go index 16d28afcd..202ea90fa 100644 --- a/server/remote/gitea/helper_test.go +++ b/server/remote/gitea/helper_test.go @@ -216,7 +216,7 @@ func Test_parse(t *testing.T) { g.Assert(repo.Link).Equal(from.HTMLURL) g.Assert(repo.Clone).Equal(from.CloneURL) g.Assert(repo.Avatar).Equal(from.Owner.AvatarURL) - g.Assert(repo.IsPrivate).Equal(from.Private) + g.Assert(repo.IsSCMPrivate).Equal(from.Private) }) g.It("Should correct a malformed avatar url", func() { diff --git a/server/remote/github/convert.go b/server/remote/github/convert.go index ebcb486ca..6a79ebb5c 100644 --- a/server/remote/github/convert.go +++ b/server/remote/github/convert.go @@ -49,7 +49,7 @@ const ( // convertStatus is a helper function used to convert a Woodpecker status to a // GitHub commit status. -func convertStatus(status string) string { +func convertStatus(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning, model.StatusBlocked, model.StatusSkipped: return statusPending @@ -64,7 +64,7 @@ func convertStatus(status string) string { // convertDesc is a helper function used to convert a Woodpecker status to a // GitHub status description. -func convertDesc(status string) string { +func convertDesc(status model.StatusValue) string { switch status { case model.StatusPending, model.StatusRunning: return descPending @@ -85,22 +85,22 @@ func convertDesc(status string) string { // structure to the common Woodpecker repository structure. func convertRepo(from *github.Repository, private bool) *model.Repo { repo := &model.Repo{ - Owner: *from.Owner.Login, - Name: *from.Name, - FullName: *from.FullName, - Link: *from.HTMLURL, - IsPrivate: *from.Private, - Clone: *from.CloneURL, - Avatar: *from.Owner.AvatarURL, - Kind: model.RepoGit, - Branch: defaultBranch, - Perm: convertPerm(from), + Owner: *from.Owner.Login, + Name: *from.Name, + FullName: *from.FullName, + Link: *from.HTMLURL, + IsSCMPrivate: *from.Private, + Clone: *from.CloneURL, + Avatar: *from.Owner.AvatarURL, + SCMKind: model.RepoGit, + Branch: defaultBranch, + Perm: convertPerm(from), } if from.DefaultBranch != nil { repo.Branch = *from.DefaultBranch } if private { - repo.IsPrivate = true + repo.IsSCMPrivate = true } return repo } @@ -160,14 +160,14 @@ func convertTeam(from *github.Organization) *model.Team { // from a webhook and convert to the common Woodpecker repository structure. func convertRepoHook(from *webhook) *model.Repo { repo := &model.Repo{ - Owner: from.Repo.Owner.Login, - Name: from.Repo.Name, - FullName: from.Repo.FullName, - Link: from.Repo.HTMLURL, - IsPrivate: from.Repo.Private, - Clone: from.Repo.CloneURL, - Branch: from.Repo.DefaultBranch, - Kind: model.RepoGit, + Owner: from.Repo.Owner.Login, + Name: from.Repo.Name, + FullName: from.Repo.FullName, + Link: from.Repo.HTMLURL, + IsSCMPrivate: from.Repo.Private, + Clone: from.Repo.CloneURL, + Branch: from.Repo.DefaultBranch, + SCMKind: model.RepoGit, } if repo.Branch == "" { repo.Branch = defaultBranch diff --git a/server/remote/github/convert_test.go b/server/remote/github/convert_test.go index f98cb1e9a..b3f320e78 100644 --- a/server/remote/github/convert_test.go +++ b/server/remote/github/convert_test.go @@ -116,8 +116,8 @@ func Test_helper(t *testing.T) { g.Assert(to.Owner).Equal("octocat") g.Assert(to.Name).Equal("hello-world") g.Assert(to.Branch).Equal("develop") - g.Assert(to.Kind).Equal("git") - g.Assert(to.IsPrivate).IsTrue() + g.Assert(string(to.SCMKind)).Equal("git") + g.Assert(to.IsSCMPrivate).IsTrue() g.Assert(to.Clone).Equal("https://github.com/octocat/hello-world.git") g.Assert(to.Link).Equal("https://github.com/octocat/hello-world") }) @@ -174,7 +174,7 @@ func Test_helper(t *testing.T) { g.Assert(repo.Owner).Equal(from.Repo.Owner.Login) g.Assert(repo.Name).Equal(from.Repo.Name) g.Assert(repo.FullName).Equal(from.Repo.FullName) - g.Assert(repo.IsPrivate).Equal(from.Repo.Private) + g.Assert(repo.IsSCMPrivate).Equal(from.Repo.Private) g.Assert(repo.Link).Equal(from.Repo.HTMLURL) g.Assert(repo.Clone).Equal(from.Repo.CloneURL) g.Assert(repo.Branch).Equal(from.Repo.DefaultBranch) diff --git a/server/remote/github/github_test.go b/server/remote/github/github_test.go index 6b156e2ac..6ea68a6dd 100644 --- a/server/remote/github/github_test.go +++ b/server/remote/github/github_test.go @@ -102,7 +102,7 @@ func Test_github(t *testing.T) { g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.FullName).Equal(fakeRepo.FullName) - g.Assert(repo.IsPrivate).IsTrue() + g.Assert(repo.IsSCMPrivate).IsTrue() g.Assert(repo.Clone).Equal(fakeRepo.Clone) g.Assert(repo.Link).Equal(fakeRepo.Link) }) @@ -156,13 +156,13 @@ var ( } fakeRepo = &model.Repo{ - Owner: "octocat", - Name: "Hello-World", - FullName: "octocat/Hello-World", - Avatar: "https://github.com/images/error/octocat_happy.gif", - Link: "https://github.com/octocat/Hello-World", - Clone: "https://github.com/octocat/Hello-World.git", - IsPrivate: true, + Owner: "octocat", + Name: "Hello-World", + FullName: "octocat/Hello-World", + Avatar: "https://github.com/images/error/octocat_happy.gif", + Link: "https://github.com/octocat/Hello-World", + Clone: "https://github.com/octocat/Hello-World.git", + IsSCMPrivate: true, } fakeRepoNotFound = &model.Repo{ diff --git a/server/remote/gitlab/convert.go b/server/remote/gitlab/convert.go index 8ec7b70c5..4c96fec36 100644 --- a/server/remote/gitlab/convert.go +++ b/server/remote/gitlab/convert.go @@ -39,7 +39,7 @@ func (g *Gitlab) convertGitlabRepo(repo_ *gitlab.Project) (*model.Repo, error) { Link: repo_.WebURL, Clone: repo_.HTTPURLToRepo, Branch: repo_.DefaultBranch, - Visibility: string(repo_.Visibility), + Visibility: model.RepoVisibly(repo_.Visibility), } if len(repo.Branch) == 0 { // TODO: do we need that? @@ -51,9 +51,9 @@ func (g *Gitlab) convertGitlabRepo(repo_ *gitlab.Project) (*model.Repo, error) { } if g.PrivateMode { - repo.IsPrivate = true + repo.IsSCMPrivate = true } else { - repo.IsPrivate = !repo_.Public + repo.IsSCMPrivate = !repo_.Public } return repo, nil @@ -149,11 +149,11 @@ func convertPushHock(hook *gitlab.PushEvent) (*model.Repo, *model.Build, error) switch hook.Project.Visibility { case gitlab.PrivateVisibility: - repo.IsPrivate = true + repo.IsSCMPrivate = true case gitlab.InternalVisibility: - repo.IsPrivate = true + repo.IsSCMPrivate = true case gitlab.PublicVisibility: - repo.IsPrivate = false + repo.IsSCMPrivate = false } build.Event = model.EventPush @@ -194,11 +194,11 @@ func convertTagHock(hook *gitlab.TagEvent) (*model.Repo, *model.Build, error) { switch hook.Project.Visibility { case gitlab.PrivateVisibility: - repo.IsPrivate = true + repo.IsSCMPrivate = true case gitlab.InternalVisibility: - repo.IsPrivate = true + repo.IsSCMPrivate = true case gitlab.PublicVisibility: - repo.IsPrivate = false + repo.IsSCMPrivate = false } build.Event = model.EventTag diff --git a/server/remote/gitlab/gitlab_test.go b/server/remote/gitlab/gitlab_test.go index de9ea2a6f..0cfe40f05 100644 --- a/server/remote/gitlab/gitlab_test.go +++ b/server/remote/gitlab/gitlab_test.go @@ -97,7 +97,7 @@ func Test_Gitlab(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "diaspora-client", _repo.Name) assert.Equal(t, "diaspora", _repo.Owner) - assert.True(t, _repo.IsPrivate) + assert.True(t, _repo.IsSCMPrivate) }) g.It("Should return error, when repo not exist", func() { diff --git a/server/remote/gitlab/status.go b/server/remote/gitlab/status.go index e9355e0a1..490cc36ae 100644 --- a/server/remote/gitlab/status.go +++ b/server/remote/gitlab/status.go @@ -31,7 +31,7 @@ const ( ) // getStatus is a helper that converts a Woodpecker status to a Gitlab status. -func getStatus(status string) gitlab.BuildStateValue { +func getStatus(status model.StatusValue) gitlab.BuildStateValue { switch status { case model.StatusPending, model.StatusBlocked: return gitlab.Pending @@ -50,7 +50,7 @@ func getStatus(status string) gitlab.BuildStateValue { // getDesc is a helper function that generates a description // message for the build based on the status. -func getDesc(status string) string { +func getDesc(status model.StatusValue) string { switch status { case model.StatusPending: return DescPending diff --git a/server/remote/gogs/gogs_test.go b/server/remote/gogs/gogs_test.go index 2b2640f6e..5d07adb31 100644 --- a/server/remote/gogs/gogs_test.go +++ b/server/remote/gogs/gogs_test.go @@ -95,7 +95,7 @@ func Test_gogs(t *testing.T) { g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name) - g.Assert(repo.IsPrivate).IsTrue() + g.Assert(repo.IsSCMPrivate).IsTrue() g.Assert(repo.Clone).Equal("http://localhost/test_name/repo_name.git") g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name") }) diff --git a/server/remote/gogs/helper.go b/server/remote/gogs/helper.go index 8f2c69277..d711ae75b 100644 --- a/server/remote/gogs/helper.go +++ b/server/remote/gogs/helper.go @@ -39,15 +39,15 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo { private = true } return &model.Repo{ - Kind: model.RepoGit, - Name: name, - Owner: from.Owner.UserName, - FullName: from.FullName, - Avatar: avatar, - Link: from.HTMLURL, - IsPrivate: private, - Clone: from.CloneURL, - Branch: from.DefaultBranch, + SCMKind: model.RepoGit, + Name: name, + Owner: from.Owner.UserName, + FullName: from.FullName, + Avatar: avatar, + Link: from.HTMLURL, + IsSCMPrivate: private, + Clone: from.CloneURL, + Branch: from.DefaultBranch, } } diff --git a/server/remote/gogs/helper_test.go b/server/remote/gogs/helper_test.go index f6de1eeb6..6a6335fcc 100644 --- a/server/remote/gogs/helper_test.go +++ b/server/remote/gogs/helper_test.go @@ -188,7 +188,7 @@ func Test_parse(t *testing.T) { g.Assert(repo.Link).Equal(from.HTMLURL) g.Assert(repo.Clone).Equal(from.CloneURL) g.Assert(repo.Avatar).Equal(from.Owner.AvatarUrl) - g.Assert(repo.IsPrivate).Equal(from.Private) + g.Assert(repo.IsSCMPrivate).Equal(from.Private) }) g.It("Should correct a malformed avatar url", func() { diff --git a/server/shared/buildStatus.go b/server/shared/buildStatus.go index 8172e497c..2ac911aef 100644 --- a/server/shared/buildStatus.go +++ b/server/shared/buildStatus.go @@ -44,7 +44,7 @@ func UpdateToStatusDeclined(store UpdateBuildStore, build model.Build, reviewer return &build, store.UpdateBuild(&build) } -func UpdateStatusToDone(store UpdateBuildStore, build model.Build, status string, stopped int64) (*model.Build, error) { +func UpdateStatusToDone(store UpdateBuildStore, build model.Build, status model.StatusValue, stopped int64) (*model.Build, error) { build.Status = status build.Finished = stopped return &build, store.UpdateBuild(&build) diff --git a/server/shared/procBuilder.go b/server/shared/procBuilder.go index b16fc7337..c794e6233 100644 --- a/server/shared/procBuilder.go +++ b/server/shared/procBuilder.go @@ -233,7 +233,7 @@ func (b *ProcBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[ b.Netrc.Password, b.Netrc.Machine, ), - b.Repo.IsPrivate, + b.Repo.IsSCMPrivate, ), compiler.WithRegistry(registries...), compiler.WithSecret(secrets...), @@ -298,7 +298,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model. Name: repo.FullName, Link: repo.Link, Remote: repo.Clone, - Private: repo.IsPrivate, + Private: repo.IsSCMPrivate, Branch: repo.Branch, }, Curr: frontend.Build{ @@ -307,7 +307,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model. Created: build.Created, Started: build.Started, Finished: build.Finished, - Status: build.Status, + Status: string(build.Status), Event: build.Event, Link: build.Link, Target: build.Deploy, @@ -330,7 +330,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model. Created: last.Created, Started: last.Started, Finished: last.Finished, - Status: last.Status, + Status: string(last.Status), Event: last.Event, Link: last.Link, Target: last.Deploy, diff --git a/server/store/datastore/feed_test.go b/server/store/datastore/feed_test.go index 90f1e2d2a..4555e945e 100644 --- a/server/store/datastore/feed_test.go +++ b/server/store/datastore/feed_test.go @@ -91,13 +91,13 @@ func TestRepoListLatest(t *testing.T) { if got, want := len(builds), 2; got != want { t.Errorf("Want %d repositories, got %d", want, got) } - if got, want := builds[0].Status, model.StatusRunning; want != got { + if got, want := builds[0].Status, string(model.StatusRunning); want != got { t.Errorf("Want repository status %s, got %s", want, got) } if got, want := builds[0].FullName, repo1.FullName; want != got { t.Errorf("Want repository name %s, got %s", want, got) } - if got, want := builds[1].Status, model.StatusKilled; want != got { + if got, want := builds[1].Status, string(model.StatusKilled); want != got { t.Errorf("Want repository status %s, got %s", want, got) } if got, want := builds[1].FullName, repo2.FullName; want != got { diff --git a/server/store/datastore/proc_test.go b/server/store/datastore/proc_test.go index dd66467a5..de65ee272 100644 --- a/server/store/datastore/proc_test.go +++ b/server/store/datastore/proc_test.go @@ -164,7 +164,7 @@ func TestProcUpdate(t *testing.T) { t.Error(err) return } - if got, want := updated.State, "running"; got != want { + if got, want := updated.State, model.StatusRunning; got != want { t.Errorf("Want proc name %s, got %s", want, got) } }