diff --git a/api/admin/repo.go b/api/admin/repo.go index 0f7327193..53ad236b9 100644 --- a/api/admin/repo.go +++ b/api/admin/repo.go @@ -66,7 +66,7 @@ func UpdateRepo(c *gin.Context) { } // send API call to update the repo - err = database.FromContext(c).UpdateRepo(input) + r, err := database.FromContext(c).UpdateRepo(input) if err != nil { retErr := fmt.Errorf("unable to update repo %d: %w", input.GetID(), err) @@ -75,5 +75,5 @@ func UpdateRepo(c *gin.Context) { return } - c.JSON(http.StatusOK, input) + c.JSON(http.StatusOK, r) } diff --git a/api/build/create.go b/api/build/create.go index 38a8867c2..cac912867 100644 --- a/api/build/create.go +++ b/api/build/create.go @@ -329,7 +329,7 @@ func CreateBuild(c *gin.Context) { } // send API call to update repo for ensuring counter is incremented - err = database.FromContext(c).UpdateRepo(r) + r, err = database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to create new build: failed to update repo %s: %w", r.GetFullName(), err) diff --git a/api/build/restart.go b/api/build/restart.go index 8bb85e798..7b7dcca69 100644 --- a/api/build/restart.go +++ b/api/build/restart.go @@ -320,7 +320,7 @@ func RestartBuild(c *gin.Context) { } // send API call to update repo for ensuring counter is incremented - err = database.FromContext(c).UpdateRepo(r) + r, err = database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to restart build: failed to update repo %s: %w", r.GetFullName(), err) util.HandleError(c, http.StatusBadRequest, retErr) diff --git a/api/repo/chown.go b/api/repo/chown.go index 00e728128..671e5a438 100644 --- a/api/repo/chown.go +++ b/api/repo/chown.go @@ -68,7 +68,7 @@ func ChownRepo(c *gin.Context) { r.SetUserID(u.GetID()) // send API call to update the repo - err := database.FromContext(c).UpdateRepo(r) + _, err := database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to change owner of repo %s to %s: %w", r.GetFullName(), u.GetName(), err) diff --git a/api/repo/create.go b/api/repo/create.go index e52cd23f4..33de7d3ae 100644 --- a/api/repo/create.go +++ b/api/repo/create.go @@ -285,7 +285,7 @@ func CreateRepo(c *gin.Context) { dbRepo.SetActive(true) // send API call to update the repo - err = database.FromContext(c).UpdateRepo(dbRepo) + r, err = database.FromContext(c).UpdateRepo(dbRepo) if err != nil { retErr := fmt.Errorf("unable to set repo %s to active: %w", dbRepo.GetFullName(), err) @@ -293,12 +293,9 @@ func CreateRepo(c *gin.Context) { return } - - // send API call to capture the updated repo - r, _ = database.FromContext(c).GetRepoForOrg(dbRepo.GetOrg(), dbRepo.GetName()) } else { // send API call to create the repo - err = database.FromContext(c).CreateRepo(r) + r, err = database.FromContext(c).CreateRepo(r) if err != nil { retErr := fmt.Errorf("unable to create new repo %s: %w", r.GetFullName(), err) @@ -306,9 +303,6 @@ func CreateRepo(c *gin.Context) { return } - - // send API call to capture the created repo - r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName()) } // create init hook in the DB after repo has been added in order to capture its ID diff --git a/api/repo/delete.go b/api/repo/delete.go index 63649f2eb..cc3ca66b9 100644 --- a/api/repo/delete.go +++ b/api/repo/delete.go @@ -88,7 +88,7 @@ func DeleteRepo(c *gin.Context) { // Mark the repo as inactive r.SetActive(false) - err = database.FromContext(c).UpdateRepo(r) + _, err = database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to set repo %s to inactive: %w", r.GetFullName(), err) diff --git a/api/repo/repair.go b/api/repo/repair.go index 192983d1c..7b7f0e98d 100644 --- a/api/repo/repair.go +++ b/api/repo/repair.go @@ -122,7 +122,7 @@ func RepairRepo(c *gin.Context) { r.SetActive(true) // send API call to update the repo - err := database.FromContext(c).UpdateRepo(r) + _, err := database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to set repo %s to active: %w", r.GetFullName(), err) diff --git a/api/repo/update.go b/api/repo/update.go index 374772d42..2f299bdc1 100644 --- a/api/repo/update.go +++ b/api/repo/update.go @@ -295,7 +295,7 @@ func UpdateRepo(c *gin.Context) { } // send API call to update the repo - err = database.FromContext(c).UpdateRepo(r) + r, err = database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to update repo %s: %w", r.GetFullName(), err) @@ -304,8 +304,5 @@ func UpdateRepo(c *gin.Context) { return } - // send API call to capture the updated repo - r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName()) - c.JSON(http.StatusOK, r) } diff --git a/api/scm/sync.go b/api/scm/sync.go index b160f5fa0..c98ea82e4 100644 --- a/api/scm/sync.go +++ b/api/scm/sync.go @@ -80,7 +80,7 @@ func SyncRepo(c *gin.Context) { r.SetActive(false) // update repo in database - err := database.FromContext(c).UpdateRepo(r) + _, err := database.FromContext(c).UpdateRepo(r) if err != nil { retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err) diff --git a/api/scm/sync_org.go b/api/scm/sync_org.go index ac18ec551..9cda091ef 100644 --- a/api/scm/sync_org.go +++ b/api/scm/sync_org.go @@ -113,7 +113,7 @@ func SyncReposForOrg(c *gin.Context) { if err != nil { repo.SetActive(false) - err := database.FromContext(c).UpdateRepo(repo) + _, err := database.FromContext(c).UpdateRepo(repo) if err != nil { retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err) diff --git a/api/webhook/post.go b/api/webhook/post.go index 7eab225f5..bae23a863 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -621,7 +621,7 @@ func PostWebhook(c *gin.Context) { } // end of retry loop // send API call to update repo for ensuring counter is incremented - err = database.FromContext(c).UpdateRepo(repo) + repo, err = database.FromContext(c).UpdateRepo(repo) if err != nil { retErr := fmt.Errorf("%s: failed to update repo %s: %w", baseErr, repo.GetFullName(), err) util.HandleError(c, http.StatusBadRequest, retErr) @@ -759,7 +759,7 @@ func handleRepositoryEvent(c *gin.Context, m *types.Metadata, h *library.Hook, r } // update repo object in the database after applying edits - err = database.FromContext(c).UpdateRepo(dbRepo) + dbRepo, err = database.FromContext(c).UpdateRepo(dbRepo) if err != nil { retErr := fmt.Errorf("%s: failed to update repo %s: %w", baseErr, r.GetFullName(), err) @@ -891,7 +891,7 @@ func renameRepository(h *library.Hook, r *library.Repo, c *gin.Context, m *types dbR.SetPreviousName(r.GetPreviousName()) // update the repo in the database - err = database.FromContext(c).UpdateRepo(dbR) + dbR, err = database.FromContext(c).UpdateRepo(dbR) if err != nil { retErr := fmt.Errorf("%s: failed to update repo %s/%s in database", baseErr, prevOrg, prevRepo) util.HandleError(c, http.StatusBadRequest, retErr) diff --git a/cmd/vela-server/schedule.go b/cmd/vela-server/schedule.go index 08e7867cc..e5b1a78c1 100644 --- a/cmd/vela-server/schedule.go +++ b/cmd/vela-server/schedule.go @@ -373,7 +373,7 @@ func processSchedule(s *library.Schedule, compiler compiler.Engine, database dat } // end of retry loop // send API call to update repo for ensuring counter is incremented - err = database.UpdateRepo(r) + r, err = database.UpdateRepo(r) if err != nil { return fmt.Errorf("unable to update repo %s: %w", r.GetFullName(), err) } diff --git a/database/repo/count_org_test.go b/database/repo/count_org_test.go index 2ff3278f3..fd4797dad 100644 --- a/database/repo/count_org_test.go +++ b/database/repo/count_org_test.go @@ -43,12 +43,12 @@ func TestRepo_Engine_CountReposForOrg(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/count_test.go b/database/repo/count_test.go index f63a935e8..104cccc65 100644 --- a/database/repo/count_test.go +++ b/database/repo/count_test.go @@ -43,12 +43,12 @@ func TestRepo_Engine_CountRepos(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/count_user_test.go b/database/repo/count_user_test.go index 654788a69..45ea309ab 100644 --- a/database/repo/count_user_test.go +++ b/database/repo/count_user_test.go @@ -49,12 +49,12 @@ func TestRepo_Engine_CountReposForUser(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/create.go b/database/repo/create.go index fbfda486a..850d854aa 100644 --- a/database/repo/create.go +++ b/database/repo/create.go @@ -15,7 +15,7 @@ import ( ) // CreateRepo creates a new repo in the database. -func (e *engine) CreateRepo(r *library.Repo) error { +func (e *engine) CreateRepo(r *library.Repo) (*library.Repo, error) { e.logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -31,7 +31,7 @@ func (e *engine) CreateRepo(r *library.Repo) error { // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Validate err := repo.Validate() if err != nil { - return err + return nil, err } // encrypt the fields for the repo @@ -39,12 +39,23 @@ func (e *engine) CreateRepo(r *library.Repo) error { // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Encrypt err = repo.Encrypt(e.config.EncryptionKey) if err != nil { - return fmt.Errorf("unable to encrypt repo %s: %w", r.GetFullName(), err) + return nil, fmt.Errorf("unable to encrypt repo %s: %w", r.GetFullName(), err) } // send query to the database - return e.client. - Table(constants.TableRepo). - Create(repo). - Error + err = e.client.Table(constants.TableRepo).Create(repo).Error + if err != nil { + return nil, err + } + + // decrypt the fields for the repo + err = repo.Decrypt(e.config.EncryptionKey) + if err != nil { + // only log to preserve backwards compatibility + e.logger.Errorf("unable to decrypt repo %d: %v", r.GetID(), err) + + return repo.ToLibrary(), nil + } + + return repo.ToLibrary(), nil } diff --git a/database/repo/create_test.go b/database/repo/create_test.go index ac0a86ffa..4241ce4ab 100644 --- a/database/repo/create_test.go +++ b/database/repo/create_test.go @@ -5,6 +5,7 @@ package repo import ( + "reflect" "testing" "github.com/DATA-DOG/go-sqlmock" @@ -22,6 +23,7 @@ func TestRepo_Engine_CreateRepo(t *testing.T) { _repo.SetVisibility("public") _repo.SetPipelineType("yaml") _repo.SetPreviousName("oldName") + _repo.SetTopics([]string{}) _postgres, _mock := testPostgres(t) defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }() @@ -60,7 +62,7 @@ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$ // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err := test.database.CreateRepo(_repo) + got, err := test.database.CreateRepo(_repo) if test.failure { if err == nil { @@ -73,6 +75,10 @@ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$ if err != nil { t.Errorf("CreateRepo for %s returned err: %v", test.name, err) } + + if !reflect.DeepEqual(got, _repo) { + t.Errorf("CreateRepo for %s returned %s, want %s", test.name, got, _repo) + } }) } } diff --git a/database/repo/delete_test.go b/database/repo/delete_test.go index ccc50eb4a..a4504d6bc 100644 --- a/database/repo/delete_test.go +++ b/database/repo/delete_test.go @@ -32,7 +32,7 @@ func TestRepo_Engine_DeleteRepo(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repo) + _, err := _sqlite.CreateRepo(_repo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/get_org_test.go b/database/repo/get_org_test.go index 2f1dee125..b60faefde 100644 --- a/database/repo/get_org_test.go +++ b/database/repo/get_org_test.go @@ -39,7 +39,7 @@ func TestRepo_Engine_GetRepoForOrg(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repo) + _, err := _sqlite.CreateRepo(_repo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/get_test.go b/database/repo/get_test.go index a1b7a8485..e098626de 100644 --- a/database/repo/get_test.go +++ b/database/repo/get_test.go @@ -39,7 +39,7 @@ func TestRepo_Engine_GetRepo(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repo) + _, err := _sqlite.CreateRepo(_repo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/interface.go b/database/repo/interface.go index a53ad3a0a..1b641da35 100644 --- a/database/repo/interface.go +++ b/database/repo/interface.go @@ -33,7 +33,7 @@ type RepoInterface interface { // CountReposForUser defines a function that gets the count of repos by user ID. CountReposForUser(*library.User, map[string]interface{}) (int64, error) // CreateRepo defines a function that creates a new repo. - CreateRepo(*library.Repo) error + CreateRepo(*library.Repo) (*library.Repo, error) // DeleteRepo defines a function that deletes an existing repo. DeleteRepo(*library.Repo) error // GetRepo defines a function that gets a repo by ID. @@ -47,5 +47,5 @@ type RepoInterface interface { // ListReposForUser defines a function that gets a list of repos by user ID. ListReposForUser(*library.User, string, map[string]interface{}, int, int) ([]*library.Repo, int64, error) // UpdateRepo defines a function that updates an existing repo. - UpdateRepo(*library.Repo) error + UpdateRepo(*library.Repo) (*library.Repo, error) } diff --git a/database/repo/list_org_test.go b/database/repo/list_org_test.go index b668aff97..e54a11bf4 100644 --- a/database/repo/list_org_test.go +++ b/database/repo/list_org_test.go @@ -87,12 +87,12 @@ func TestRepo_Engine_ListReposForOrg(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/list_test.go b/database/repo/list_test.go index 9e359c40f..6936406e6 100644 --- a/database/repo/list_test.go +++ b/database/repo/list_test.go @@ -57,12 +57,12 @@ func TestRepo_Engine_ListRepos(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/list_user_test.go b/database/repo/list_user_test.go index a65958c39..7bff6fe2c 100644 --- a/database/repo/list_user_test.go +++ b/database/repo/list_user_test.go @@ -92,12 +92,12 @@ func TestRepo_Engine_ListReposForUser(t *testing.T) { _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repoOne) + _, err := _sqlite.CreateRepo(_repoOne) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } - err = _sqlite.CreateRepo(_repoTwo) + _, err = _sqlite.CreateRepo(_repoTwo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } diff --git a/database/repo/update.go b/database/repo/update.go index 4c31791db..cf7111499 100644 --- a/database/repo/update.go +++ b/database/repo/update.go @@ -15,7 +15,7 @@ import ( ) // UpdateRepo updates an existing repo in the database. -func (e *engine) UpdateRepo(r *library.Repo) error { +func (e *engine) UpdateRepo(r *library.Repo) (*library.Repo, error) { e.logger.WithFields(logrus.Fields{ "org": r.GetOrg(), "repo": r.GetName(), @@ -31,7 +31,7 @@ func (e *engine) UpdateRepo(r *library.Repo) error { // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Validate err := repo.Validate() if err != nil { - return err + return nil, err } // encrypt the fields for the repo @@ -39,12 +39,23 @@ func (e *engine) UpdateRepo(r *library.Repo) error { // https://pkg.go.dev/github.com/go-vela/types/database#Repo.Encrypt err = repo.Encrypt(e.config.EncryptionKey) if err != nil { - return fmt.Errorf("unable to encrypt repo %s: %w", r.GetFullName(), err) + return nil, fmt.Errorf("unable to encrypt repo %s: %w", r.GetFullName(), err) } // send query to the database - return e.client. - Table(constants.TableRepo). - Save(repo). - Error + err = e.client.Table(constants.TableRepo).Save(repo).Error + if err != nil { + return nil, err + } + + // decrypt the fields for the repo + err = repo.Decrypt(e.config.EncryptionKey) + if err != nil { + // only log to preserve backwards compatibility + e.logger.Errorf("unable to decrypt repo %d: %v", r.GetID(), err) + + return repo.ToLibrary(), nil + } + + return repo.ToLibrary(), nil } diff --git a/database/repo/update_test.go b/database/repo/update_test.go index 35d4b74bb..66f4fa6a9 100644 --- a/database/repo/update_test.go +++ b/database/repo/update_test.go @@ -5,6 +5,7 @@ package repo import ( + "reflect" "testing" "github.com/DATA-DOG/go-sqlmock" @@ -22,6 +23,7 @@ func TestRepo_Engine_UpdateRepo(t *testing.T) { _repo.SetVisibility("public") _repo.SetPipelineType("yaml") _repo.SetPreviousName("oldName") + _repo.SetTopics([]string{}) _postgres, _mock := testPostgres(t) defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }() @@ -36,7 +38,7 @@ WHERE "id" = $24`). _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }() - err := _sqlite.CreateRepo(_repo) + _, err := _sqlite.CreateRepo(_repo) if err != nil { t.Errorf("unable to create test repo for sqlite: %v", err) } @@ -62,7 +64,7 @@ WHERE "id" = $24`). // run tests for _, test := range tests { t.Run(test.name, func(t *testing.T) { - err = test.database.UpdateRepo(_repo) + got, err := test.database.UpdateRepo(_repo) if test.failure { if err == nil { @@ -75,6 +77,10 @@ WHERE "id" = $24`). if err != nil { t.Errorf("UpdateRepo for %s returned err: %v", test.name, err) } + + if !reflect.DeepEqual(got, _repo) { + t.Errorf("UpdateRepo for %s returned %s, want %s", test.name, got, _repo) + } }) } } diff --git a/router/middleware/build/build_test.go b/router/middleware/build/build_test.go index d8a540b9c..d0e0733a5 100644 --- a/router/middleware/build/build_test.go +++ b/router/middleware/build/build_test.go @@ -94,7 +94,7 @@ func TestBuild_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(want) // setup context @@ -176,7 +176,7 @@ func TestBuild_Establish_NoBuildParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) @@ -224,7 +224,7 @@ func TestBuild_Establish_InvalidBuildParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) @@ -272,7 +272,7 @@ func TestBuild_Establish_NoBuild(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/org/org_test.go b/router/middleware/org/org_test.go index aa64710cc..4c98de87e 100644 --- a/router/middleware/org/org_test.go +++ b/router/middleware/org/org_test.go @@ -69,7 +69,7 @@ func TestOrg_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/perm/perm_test.go b/router/middleware/perm/perm_test.go index 70a88fbf8..a5af1cbbe 100644 --- a/router/middleware/perm/perm_test.go +++ b/router/middleware/perm/perm_test.go @@ -447,7 +447,7 @@ func TestPerm_MustBuildAccess(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar/builds/1", nil) @@ -537,7 +537,7 @@ func TestPerm_MustBuildAccess_PlatAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) _ = db.CreateUser(u) @@ -622,7 +622,7 @@ func TestPerm_MustBuildToken_WrongBuild(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar/builds/1", nil) @@ -706,7 +706,7 @@ func TestPerm_MustSecretAdmin_BuildToken_Repo(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) context.Request, _ = http.NewRequest(http.MethodGet, "/test/native/repo/foo/bar/baz", nil) @@ -787,7 +787,7 @@ func TestPerm_MustSecretAdmin_BuildToken_Org(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) context.Request, _ = http.NewRequest(http.MethodGet, "/test/native/org/foo/*/baz", nil) @@ -868,7 +868,7 @@ func TestPerm_MustSecretAdmin_BuildToken_Shared(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) context.Request, _ = http.NewRequest(http.MethodGet, "/test/native/shared/foo/*/*", nil) @@ -949,7 +949,7 @@ func TestPerm_MustAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1047,7 +1047,7 @@ func TestPerm_MustAdmin_PlatAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1145,7 +1145,7 @@ func TestPerm_MustAdmin_NotAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1243,7 +1243,7 @@ func TestPerm_MustWrite(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1341,7 +1341,7 @@ func TestPerm_MustWrite_PlatAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1439,7 +1439,7 @@ func TestPerm_MustWrite_RepoAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1537,7 +1537,7 @@ func TestPerm_MustWrite_NotWrite(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1635,7 +1635,7 @@ func TestPerm_MustRead(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1733,7 +1733,7 @@ func TestPerm_MustRead_PlatAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -1832,7 +1832,7 @@ func TestPerm_MustRead_WorkerBuildToken(t *testing.T) { }() _, _ = db.CreateBuild(b) - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar/builds/1", nil) context.Request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tok)) @@ -1915,7 +1915,7 @@ func TestPerm_MustRead_RepoAdmin(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -2013,7 +2013,7 @@ func TestPerm_MustRead_RepoWrite(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -2111,7 +2111,7 @@ func TestPerm_MustRead_RepoPublic(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) @@ -2209,7 +2209,7 @@ func TestPerm_MustRead_NotRead(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) context.Request, _ = http.NewRequest(http.MethodGet, "/test/foo/bar", nil) diff --git a/router/middleware/pipeline/pipeline_test.go b/router/middleware/pipeline/pipeline_test.go index a7c76c892..4e7912372 100644 --- a/router/middleware/pipeline/pipeline_test.go +++ b/router/middleware/pipeline/pipeline_test.go @@ -107,7 +107,7 @@ func TestPipeline_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreatePipeline(want) // setup context @@ -189,7 +189,7 @@ func TestPipeline_Establish_NoPipelineParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) @@ -293,7 +293,7 @@ func TestPipeline_Establish_NoPipeline(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _ = db.CreateUser(u) // setup context diff --git a/router/middleware/repo/repo_test.go b/router/middleware/repo/repo_test.go index 83051c09c..50b6c8cc7 100644 --- a/router/middleware/repo/repo_test.go +++ b/router/middleware/repo/repo_test.go @@ -76,7 +76,7 @@ func TestRepo_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(want) + _, _ = db.CreateRepo(want) // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/service/service_test.go b/router/middleware/service/service_test.go index cd057b471..20c84c868 100644 --- a/router/middleware/service/service_test.go +++ b/router/middleware/service/service_test.go @@ -84,7 +84,7 @@ func TestService_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) _ = db.CreateService(want) @@ -171,7 +171,7 @@ func TestService_Establish_NoBuild(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) @@ -225,7 +225,7 @@ func TestService_Establish_NoServiceParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context @@ -281,7 +281,7 @@ func TestService_Establish_InvalidServiceParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context @@ -337,7 +337,7 @@ func TestService_Establish_NoService(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context diff --git a/router/middleware/step/step_test.go b/router/middleware/step/step_test.go index d0ad740c4..85aa8c246 100644 --- a/router/middleware/step/step_test.go +++ b/router/middleware/step/step_test.go @@ -86,7 +86,7 @@ func TestStep_Establish(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) _ = db.CreateStep(want) @@ -173,7 +173,7 @@ func TestStep_Establish_NoBuild(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) // setup context gin.SetMode(gin.TestMode) @@ -227,7 +227,7 @@ func TestStep_Establish_NoStepParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context @@ -283,7 +283,7 @@ func TestStep_Establish_InvalidStepParameter(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context @@ -339,7 +339,7 @@ func TestStep_Establish_NoStep(t *testing.T) { db.Close() }() - _ = db.CreateRepo(r) + _, _ = db.CreateRepo(r) _, _ = db.CreateBuild(b) // setup context