mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-01 21:28:44 +00:00
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:
parent
d02dfe993f
commit
51617e7f86
40 changed files with 267 additions and 271 deletions
|
@ -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 }}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -24,7 +24,7 @@ type Build struct {
|
|||
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'"`
|
||||
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"`
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -32,9 +32,8 @@ type Perm struct {
|
|||
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"`
|
||||
Created int64 `json:"created" xorm:"created"`
|
||||
Updated int64 `json:"updated" xorm:"updated"`
|
||||
}
|
||||
|
||||
// TableName return database table name for xorm
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -33,10 +33,10 @@ type Repo struct {
|
|||
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`
|
||||
SCMKind SCMKind `json:"scm,omitempty" xorm:"varchar(50) 'repo_scm'"`
|
||||
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`
|
||||
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"`
|
||||
|
@ -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.
|
||||
|
|
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -82,12 +82,12 @@ func convertRepo(from *internal.Repo) *model.Repo {
|
|||
Name: strings.Split(from.FullName, "/")[1],
|
||||
FullName: from.FullName,
|
||||
Link: from.Links.Html.Href,
|
||||
IsPrivate: from.IsPrivate,
|
||||
IsSCMPrivate: from.IsPrivate,
|
||||
Avatar: from.Owner.Links.Avatar.Href,
|
||||
Kind: from.Scm,
|
||||
SCMKind: model.SCMKind(from.Scm),
|
||||
Branch: "master",
|
||||
}
|
||||
if repo.Kind == model.RepoHg {
|
||||
if repo.SCMKind == model.RepoHg {
|
||||
repo.Branch = "default"
|
||||
}
|
||||
return &repo
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
@ -77,8 +77,8 @@ func convertRepo(from *internal.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 :/
|
||||
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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -174,10 +174,10 @@ func (c *Coding) Repo(ctx context.Context, u *model.User, owner, name string) (*
|
|||
FullName: projectFullName(project.Owner, project.Name),
|
||||
Avatar: c.resourceLink(project.Icon),
|
||||
Link: c.resourceLink(project.DepotPath),
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Clone: project.HttpsURL,
|
||||
Branch: depot.DefaultBranch,
|
||||
IsPrivate: !project.IsPublic,
|
||||
IsSCMPrivate: !project.IsPublic,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -201,10 +201,10 @@ func (c *Coding) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
|
|||
FullName: projectFullName(project.Owner, project.Name),
|
||||
Avatar: c.resourceLink(project.Icon),
|
||||
Link: c.resourceLink(project.DepotPath),
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Clone: project.HttpsURL,
|
||||
Branch: depot.DefaultBranch,
|
||||
IsPrivate: !project.IsPublic,
|
||||
IsSCMPrivate: !project.IsPublic,
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -262,10 +262,10 @@ var (
|
|||
FullName: "demo1/test1",
|
||||
Avatar: "/static/project_icon/scenery-5.png",
|
||||
Link: "/u/gilala/p/abp/git",
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Clone: "https://git.coding.net/demo1/test1.git",
|
||||
Branch: "master",
|
||||
IsPrivate: true,
|
||||
IsSCMPrivate: true,
|
||||
}
|
||||
|
||||
fakeRepoNotFound = &model.Repo{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
|
|
@ -39,13 +39,13 @@ func toRepo(from *gitea.Repository, privateMode bool) *model.Repo {
|
|||
private = true
|
||||
}
|
||||
return &model.Repo{
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsPrivate: private,
|
||||
IsSCMPrivate: private,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
@ -89,10 +89,10 @@ func convertRepo(from *github.Repository, private bool) *model.Repo {
|
|||
Name: *from.Name,
|
||||
FullName: *from.FullName,
|
||||
Link: *from.HTMLURL,
|
||||
IsPrivate: *from.Private,
|
||||
IsSCMPrivate: *from.Private,
|
||||
Clone: *from.CloneURL,
|
||||
Avatar: *from.Owner.AvatarURL,
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Branch: defaultBranch,
|
||||
Perm: convertPerm(from),
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func convertRepo(from *github.Repository, private bool) *model.Repo {
|
|||
repo.Branch = *from.DefaultBranch
|
||||
}
|
||||
if private {
|
||||
repo.IsPrivate = true
|
||||
repo.IsSCMPrivate = true
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
@ -164,10 +164,10 @@ func convertRepoHook(from *webhook) *model.Repo {
|
|||
Name: from.Repo.Name,
|
||||
FullName: from.Repo.FullName,
|
||||
Link: from.Repo.HTMLURL,
|
||||
IsPrivate: from.Repo.Private,
|
||||
IsSCMPrivate: from.Repo.Private,
|
||||
Clone: from.Repo.CloneURL,
|
||||
Branch: from.Repo.DefaultBranch,
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
}
|
||||
if repo.Branch == "" {
|
||||
repo.Branch = defaultBranch
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
@ -162,7 +162,7 @@ var (
|
|||
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,
|
||||
IsSCMPrivate: true,
|
||||
}
|
||||
|
||||
fakeRepoNotFound = &model.Repo{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
|
|
@ -39,13 +39,13 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
|||
private = true
|
||||
}
|
||||
return &model.Repo{
|
||||
Kind: model.RepoGit,
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsPrivate: private,
|
||||
IsSCMPrivate: private,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue