Add fields for tests
This commit is contained in:
parent
ec71073cb6
commit
7340e10a7a
2
db.go
2
db.go
@ -242,6 +242,8 @@ CREATE TABLE IF NOT EXISTS user_work_repositories(
|
|||||||
secret BLOB NOT NULL,
|
secret BLOB NOT NULL,
|
||||||
last_check TIMESTAMP NULL DEFAULT NULL,
|
last_check TIMESTAMP NULL DEFAULT NULL,
|
||||||
droneref VARCHAR(255) NOT 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_user) REFERENCES users(id_user),
|
||||||
FOREIGN KEY(id_work) REFERENCES works(id_work),
|
FOREIGN KEY(id_work) REFERENCES works(id_work),
|
||||||
UNIQUE one_repo_per_work (id_user, id_work)
|
UNIQUE one_repo_per_work (id_user, id_work)
|
||||||
|
@ -220,7 +220,6 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to find related work."})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to find related work."})
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -474,18 +473,20 @@ type Repository struct {
|
|||||||
Secret []byte `json:"secret,omitempty"`
|
Secret []byte `json:"secret,omitempty"`
|
||||||
LastCheck *time.Time `json:"last_check"`
|
LastCheck *time.Time `json:"last_check"`
|
||||||
DroneRef string `json:"drone_ref,omitempty"`
|
DroneRef string `json:"drone_ref,omitempty"`
|
||||||
|
LastTests *time.Time `json:"last_tests"`
|
||||||
|
TestsRef string `json:"drone_ref,omitempty"`
|
||||||
AlreadyUsed bool `json:"already_used,omitempty"`
|
AlreadyUsed bool `json:"already_used,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) GetRepositories() (repositories []*Repository, err error) {
|
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
|
return nil, errr
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var repo Repository
|
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
|
return
|
||||||
}
|
}
|
||||||
repositories = append(repositories, &repo)
|
repositories = append(repositories, &repo)
|
||||||
@ -499,14 +500,14 @@ func (u *User) GetRepositories() (repositories []*Repository, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRepositoriesByURI(uri string) (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
|
return nil, errr
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var repo Repository
|
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
|
return
|
||||||
}
|
}
|
||||||
repositories = append(repositories, &repo)
|
repositories = append(repositories, &repo)
|
||||||
@ -521,13 +522,13 @@ func getRepositoriesByURI(uri string) (repositories []*Repository, err error) {
|
|||||||
|
|
||||||
func getRepository(id int) (r *Repository, err error) {
|
func getRepository(id int) (r *Repository, err error) {
|
||||||
r = new(Repository)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) getRepository(id int) (r *Repository, err error) {
|
func (u *User) getRepository(id int) (r *Repository, err error) {
|
||||||
r = new(Repository)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +549,7 @@ func (u *User) NewRepository(w *Work, uri string) (*Repository, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) Update() (*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
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return r, err
|
return r, err
|
||||||
|
Reference in New Issue
Block a user