Skip to content

Commit

Permalink
refactor(user)!: migrate from types repo (#1106)
Browse files Browse the repository at this point in the history
* refactor(user): migrate from types repo

* make clean

* remove extra lines from auto fix linter
  • Loading branch information
ecrupper authored Apr 12, 2024
1 parent fe803f8 commit 04f9308
Show file tree
Hide file tree
Showing 91 changed files with 1,714 additions and 494 deletions.
4 changes: 2 additions & 2 deletions api/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"

"github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
)

// swagger:operation PUT /api/v1/admin/user admin AdminUpdateUser
Expand Down Expand Up @@ -54,7 +54,7 @@ func UpdateUser(c *gin.Context) {
ctx := c.Request.Context()

// capture body from API request
input := new(library.User)
input := new(types.User)

err := c.Bind(input)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion api/auth/get_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/go-vela/server/api/types"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/scm"
Expand Down Expand Up @@ -102,7 +103,7 @@ func GetAuthToken(c *gin.Context) {
// create a new user account
if len(u.GetName()) == 0 || err != nil {
// create the user account
u := new(library.User)
u := new(types.User)
u.SetName(newUser.GetName())
u.SetToken(newUser.GetToken())
u.SetActive(true)
Expand Down
2 changes: 0 additions & 2 deletions api/build/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

// SkipEmptyBuild checks if the build should be skipped due to it
// not containing any steps besides init or clone.
//
//nolint:goconst // ignore init and clone constants
func SkipEmptyBuild(p *pipeline.Build) string {
if len(p.Stages) == 1 {
if p.Stages[0].Name == "init" {
Expand Down
2 changes: 1 addition & 1 deletion api/types/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/go-vela/types/pipeline"
)

// Executor is the library representation of an executor for a worker.
// Executor is the API representation of an executor for a worker.
//
// swagger:model Executor
type Executor struct {
Expand Down
50 changes: 24 additions & 26 deletions api/types/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@ package types
import (
"fmt"
"strings"

"github.com/go-vela/types/library"
)

// Repo is the API representation of a repo.
//
// swagger:model Repo
type Repo struct {
ID *int64 `json:"id,omitempty"`
Owner *library.User `json:"owner,omitempty"`
Hash *string `json:"-"`
Org *string `json:"org,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
Link *string `json:"link,omitempty"`
Clone *string `json:"clone,omitempty"`
Branch *string `json:"branch,omitempty"`
Topics *[]string `json:"topics,omitempty"`
BuildLimit *int64 `json:"build_limit,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Counter *int `json:"counter,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Private *bool `json:"private,omitempty"`
Trusted *bool `json:"trusted,omitempty"`
Active *bool `json:"active,omitempty"`
AllowEvents *Events `json:"allow_events,omitempty"`
PipelineType *string `json:"pipeline_type,omitempty"`
PreviousName *string `json:"previous_name,omitempty"`
ApproveBuild *string `json:"approve_build,omitempty"`
ID *int64 `json:"id,omitempty"`
Owner *User `json:"owner,omitempty"`
Hash *string `json:"-"`
Org *string `json:"org,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
Link *string `json:"link,omitempty"`
Clone *string `json:"clone,omitempty"`
Branch *string `json:"branch,omitempty"`
Topics *[]string `json:"topics,omitempty"`
BuildLimit *int64 `json:"build_limit,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Counter *int `json:"counter,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Private *bool `json:"private,omitempty"`
Trusted *bool `json:"trusted,omitempty"`
Active *bool `json:"active,omitempty"`
AllowEvents *Events `json:"allow_events,omitempty"`
PipelineType *string `json:"pipeline_type,omitempty"`
PreviousName *string `json:"previous_name,omitempty"`
ApproveBuild *string `json:"approve_build,omitempty"`
}

// Environment returns a list of environment variables
Expand Down Expand Up @@ -91,10 +89,10 @@ func (r *Repo) GetID() int64 {
//
// When the provided Repo type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Repo) GetOwner() *library.User {
func (r *Repo) GetOwner() *User {
// return zero value if Repo type or Owner field is nil
if r == nil || r.Owner == nil {
return new(library.User)
return new(User)
}

return r.Owner
Expand Down Expand Up @@ -364,7 +362,7 @@ func (r *Repo) SetID(v int64) {
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetOwner(v *library.User) {
func (r *Repo) SetOwner(v *User) {
// return if Repo type is nil
if r == nil {
return
Expand Down
3 changes: 1 addition & 2 deletions api/types/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/google/go-cmp/cmp"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
)

func TestTypes_Repo_Environment(t *testing.T) {
Expand Down Expand Up @@ -343,7 +342,7 @@ func testRepo() *Repo {

e, _ := testEvents()

owner := new(library.User)
owner := new(User)
owner.SetID(1)
owner.SetName("octocat")

Expand Down
Loading

0 comments on commit 04f9308

Please sign in to comment.