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
var tmplRepoInfo = `Owner: {{ .Owner }}
Repo: {{ .Name }}
Type: {{ .Kind }}
Type: {{ .SCMKind }}
Config: {{ .Config }}
Visibility: {{ .Visibility }}
Private: {{ .IsPrivate }}
Private: {{ .IsSCMPrivate }}
Trusted: {{ .IsTrusted }}
Gated: {{ .IsGated }}
Remote: {{ .Clone }}

View file

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

View file

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

View file

@ -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()
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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"
"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.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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")
})

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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")
})

View file

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

View file

@ -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() {

View file

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

View file

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

View file

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

View file

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

View file

@ -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() {

View file

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

View file

@ -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")
})

View file

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

View file

@ -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() {

View file

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

View file

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

View file

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

View file

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