From 7340e10a7ae56851aaf6aa0a0cda2aa18c9bbcdd Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 1 Jan 2023 19:32:32 +0100 Subject: [PATCH] Add fields for tests --- db.go | 2 ++ repositories.go | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/db.go b/db.go index becb4a8..d67d311 100644 --- a/db.go +++ b/db.go @@ -242,6 +242,8 @@ CREATE TABLE IF NOT EXISTS user_work_repositories( secret BLOB NOT NULL, last_check TIMESTAMP NULL DEFAULT NULL, droneref VARCHAR(255) NOT NULL, + last_tests TIMESTAMP NULL DEFAULT NULL, + testsref VARCHAR(255) NOT NULL, FOREIGN KEY(id_user) REFERENCES users(id_user), FOREIGN KEY(id_work) REFERENCES works(id_work), UNIQUE one_repo_per_work (id_user, id_work) diff --git a/repositories.go b/repositories.go index bf14459..6a4dbe4 100644 --- a/repositories.go +++ b/repositories.go @@ -220,7 +220,6 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) { if err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to find related work."}) return - } now := time.Now() @@ -474,18 +473,20 @@ type Repository struct { Secret []byte `json:"secret,omitempty"` LastCheck *time.Time `json:"last_check"` DroneRef string `json:"drone_ref,omitempty"` + LastTests *time.Time `json:"last_tests"` + TestsRef string `json:"drone_ref,omitempty"` AlreadyUsed bool `json:"already_used,omitempty"` } func (u *User) GetRepositories() (repositories []*Repository, err error) { - if rows, errr := DBQuery("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref FROM user_work_repositories WHERE id_user=?", u.Id); errr != nil { + if rows, errr := DBQuery("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref, last_tests, testsref FROM user_work_repositories WHERE id_user=?", u.Id); errr != nil { return nil, errr } else { defer rows.Close() for rows.Next() { var repo Repository - if err = rows.Scan(&repo.Id, &repo.IdUser, &repo.IdWork, &repo.URI, &repo.Secret, &repo.LastCheck, &repo.DroneRef); err != nil { + if err = rows.Scan(&repo.Id, &repo.IdUser, &repo.IdWork, &repo.URI, &repo.Secret, &repo.LastCheck, &repo.DroneRef, &repo.LastTests, &repo.TestsRef); err != nil { return } repositories = append(repositories, &repo) @@ -499,14 +500,14 @@ func (u *User) GetRepositories() (repositories []*Repository, err error) { } func getRepositoriesByURI(uri string) (repositories []*Repository, err error) { - if rows, errr := DBQuery("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref FROM user_work_repositories WHERE uri=?", uri); errr != nil { + if rows, errr := DBQuery("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref, last_tests, testsref FROM user_work_repositories WHERE uri=?", uri); errr != nil { return nil, errr } else { defer rows.Close() for rows.Next() { var repo Repository - if err = rows.Scan(&repo.Id, &repo.IdUser, &repo.IdWork, &repo.URI, &repo.Secret, &repo.LastCheck, &repo.DroneRef); err != nil { + if err = rows.Scan(&repo.Id, &repo.IdUser, &repo.IdWork, &repo.URI, &repo.Secret, &repo.LastCheck, &repo.DroneRef, &repo.LastTests, &repo.TestsRef); err != nil { return } repositories = append(repositories, &repo) @@ -521,13 +522,13 @@ func getRepositoriesByURI(uri string) (repositories []*Repository, err error) { func getRepository(id int) (r *Repository, err error) { r = new(Repository) - err = DBQueryRow("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref FROM user_work_repositories WHERE id_repository=?", id).Scan(&r.Id, &r.IdUser, &r.IdWork, &r.URI, &r.Secret, &r.LastCheck, &r.DroneRef) + err = DBQueryRow("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref, last_tests, testsref FROM user_work_repositories WHERE id_repository=?", id).Scan(&r.Id, &r.IdUser, &r.IdWork, &r.URI, &r.Secret, &r.LastCheck, &r.DroneRef, &r.LastTests, &r.TestsRef) return } func (u *User) getRepository(id int) (r *Repository, err error) { r = new(Repository) - err = DBQueryRow("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref FROM user_work_repositories WHERE id_repository=? AND id_user=?", id, u.Id).Scan(&r.Id, &r.IdUser, &r.IdWork, &r.URI, &r.Secret, &r.LastCheck, &r.DroneRef) + err = DBQueryRow("SELECT id_repository, id_user, id_work, uri, secret, last_check, droneref, last_tests, testsref FROM user_work_repositories WHERE id_repository=? AND id_user=?", id, u.Id).Scan(&r.Id, &r.IdUser, &r.IdWork, &r.URI, &r.Secret, &r.LastCheck, &r.DroneRef, &r.LastTests, &r.TestsRef) return } @@ -548,7 +549,7 @@ func (u *User) NewRepository(w *Work, uri string) (*Repository, error) { } func (r *Repository) Update() (*Repository, error) { - if _, err := DBExec("UPDATE user_work_repositories SET id_user = ?, id_work = ?, uri = ?, secret = ?, last_check = ?, droneref = ? WHERE id_repository = ?", r.IdUser, r.IdWork, r.URI, r.Secret, r.LastCheck, r.DroneRef, r.Id); err != nil { + if _, err := DBExec("UPDATE user_work_repositories SET id_user = ?, id_work = ?, uri = ?, secret = ?, last_check = ?, droneref = ?, last_tests = ?, testsref = ? WHERE id_repository = ?", r.IdUser, r.IdWork, r.URI, r.Secret, r.LastCheck, r.DroneRef, r.LastTests, r.TestsRef, r.Id); err != nil { return nil, err } else { return r, err