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
This commit is contained in:
6543 2021-11-22 12:55:13 +01:00 committed by GitHub
parent d02dfe993f
commit 51617e7f86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 267 additions and 271 deletions

View file

@ -47,10 +47,10 @@ func repoInfo(c *cli.Context) error {
// template for repo information // template for repo information
var tmplRepoInfo = `Owner: {{ .Owner }} var tmplRepoInfo = `Owner: {{ .Owner }}
Repo: {{ .Name }} Repo: {{ .Name }}
Type: {{ .Kind }} Type: {{ .SCMKind }}
Config: {{ .Config }} Config: {{ .Config }}
Visibility: {{ .Visibility }} Visibility: {{ .Visibility }}
Private: {{ .IsPrivate }} Private: {{ .IsSCMPrivate }}
Trusted: {{ .IsTrusted }} Trusted: {{ .IsTrusted }}
Gated: {{ .IsGated }} Gated: {{ .IsGated }}
Remote: {{ .Clone }} Remote: {{ .Clone }}

View file

@ -154,7 +154,7 @@ func fallbackSqlite3File(path string) (string, error) {
} }
func setupQueue(c *cli.Context, s store.Store) queue.Queue { 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 { func setupSecretService(c *cli.Context, s store.Store) model.SecretService {

View file

@ -371,7 +371,7 @@ func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event
message := pubsub.Message{ message := pubsub.Message{
Labels: map[string]string{ Labels: map[string]string{
"repo": repo.FullName, "repo": repo.FullName,
"private": strconv.FormatBool(repo.IsPrivate), "private": strconv.FormatBool(repo.IsSCMPrivate),
}, },
} }
buildCopy := *build buildCopy := *build

View file

@ -48,7 +48,7 @@ func PostRepo(c *gin.Context) {
if repo.Visibility == "" { if repo.Visibility == "" {
repo.Visibility = model.VisibilityPublic repo.Visibility = model.VisibilityPublic
if repo.IsPrivate { if repo.IsSCMPrivate {
repo.Visibility = model.VisibilityPrivate repo.Visibility = model.VisibilityPrivate
} }
} }
@ -130,8 +130,8 @@ func PatchRepo(c *gin.Context) {
} }
if in.Visibility != nil { if in.Visibility != nil {
switch *in.Visibility { switch *in.Visibility {
case model.VisibilityInternal, model.VisibilityPrivate, model.VisibilityPublic: case string(model.VisibilityInternal), string(model.VisibilityPrivate), string(model.VisibilityPublic):
repo.Visibility = *in.Visibility repo.Visibility = model.RepoVisibly(*in.Visibility)
default: default:
c.String(400, "Invalid visibility type") c.String(400, "Invalid visibility type")
return return
@ -256,8 +256,8 @@ func RepairRepo(c *gin.Context) {
repo.Avatar = from.Avatar repo.Avatar = from.Avatar
repo.Link = from.Link repo.Link = from.Link
repo.Clone = from.Clone repo.Clone = from.Clone
repo.IsPrivate = from.IsPrivate repo.IsSCMPrivate = from.IsSCMPrivate
if repo.IsPrivate != from.IsPrivate { if repo.IsSCMPrivate != from.IsSCMPrivate {
repo.ResetVisibility() repo.ResetVisibility()
} }
store_.UpdateRepo(repo) store_.UpdateRepo(repo)
@ -301,8 +301,8 @@ func MoveRepo(c *gin.Context) {
repo.Avatar = from.Avatar repo.Avatar = from.Avatar
repo.Link = from.Link repo.Link = from.Link
repo.Clone = from.Clone repo.Clone = from.Clone
repo.IsPrivate = from.IsPrivate repo.IsSCMPrivate = from.IsSCMPrivate
if repo.IsPrivate != from.IsPrivate { if repo.IsSCMPrivate != from.IsSCMPrivate {
repo.ResetVisibility() repo.ResetVisibility()
} }

View file

@ -144,7 +144,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
message := pubsub.Message{ message := pubsub.Message{
Labels: map[string]string{ Labels: map[string]string{
"repo": repo.FullName, "repo": repo.FullName,
"private": strconv.FormatBool(repo.IsPrivate), "private": strconv.FormatBool(repo.IsSCMPrivate),
}, },
} }
message.Data, _ = json.Marshal(model.Event{ 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{ message := pubsub.Message{
Labels: map[string]string{ Labels: map[string]string{
"repo": repo.FullName, "repo": repo.FullName,
"private": strconv.FormatBool(repo.IsPrivate), "private": strconv.FormatBool(repo.IsSCMPrivate),
}, },
} }
message.Data, _ = json.Marshal(model.Event{ 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) s.notify(c, repo, build, procs)
if build.Status == model.StatusSuccess || build.Status == model.StatusFailure { if build.Status == model.StatusSuccess || build.Status == model.StatusFailure {
s.buildCount.WithLabelValues(repo.FullName, build.Branch, build.Status, "total").Inc() s.buildCount.WithLabelValues(repo.FullName, build.Branch, string(build.Status), "total").Inc()
s.buildTime.WithLabelValues(repo.FullName, build.Branch, build.Status, "total").Set(float64(build.Finished - build.Started)) s.buildTime.WithLabelValues(repo.FullName, build.Branch, string(build.Status), "total").Set(float64(build.Finished - build.Started))
} }
if isMultiPipeline(procs) { 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 return nil
@ -398,7 +398,7 @@ func isThereRunningStage(procs []*model.Proc) bool {
return false return false
} }
func buildStatus(procs []*model.Proc) string { func buildStatus(procs []*model.Proc) model.StatusValue {
status := model.StatusSuccess status := model.StatusSuccess
for _, p := range procs { 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{ message := pubsub.Message{
Labels: map[string]string{ Labels: map[string]string{
"repo": repo.FullName, "repo": repo.FullName,
"private": strconv.FormatBool(repo.IsPrivate), "private": strconv.FormatBool(repo.IsSCMPrivate),
}, },
} }
message.Data, _ = json.Marshal(model.Event{ message.Data, _ = json.Marshal(model.Event{

View file

@ -17,39 +17,39 @@ package model
// swagger:model build // swagger:model build
type Build struct { type Build struct {
ID int64 `json:"id" xorm:"pk autoincr 'build_id'"` ID int64 `json:"id" xorm:"pk autoincr 'build_id'"`
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'build_repo_id'"` RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'build_repo_id'"`
Number int64 `json:"number" xorm:"UNIQUE(s) 'build_number'"` Number int64 `json:"number" xorm:"UNIQUE(s) 'build_number'"`
Author string `json:"author" xorm:"INDEX 'build_author'"` Author string `json:"author" xorm:"INDEX 'build_author'"`
ConfigID int64 `json:"-" xorm:"build_config_id"` ConfigID int64 `json:"-" xorm:"build_config_id"`
Parent int64 `json:"parent" xorm:"build_parent"` Parent int64 `json:"parent" xorm:"build_parent"`
Event string `json:"event" xorm:"build_event"` Event string `json:"event" xorm:"build_event"`
Status string `json:"status" xorm:"INDEX 'build_status'"` Status StatusValue `json:"status" xorm:"INDEX 'build_status'"`
Error string `json:"error" xorm:"build_error"` Error string `json:"error" xorm:"build_error"`
Enqueued int64 `json:"enqueued_at" xorm:"build_enqueued"` Enqueued int64 `json:"enqueued_at" xorm:"build_enqueued"`
Created int64 `json:"created_at" xorm:"build_created"` Created int64 `json:"created_at" xorm:"build_created"`
Started int64 `json:"started_at" xorm:"build_started"` Started int64 `json:"started_at" xorm:"build_started"`
Finished int64 `json:"finished_at" xorm:"build_finished"` Finished int64 `json:"finished_at" xorm:"build_finished"`
Deploy string `json:"deploy_to" xorm:"build_deploy"` Deploy string `json:"deploy_to" xorm:"build_deploy"`
Commit string `json:"commit" xorm:"build_commit"` Commit string `json:"commit" xorm:"build_commit"`
Branch string `json:"branch" xorm:"build_branch"` Branch string `json:"branch" xorm:"build_branch"`
Ref string `json:"ref" xorm:"build_ref"` Ref string `json:"ref" xorm:"build_ref"`
Refspec string `json:"refspec" xorm:"build_refspec"` Refspec string `json:"refspec" xorm:"build_refspec"`
Remote string `json:"remote" xorm:"build_remote"` Remote string `json:"remote" xorm:"build_remote"`
Title string `json:"title" xorm:"build_title"` Title string `json:"title" xorm:"build_title"`
Message string `json:"message" xorm:"build_message"` Message string `json:"message" xorm:"build_message"`
Timestamp int64 `json:"timestamp" xorm:"build_timestamp"` Timestamp int64 `json:"timestamp" xorm:"build_timestamp"`
Sender string `json:"sender" xorm:"build_sender"` Sender string `json:"sender" xorm:"build_sender"`
Avatar string `json:"author_avatar" xorm:"build_avatar"` Avatar string `json:"author_avatar" xorm:"build_avatar"`
Email string `json:"author_email" xorm:"build_email"` Email string `json:"author_email" xorm:"build_email"`
Link string `json:"link_url" xorm:"build_link"` Link string `json:"link_url" xorm:"build_link"`
Signed bool `json:"signed" xorm:"build_signed"` // deprecate Signed bool `json:"signed" xorm:"build_signed"` // deprecate
Verified bool `json:"verified" xorm:"build_verified"` // deprecate Verified bool `json:"verified" xorm:"build_verified"` // deprecate
Reviewer string `json:"reviewed_by" xorm:"build_reviewer"` Reviewer string `json:"reviewed_by" xorm:"build_reviewer"`
Reviewed int64 `json:"reviewed_at" xorm:"build_reviewed"` Reviewed int64 `json:"reviewed_at" xorm:"build_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'"`
} }
// TableName return database table name for xorm // TableName return database table name for xorm

View file

@ -21,29 +21,36 @@ const (
EventDeploy = "deployment" EventDeploy = "deployment"
) )
// TODO: type StatusValue string // StatusValue represent pipeline states woodpecker know
type StatusValue string
const ( const (
StatusSkipped = "skipped" StatusSkipped StatusValue = "skipped"
StatusPending = "pending" StatusPending StatusValue = "pending"
StatusRunning = "running" StatusRunning StatusValue = "running"
StatusSuccess = "success" StatusSuccess StatusValue = "success"
StatusFailure = "failure" StatusFailure StatusValue = "failure"
StatusKilled = "killed" StatusKilled StatusValue = "killed"
StatusError = "error" StatusError StatusValue = "error"
StatusBlocked = "blocked" StatusBlocked StatusValue = "blocked"
StatusDeclined = "declined" StatusDeclined StatusValue = "declined"
) )
const ( // SCMKind represent different version control systems
RepoGit = "git" type SCMKind string
RepoHg = "hg"
RepoFossil = "fossil"
RepoPerforce = "perforce"
)
const ( const (
VisibilityPublic = "public" RepoGit SCMKind = "git"
VisibilityPrivate = "private" RepoHg SCMKind = "hg"
VisibilityInternal = "internal" 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"
) )

View file

@ -25,16 +25,15 @@ type PermStore interface {
// Perm defines a repository permission for an individual user. // Perm defines a repository permission for an individual user.
type Perm struct { type Perm struct {
UserID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_user_id'"` UserID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_user_id'"`
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_repo_id'"` RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX NOT NULL 'perm_repo_id'"`
Repo string `json:"-" xorm:"-"` // TODO: better caching (use type *Repo) Repo string `json:"-" xorm:"-"` // TODO: better caching (use type *Repo)
Pull bool `json:"pull" xorm:"perm_pull"` Pull bool `json:"pull" xorm:"perm_pull"`
Push bool `json:"push" xorm:"perm_push"` Push bool `json:"push" xorm:"perm_push"`
Admin bool `json:"admin" xorm:"perm_admin"` Admin bool `json:"admin" xorm:"perm_admin"`
Synced int64 `json:"synced" xorm:"perm_synced"` Synced int64 `json:"synced" xorm:"perm_synced"`
// TODO: after xorm switch make followup pull that utilize created & updated Created int64 `json:"created" xorm:"created"`
// Created int64 `json:"created" xorm:"created"` Updated int64 `json:"updated" xorm:"updated"`
// Updated int64 `json:"updated" xorm:"updated"`
} }
// TableName return database table name for xorm // TableName return database table name for xorm

View file

@ -37,7 +37,7 @@ type Proc struct {
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"`
Name string `json:"name" xorm:"proc_name"` 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"` Error string `json:"error,omitempty" xorm:"VARCHAR(500) proc_error"`
ExitCode int `json:"exit_code" xorm:"proc_exit_code"` ExitCode int `json:"exit_code" xorm:"proc_exit_code"`
Started int64 `json:"start_time,omitempty" xorm:"proc_started"` Started int64 `json:"start_time,omitempty" xorm:"proc_started"`

View file

@ -24,24 +24,24 @@ import (
// //
// swagger:model repo // swagger:model repo
type Repo struct { type Repo struct {
ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"` ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"`
UserID int64 `json:"-" xorm:"repo_user_id"` UserID int64 `json:"-" xorm:"repo_user_id"`
Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"` Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"`
Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"` Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"`
FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_name'"` FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_name'"`
Avatar string `json:"avatar_url,omitempty" xorm:"varchar(500) 'repo_avatar'"` Avatar string `json:"avatar_url,omitempty" xorm:"varchar(500) 'repo_avatar'"`
Link string `json:"link_url,omitempty" xorm:"varchar(1000) 'repo_link'"` Link string `json:"link_url,omitempty" xorm:"varchar(1000) 'repo_link'"`
Clone string `json:"clone_url,omitempty" xorm:"varchar(1000) 'repo_clone'"` Clone string `json:"clone_url,omitempty" xorm:"varchar(1000) 'repo_clone'"`
Branch string `json:"default_branch,omitempty" xorm:"varchar(500) 'repo_branch'"` 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` SCMKind SCMKind `json:"scm,omitempty" xorm:"varchar(50) 'repo_scm'"`
Timeout int64 `json:"timeout,omitempty" xorm:"repo_timeout"` Timeout int64 `json:"timeout,omitempty" xorm:"repo_timeout"`
Visibility string `json:"visibility" xorm:"varchar(10) 'repo_visibility'"` Visibility RepoVisibly `json:"visibility" xorm:"varchar(10) 'repo_visibility'"`
IsPrivate bool `json:"private" xorm:"repo_private"` // TODO: Rename to `IsSCMPrivate` IsSCMPrivate bool `json:"private" xorm:"repo_private"`
IsTrusted bool `json:"trusted" xorm:"repo_trusted"` IsTrusted bool `json:"trusted" xorm:"repo_trusted"`
IsStarred bool `json:"starred,omitempty" xorm:"-"` IsStarred bool `json:"starred,omitempty" xorm:"-"`
IsGated bool `json:"gated" xorm:"repo_gated"` IsGated bool `json:"gated" xorm:"repo_gated"`
IsActive bool `json:"active" xorm:"repo_active"` IsActive bool `json:"active" xorm:"repo_active"`
AllowPull bool `json:"allow_pr" xorm:"repo_allow_pr"` AllowPull bool `json:"allow_pr" xorm:"repo_allow_pr"`
// Counter is used as index to determine new build numbers // Counter is used as index to determine new build numbers
Counter int64 `json:"last_build" xorm:"NOT NULL DEFAULT 0 'repo_counter'"` Counter int64 `json:"last_build" xorm:"NOT NULL DEFAULT 0 'repo_counter'"`
Config string `json:"config_file" xorm:"varchar(500) 'repo_config_path'"` Config string `json:"config_file" xorm:"varchar(500) 'repo_config_path'"`
@ -56,7 +56,7 @@ func (Repo) TableName() string {
func (r *Repo) ResetVisibility() { func (r *Repo) ResetVisibility() {
r.Visibility = VisibilityPublic r.Visibility = VisibilityPublic
if r.IsPrivate { if r.IsSCMPrivate {
r.Visibility = VisibilityPrivate r.Visibility = VisibilityPrivate
} }
} }
@ -77,17 +77,17 @@ func ParseRepo(str string) (user, repo string, err error) {
func (r *Repo) Update(from *Repo) { func (r *Repo) Update(from *Repo) {
r.Avatar = from.Avatar r.Avatar = from.Avatar
r.Link = from.Link r.Link = from.Link
r.Kind = from.Kind r.SCMKind = from.SCMKind
r.Clone = from.Clone r.Clone = from.Clone
r.Branch = from.Branch r.Branch = from.Branch
if from.IsPrivate != r.IsPrivate { if from.IsSCMPrivate != r.IsSCMPrivate {
if from.IsPrivate { if from.IsSCMPrivate {
r.Visibility = VisibilityPrivate r.Visibility = VisibilityPrivate
} else { } else {
r.Visibility = VisibilityPublic r.Visibility = VisibilityPublic
} }
} }
r.IsPrivate = from.IsPrivate r.IsSCMPrivate = from.IsSCMPrivate
} }
// RepoPatch represents a repository patch object. // RepoPatch represents a repository patch object.

View file

@ -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

View file

@ -7,6 +7,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/rs/zerolog/log" "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. // Done signals that the item is done executing.
func (q *fifo) Done(c context.Context, id string, exitStatus string) error { func (q *fifo) Done(c context.Context, id string, exitStatus model.StatusValue) error {
return q.finished([]string{id}, exitStatus, nil) return q.finished([]string{id}, string(exitStatus), nil)
} }
// Error signals that the item is done executing with error. // Error signals that the item is done executing with error.

View file

@ -13,25 +13,23 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package model package queue
import ( import (
"context" "context"
"github.com/rs/zerolog/log" "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 // WithTaskStore returns a queue that is backed by the TaskStore. This
// ensures the task Queue can be restored when the system starts. // 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() tasks, _ := s.TaskList()
var toEnqueue []*queue.Task var toEnqueue []*Task
for _, task := range tasks { for _, task := range tasks {
toEnqueue = append(toEnqueue, &queue.Task{ toEnqueue = append(toEnqueue, &Task{
ID: task.ID, ID: task.ID,
Data: task.Data, Data: task.Data,
Labels: task.Labels, Labels: task.Labels,
@ -45,13 +43,13 @@ func WithTaskStore(q queue.Queue, s TaskStore) queue.Queue {
} }
type persistentQueue struct { type persistentQueue struct {
queue.Queue Queue
store TaskStore store model.TaskStore
} }
// Push pushes a task to the tail of this queue. // Push pushes a task to the tail of this queue.
func (q *persistentQueue) Push(c context.Context, task *queue.Task) error { func (q *persistentQueue) Push(c context.Context, task *Task) error {
q.store.TaskInsert(&Task{ q.store.TaskInsert(&model.Task{
ID: task.ID, ID: task.ID,
Data: task.Data, Data: task.Data,
Labels: task.Labels, Labels: task.Labels,
@ -65,10 +63,10 @@ func (q *persistentQueue) Push(c context.Context, task *queue.Task) error {
return err return err
} }
// Push pushes multiple tasks to the tail of this queue. // PushAtOnce pushes multiple tasks to the tail of this queue.
func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*queue.Task) error { func (q *persistentQueue) PushAtOnce(c context.Context, tasks []*Task) error {
for _, task := range tasks { for _, task := range tasks {
q.store.TaskInsert(&Task{ q.store.TaskInsert(&model.Task{
ID: task.ID, ID: task.ID,
Data: task.Data, Data: task.Data,
Labels: task.Labels, 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. // 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) task, err := q.Queue.Poll(c, f)
if task != nil { if task != nil {
log.Debug().Msgf("pull queue item: %s: remove from backup", task.ID) 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 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 { func (q *persistentQueue) EvictAtOnce(c context.Context, ids []string) error {
err := q.Queue.EvictAtOnce(c, ids) err := q.Queue.EvictAtOnce(c, ids)
if err == nil { if err == nil {

View file

@ -5,6 +5,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/server/model"
) )
var ( var (
@ -144,7 +146,7 @@ type Queue interface {
Extend(c context.Context, id string) error Extend(c context.Context, id string) error
// Done signals the task is complete. // 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 signals the task is complete with errors.
Error(c context.Context, id string, err error) error Error(c context.Context, id string, err error) error

View file

@ -43,7 +43,7 @@ const (
// convertStatus is a helper function used to convert a Woodpecker status to a // convertStatus is a helper function used to convert a Woodpecker status to a
// Bitbucket commit status. // Bitbucket commit status.
func convertStatus(status string) string { func convertStatus(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning, model.StatusBlocked: case model.StatusPending, model.StatusRunning, model.StatusBlocked:
return statusPending return statusPending
@ -56,7 +56,7 @@ func convertStatus(status string) string {
// convertDesc is a helper function used to convert a Woodpecker status to a // convertDesc is a helper function used to convert a Woodpecker status to a
// Bitbucket status description. // Bitbucket status description.
func convertDesc(status string) string { func convertDesc(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning: case model.StatusPending, model.StatusRunning:
return descPending return descPending
@ -77,17 +77,17 @@ func convertDesc(status string) string {
// structure to the common Woodpecker repository structure. // structure to the common Woodpecker repository structure.
func convertRepo(from *internal.Repo) *model.Repo { func convertRepo(from *internal.Repo) *model.Repo {
repo := model.Repo{ repo := model.Repo{
Clone: cloneLink(from), Clone: cloneLink(from),
Owner: strings.Split(from.FullName, "/")[0], Owner: strings.Split(from.FullName, "/")[0],
Name: strings.Split(from.FullName, "/")[1], Name: strings.Split(from.FullName, "/")[1],
FullName: from.FullName, FullName: from.FullName,
Link: from.Links.Html.Href, Link: from.Links.Html.Href,
IsPrivate: from.IsPrivate, IsSCMPrivate: from.IsPrivate,
Avatar: from.Owner.Links.Avatar.Href, Avatar: from.Owner.Links.Avatar.Href,
Kind: from.Scm, SCMKind: model.SCMKind(from.Scm),
Branch: "master", Branch: "master",
} }
if repo.Kind == model.RepoHg { if repo.SCMKind == model.RepoHg {
repo.Branch = "default" repo.Branch = "default"
} }
return &repo return &repo

View file

@ -78,8 +78,8 @@ func Test_helper(t *testing.T) {
g.Assert(to.Owner).Equal("octocat") g.Assert(to.Owner).Equal("octocat")
g.Assert(to.Name).Equal("hello-world") g.Assert(to.Name).Equal("hello-world")
g.Assert(to.Branch).Equal("default") g.Assert(to.Branch).Equal("default")
g.Assert(to.Kind).Equal(from.Scm) g.Assert(string(to.SCMKind)).Equal(from.Scm)
g.Assert(to.IsPrivate).Equal(from.IsPrivate) g.Assert(to.IsSCMPrivate).Equal(from.IsPrivate)
g.Assert(to.Clone).Equal(from.Links.Html.Href) g.Assert(to.Clone).Equal(from.Links.Html.Href)
g.Assert(to.Link).Equal(from.Links.Html.Href) g.Assert(to.Link).Equal(from.Links.Html.Href)
}) })

View file

@ -43,7 +43,7 @@ const (
// convertStatus is a helper function used to convert a Woodpecker status to a // convertStatus is a helper function used to convert a Woodpecker status to a
// Bitbucket commit status. // Bitbucket commit status.
func convertStatus(status string) string { func convertStatus(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning: case model.StatusPending, model.StatusRunning:
return statusPending return statusPending
@ -56,7 +56,7 @@ func convertStatus(status string) string {
// convertDesc is a helper function used to convert a Woodpecker status to a // convertDesc is a helper function used to convert a Woodpecker status to a
// Bitbucket status description. // Bitbucket status description.
func convertDesc(status string) string { func convertDesc(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning: case model.StatusPending, model.StatusRunning:
return descPending return descPending
@ -74,12 +74,12 @@ func convertDesc(status string) string {
func convertRepo(from *internal.Repo) *model.Repo { func convertRepo(from *internal.Repo) *model.Repo {
repo := model.Repo{ repo := model.Repo{
Name: from.Slug, Name: from.Slug,
Owner: from.Project.Key, Owner: from.Project.Key,
Branch: "master", Branch: "master",
Kind: model.RepoGit, SCMKind: model.RepoGit,
IsPrivate: true, // Since we have to use Netrc it has to always be private :/ IsSCMPrivate: true, // Since we have to use Netrc it has to always be private :/
FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug), FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug),
} }
for _, item := range from.Links.Clone { for _, item := range from.Links.Clone {

View file

@ -53,8 +53,8 @@ func Test_helper(t *testing.T) {
g.Assert(to.Owner).Equal("octocat") g.Assert(to.Owner).Equal("octocat")
g.Assert(to.Name).Equal("hello-world") g.Assert(to.Name).Equal("hello-world")
g.Assert(to.Branch).Equal("master") g.Assert(to.Branch).Equal("master")
g.Assert(to.Kind).Equal(model.RepoGit) g.Assert(to.SCMKind).Equal(model.RepoGit)
g.Assert(to.IsPrivate).Equal(true) g.Assert(to.IsSCMPrivate).Equal(true)
g.Assert(to.Clone).Equal("https://server.org/foo/bar.git") g.Assert(to.Clone).Equal("https://server.org/foo/bar.git")
g.Assert(to.Link).Equal("https://server.org/foo/bar") g.Assert(to.Link).Equal("https://server.org/foo/bar")
}) })

View file

@ -36,7 +36,7 @@ func parseHook(r *http.Request, baseURL string) (*model.Repo, *model.Build, erro
Owner: hook.Repository.Project.Key, Owner: hook.Repository.Project.Key,
FullName: fmt.Sprintf("%s/%s", hook.Repository.Project.Key, hook.Repository.Slug), FullName: fmt.Sprintf("%s/%s", hook.Repository.Project.Key, hook.Repository.Slug),
Branch: "master", Branch: "master",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
return repo, build, nil return repo, build, nil

View file

@ -169,15 +169,15 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, owner, name string) (*
return nil, err return nil, err
} }
return &model.Repo{ return &model.Repo{
Owner: project.Owner, Owner: project.Owner,
Name: project.Name, Name: project.Name,
FullName: projectFullName(project.Owner, project.Name), FullName: projectFullName(project.Owner, project.Name),
Avatar: c.resourceLink(project.Icon), Avatar: c.resourceLink(project.Icon),
Link: c.resourceLink(project.DepotPath), Link: c.resourceLink(project.DepotPath),
Kind: model.RepoGit, SCMKind: model.RepoGit,
Clone: project.HttpsURL, Clone: project.HttpsURL,
Branch: depot.DefaultBranch, Branch: depot.DefaultBranch,
IsPrivate: !project.IsPublic, IsSCMPrivate: !project.IsPublic,
}, nil }, nil
} }
@ -196,15 +196,15 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
return nil, err return nil, err
} }
repo := &model.Repo{ repo := &model.Repo{
Owner: project.Owner, Owner: project.Owner,
Name: project.Name, Name: project.Name,
FullName: projectFullName(project.Owner, project.Name), FullName: projectFullName(project.Owner, project.Name),
Avatar: c.resourceLink(project.Icon), Avatar: c.resourceLink(project.Icon),
Link: c.resourceLink(project.DepotPath), Link: c.resourceLink(project.DepotPath),
Kind: model.RepoGit, SCMKind: model.RepoGit,
Clone: project.HttpsURL, Clone: project.HttpsURL,
Branch: depot.DefaultBranch, Branch: depot.DefaultBranch,
IsPrivate: !project.IsPublic, IsSCMPrivate: !project.IsPublic,
} }
repos = append(repos, repo) repos = append(repos, repo)
} }

View file

@ -116,10 +116,10 @@ func Test_coding(t *testing.T) {
g.Assert(repo.FullName).Equal(fakeRepo.FullName) g.Assert(repo.FullName).Equal(fakeRepo.FullName)
g.Assert(repo.Avatar).Equal(s.URL + fakeRepo.Avatar) g.Assert(repo.Avatar).Equal(s.URL + fakeRepo.Avatar)
g.Assert(repo.Link).Equal(s.URL + fakeRepo.Link) 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.Clone).Equal(fakeRepo.Clone)
g.Assert(repo.Branch).Equal(fakeRepo.Branch) 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() { g.It("Should handle not found errors", func() {
_, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name) _, err := c.Repo(ctx, fakeUser, fakeRepoNotFound.Owner, fakeRepoNotFound.Name)
@ -257,15 +257,15 @@ var (
} }
fakeRepo = &model.Repo{ fakeRepo = &model.Repo{
Owner: "demo1", Owner: "demo1",
Name: "test1", Name: "test1",
FullName: "demo1/test1", FullName: "demo1/test1",
Avatar: "/static/project_icon/scenery-5.png", Avatar: "/static/project_icon/scenery-5.png",
Link: "/u/gilala/p/abp/git", Link: "/u/gilala/p/abp/git",
Kind: model.RepoGit, SCMKind: model.RepoGit,
Clone: "https://git.coding.net/demo1/test1.git", Clone: "https://git.coding.net/demo1/test1.git",
Branch: "master", Branch: "master",
IsPrivate: true, IsSCMPrivate: true,
} }
fakeRepoNotFound = &model.Repo{ fakeRepoNotFound = &model.Repo{

View file

@ -141,7 +141,7 @@ func convertRepository(repo *Repository) (*model.Repo, error) {
Name: repo.Name, Name: repo.Name,
FullName: projectFullName(repo.Owner.GlobalKey, repo.Name), FullName: projectFullName(repo.Owner.GlobalKey, repo.Name),
Link: repo.WebURL, Link: repo.WebURL,
Kind: model.RepoGit, SCMKind: model.RepoGit,
}, nil }, nil
} }

View file

@ -46,7 +46,7 @@ func Test_hook(t *testing.T) {
Name: "test1", Name: "test1",
FullName: "demo1/test1", FullName: "demo1/test1",
Link: "https://coding.net/u/demo1/p/test1", Link: "https://coding.net/u/demo1/p/test1",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
build := &model.Build{ build := &model.Build{
@ -99,7 +99,7 @@ func Test_hook(t *testing.T) {
Name: "test_project", Name: "test_project",
FullName: "kelvin/test_project", FullName: "kelvin/test_project",
Link: "https://coding.net/u/kelvin/p/test_project", Link: "https://coding.net/u/kelvin/p/test_project",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
actual, err := convertRepository(repository) actual, err := convertRepository(repository)
g.Assert(err).IsNil() g.Assert(err).IsNil()
@ -113,7 +113,7 @@ func Test_hook(t *testing.T) {
Name: "test1", Name: "test1",
FullName: "demo1/test1", FullName: "demo1/test1",
Link: "https://coding.net/u/demo1/p/test1", Link: "https://coding.net/u/demo1/p/test1",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
build := &model.Build{ build := &model.Build{
@ -149,7 +149,7 @@ func Test_hook(t *testing.T) {
Name: "test2", Name: "test2",
FullName: "demo1/test2", FullName: "demo1/test2",
Link: "https://coding.net/u/demo1/p/test2", Link: "https://coding.net/u/demo1/p/test2",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
build := &model.Build{ build := &model.Build{
@ -179,7 +179,7 @@ func Test_hook(t *testing.T) {
Name: "test1", Name: "test1",
FullName: "demo1/test1", FullName: "demo1/test1",
Link: "https://coding.net/u/demo1/p/test1", Link: "https://coding.net/u/demo1/p/test1",
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
build := &model.Build{ build := &model.Build{

View file

@ -472,7 +472,7 @@ const (
// getStatus is a helper function that converts a Woodpecker // getStatus is a helper function that converts a Woodpecker
// status to a Gitea status. // status to a Gitea status.
func getStatus(status string) gitea.StatusState { func getStatus(status model.StatusValue) gitea.StatusState {
switch status { switch status {
case model.StatusPending, model.StatusBlocked: case model.StatusPending, model.StatusBlocked:
return gitea.StatusPending return gitea.StatusPending
@ -493,7 +493,7 @@ func getStatus(status string) gitea.StatusState {
// getDesc is a helper function that generates a description // getDesc is a helper function that generates a description
// message for the build based on the status. // message for the build based on the status.
func getDesc(status string) string { func getDesc(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending: case model.StatusPending:
return DescPending return DescPending

View file

@ -97,7 +97,7 @@ func Test_gitea(t *testing.T) {
g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Owner).Equal(fakeRepo.Owner)
g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.Name).Equal(fakeRepo.Name)
g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + 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.Clone).Equal("http://localhost/test_name/repo_name.git")
g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name") g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name")
}) })

View file

@ -39,15 +39,15 @@ func toRepo(from *gitea.Repository, privateMode bool) *model.Repo {
private = true private = true
} }
return &model.Repo{ return &model.Repo{
Kind: model.RepoGit, SCMKind: model.RepoGit,
Name: name, Name: name,
Owner: from.Owner.UserName, Owner: from.Owner.UserName,
FullName: from.FullName, FullName: from.FullName,
Avatar: avatar, Avatar: avatar,
Link: from.HTMLURL, Link: from.HTMLURL,
IsPrivate: private, IsSCMPrivate: private,
Clone: from.CloneURL, Clone: from.CloneURL,
Branch: from.DefaultBranch, Branch: from.DefaultBranch,
} }
} }

View file

@ -216,7 +216,7 @@ func Test_parse(t *testing.T) {
g.Assert(repo.Link).Equal(from.HTMLURL) g.Assert(repo.Link).Equal(from.HTMLURL)
g.Assert(repo.Clone).Equal(from.CloneURL) g.Assert(repo.Clone).Equal(from.CloneURL)
g.Assert(repo.Avatar).Equal(from.Owner.AvatarURL) 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() { g.It("Should correct a malformed avatar url", func() {

View file

@ -49,7 +49,7 @@ const (
// convertStatus is a helper function used to convert a Woodpecker status to a // convertStatus is a helper function used to convert a Woodpecker status to a
// GitHub commit status. // GitHub commit status.
func convertStatus(status string) string { func convertStatus(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning, model.StatusBlocked, model.StatusSkipped: case model.StatusPending, model.StatusRunning, model.StatusBlocked, model.StatusSkipped:
return statusPending return statusPending
@ -64,7 +64,7 @@ func convertStatus(status string) string {
// convertDesc is a helper function used to convert a Woodpecker status to a // convertDesc is a helper function used to convert a Woodpecker status to a
// GitHub status description. // GitHub status description.
func convertDesc(status string) string { func convertDesc(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending, model.StatusRunning: case model.StatusPending, model.StatusRunning:
return descPending return descPending
@ -85,22 +85,22 @@ func convertDesc(status string) string {
// structure to the common Woodpecker repository structure. // structure to the common Woodpecker repository structure.
func convertRepo(from *github.Repository, private bool) *model.Repo { func convertRepo(from *github.Repository, private bool) *model.Repo {
repo := &model.Repo{ repo := &model.Repo{
Owner: *from.Owner.Login, Owner: *from.Owner.Login,
Name: *from.Name, Name: *from.Name,
FullName: *from.FullName, FullName: *from.FullName,
Link: *from.HTMLURL, Link: *from.HTMLURL,
IsPrivate: *from.Private, IsSCMPrivate: *from.Private,
Clone: *from.CloneURL, Clone: *from.CloneURL,
Avatar: *from.Owner.AvatarURL, Avatar: *from.Owner.AvatarURL,
Kind: model.RepoGit, SCMKind: model.RepoGit,
Branch: defaultBranch, Branch: defaultBranch,
Perm: convertPerm(from), Perm: convertPerm(from),
} }
if from.DefaultBranch != nil { if from.DefaultBranch != nil {
repo.Branch = *from.DefaultBranch repo.Branch = *from.DefaultBranch
} }
if private { if private {
repo.IsPrivate = true repo.IsSCMPrivate = true
} }
return repo return repo
} }
@ -160,14 +160,14 @@ func convertTeam(from *github.Organization) *model.Team {
// from a webhook and convert to the common Woodpecker repository structure. // from a webhook and convert to the common Woodpecker repository structure.
func convertRepoHook(from *webhook) *model.Repo { func convertRepoHook(from *webhook) *model.Repo {
repo := &model.Repo{ repo := &model.Repo{
Owner: from.Repo.Owner.Login, Owner: from.Repo.Owner.Login,
Name: from.Repo.Name, Name: from.Repo.Name,
FullName: from.Repo.FullName, FullName: from.Repo.FullName,
Link: from.Repo.HTMLURL, Link: from.Repo.HTMLURL,
IsPrivate: from.Repo.Private, IsSCMPrivate: from.Repo.Private,
Clone: from.Repo.CloneURL, Clone: from.Repo.CloneURL,
Branch: from.Repo.DefaultBranch, Branch: from.Repo.DefaultBranch,
Kind: model.RepoGit, SCMKind: model.RepoGit,
} }
if repo.Branch == "" { if repo.Branch == "" {
repo.Branch = defaultBranch repo.Branch = defaultBranch

View file

@ -116,8 +116,8 @@ func Test_helper(t *testing.T) {
g.Assert(to.Owner).Equal("octocat") g.Assert(to.Owner).Equal("octocat")
g.Assert(to.Name).Equal("hello-world") g.Assert(to.Name).Equal("hello-world")
g.Assert(to.Branch).Equal("develop") g.Assert(to.Branch).Equal("develop")
g.Assert(to.Kind).Equal("git") g.Assert(string(to.SCMKind)).Equal("git")
g.Assert(to.IsPrivate).IsTrue() g.Assert(to.IsSCMPrivate).IsTrue()
g.Assert(to.Clone).Equal("https://github.com/octocat/hello-world.git") g.Assert(to.Clone).Equal("https://github.com/octocat/hello-world.git")
g.Assert(to.Link).Equal("https://github.com/octocat/hello-world") 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.Owner).Equal(from.Repo.Owner.Login)
g.Assert(repo.Name).Equal(from.Repo.Name) g.Assert(repo.Name).Equal(from.Repo.Name)
g.Assert(repo.FullName).Equal(from.Repo.FullName) 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.Link).Equal(from.Repo.HTMLURL)
g.Assert(repo.Clone).Equal(from.Repo.CloneURL) g.Assert(repo.Clone).Equal(from.Repo.CloneURL)
g.Assert(repo.Branch).Equal(from.Repo.DefaultBranch) g.Assert(repo.Branch).Equal(from.Repo.DefaultBranch)

View file

@ -102,7 +102,7 @@ func Test_github(t *testing.T) {
g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Owner).Equal(fakeRepo.Owner)
g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.Name).Equal(fakeRepo.Name)
g.Assert(repo.FullName).Equal(fakeRepo.FullName) 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.Clone).Equal(fakeRepo.Clone)
g.Assert(repo.Link).Equal(fakeRepo.Link) g.Assert(repo.Link).Equal(fakeRepo.Link)
}) })
@ -156,13 +156,13 @@ var (
} }
fakeRepo = &model.Repo{ fakeRepo = &model.Repo{
Owner: "octocat", Owner: "octocat",
Name: "Hello-World", Name: "Hello-World",
FullName: "octocat/Hello-World", FullName: "octocat/Hello-World",
Avatar: "https://github.com/images/error/octocat_happy.gif", Avatar: "https://github.com/images/error/octocat_happy.gif",
Link: "https://github.com/octocat/Hello-World", Link: "https://github.com/octocat/Hello-World",
Clone: "https://github.com/octocat/Hello-World.git", Clone: "https://github.com/octocat/Hello-World.git",
IsPrivate: true, IsSCMPrivate: true,
} }
fakeRepoNotFound = &model.Repo{ fakeRepoNotFound = &model.Repo{

View file

@ -39,7 +39,7 @@ func (g *Gitlab) convertGitlabRepo(repo_ *gitlab.Project) (*model.Repo, error) {
Link: repo_.WebURL, Link: repo_.WebURL,
Clone: repo_.HTTPURLToRepo, Clone: repo_.HTTPURLToRepo,
Branch: repo_.DefaultBranch, Branch: repo_.DefaultBranch,
Visibility: string(repo_.Visibility), Visibility: model.RepoVisibly(repo_.Visibility),
} }
if len(repo.Branch) == 0 { // TODO: do we need that? 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 { if g.PrivateMode {
repo.IsPrivate = true repo.IsSCMPrivate = true
} else { } else {
repo.IsPrivate = !repo_.Public repo.IsSCMPrivate = !repo_.Public
} }
return repo, nil return repo, nil
@ -149,11 +149,11 @@ func convertPushHock(hook *gitlab.PushEvent) (*model.Repo, *model.Build, error)
switch hook.Project.Visibility { switch hook.Project.Visibility {
case gitlab.PrivateVisibility: case gitlab.PrivateVisibility:
repo.IsPrivate = true repo.IsSCMPrivate = true
case gitlab.InternalVisibility: case gitlab.InternalVisibility:
repo.IsPrivate = true repo.IsSCMPrivate = true
case gitlab.PublicVisibility: case gitlab.PublicVisibility:
repo.IsPrivate = false repo.IsSCMPrivate = false
} }
build.Event = model.EventPush build.Event = model.EventPush
@ -194,11 +194,11 @@ func convertTagHock(hook *gitlab.TagEvent) (*model.Repo, *model.Build, error) {
switch hook.Project.Visibility { switch hook.Project.Visibility {
case gitlab.PrivateVisibility: case gitlab.PrivateVisibility:
repo.IsPrivate = true repo.IsSCMPrivate = true
case gitlab.InternalVisibility: case gitlab.InternalVisibility:
repo.IsPrivate = true repo.IsSCMPrivate = true
case gitlab.PublicVisibility: case gitlab.PublicVisibility:
repo.IsPrivate = false repo.IsSCMPrivate = false
} }
build.Event = model.EventTag build.Event = model.EventTag

View file

@ -97,7 +97,7 @@ func Test_Gitlab(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "diaspora-client", _repo.Name) assert.Equal(t, "diaspora-client", _repo.Name)
assert.Equal(t, "diaspora", _repo.Owner) 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() { g.It("Should return error, when repo not exist", func() {

View file

@ -31,7 +31,7 @@ const (
) )
// getStatus is a helper that converts a Woodpecker status to a Gitlab status. // 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 { switch status {
case model.StatusPending, model.StatusBlocked: case model.StatusPending, model.StatusBlocked:
return gitlab.Pending return gitlab.Pending
@ -50,7 +50,7 @@ func getStatus(status string) gitlab.BuildStateValue {
// getDesc is a helper function that generates a description // getDesc is a helper function that generates a description
// message for the build based on the status. // message for the build based on the status.
func getDesc(status string) string { func getDesc(status model.StatusValue) string {
switch status { switch status {
case model.StatusPending: case model.StatusPending:
return DescPending return DescPending

View file

@ -95,7 +95,7 @@ func Test_gogs(t *testing.T) {
g.Assert(repo.Owner).Equal(fakeRepo.Owner) g.Assert(repo.Owner).Equal(fakeRepo.Owner)
g.Assert(repo.Name).Equal(fakeRepo.Name) g.Assert(repo.Name).Equal(fakeRepo.Name)
g.Assert(repo.FullName).Equal(fakeRepo.Owner + "/" + 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.Clone).Equal("http://localhost/test_name/repo_name.git")
g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name") g.Assert(repo.Link).Equal("http://localhost/test_name/repo_name")
}) })

View file

@ -39,15 +39,15 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
private = true private = true
} }
return &model.Repo{ return &model.Repo{
Kind: model.RepoGit, SCMKind: model.RepoGit,
Name: name, Name: name,
Owner: from.Owner.UserName, Owner: from.Owner.UserName,
FullName: from.FullName, FullName: from.FullName,
Avatar: avatar, Avatar: avatar,
Link: from.HTMLURL, Link: from.HTMLURL,
IsPrivate: private, IsSCMPrivate: private,
Clone: from.CloneURL, Clone: from.CloneURL,
Branch: from.DefaultBranch, Branch: from.DefaultBranch,
} }
} }

View file

@ -188,7 +188,7 @@ func Test_parse(t *testing.T) {
g.Assert(repo.Link).Equal(from.HTMLURL) g.Assert(repo.Link).Equal(from.HTMLURL)
g.Assert(repo.Clone).Equal(from.CloneURL) g.Assert(repo.Clone).Equal(from.CloneURL)
g.Assert(repo.Avatar).Equal(from.Owner.AvatarUrl) 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() { g.It("Should correct a malformed avatar url", func() {

View file

@ -44,7 +44,7 @@ func UpdateToStatusDeclined(store UpdateBuildStore, build model.Build, reviewer
return &build, store.UpdateBuild(&build) 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.Status = status
build.Finished = stopped build.Finished = stopped
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)

View file

@ -233,7 +233,7 @@ func (b *ProcBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[
b.Netrc.Password, b.Netrc.Password,
b.Netrc.Machine, b.Netrc.Machine,
), ),
b.Repo.IsPrivate, b.Repo.IsSCMPrivate,
), ),
compiler.WithRegistry(registries...), compiler.WithRegistry(registries...),
compiler.WithSecret(secrets...), compiler.WithSecret(secrets...),
@ -298,7 +298,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.
Name: repo.FullName, Name: repo.FullName,
Link: repo.Link, Link: repo.Link,
Remote: repo.Clone, Remote: repo.Clone,
Private: repo.IsPrivate, Private: repo.IsSCMPrivate,
Branch: repo.Branch, Branch: repo.Branch,
}, },
Curr: frontend.Build{ Curr: frontend.Build{
@ -307,7 +307,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.
Created: build.Created, Created: build.Created,
Started: build.Started, Started: build.Started,
Finished: build.Finished, Finished: build.Finished,
Status: build.Status, Status: string(build.Status),
Event: build.Event, Event: build.Event,
Link: build.Link, Link: build.Link,
Target: build.Deploy, Target: build.Deploy,
@ -330,7 +330,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.
Created: last.Created, Created: last.Created,
Started: last.Started, Started: last.Started,
Finished: last.Finished, Finished: last.Finished,
Status: last.Status, Status: string(last.Status),
Event: last.Event, Event: last.Event,
Link: last.Link, Link: last.Link,
Target: last.Deploy, Target: last.Deploy,

View file

@ -91,13 +91,13 @@ func TestRepoListLatest(t *testing.T) {
if got, want := len(builds), 2; got != want { if got, want := len(builds), 2; got != want {
t.Errorf("Want %d repositories, got %d", want, got) 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) t.Errorf("Want repository status %s, got %s", want, got)
} }
if got, want := builds[0].FullName, repo1.FullName; want != got { if got, want := builds[0].FullName, repo1.FullName; want != got {
t.Errorf("Want repository name %s, got %s", 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) t.Errorf("Want repository status %s, got %s", want, got)
} }
if got, want := builds[1].FullName, repo2.FullName; want != got { if got, want := builds[1].FullName, repo2.FullName; want != got {

View file

@ -164,7 +164,7 @@ func TestProcUpdate(t *testing.T) {
t.Error(err) t.Error(err)
return 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) t.Errorf("Want proc name %s, got %s", want, got)
} }
} }