Warn and give hint when using an already used repo for another work
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-09-30 12:41:34 +02:00
commit 7cdfafc329
4 changed files with 47 additions and 10 deletions

View file

@ -60,6 +60,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
for _, r := range repositories {
if r.IdWork == work.(*Work).Id {
// Is the URL used elsewhere?
repos, _ := getRepositoriesByURI(r.URI)
log.Println(repos)
if len(repos) > 1 {
r.AlreadyUsed = true
}
res = append(res, r)
}
}
@ -114,6 +121,13 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
repositoriesRoutes.GET("", func(c *gin.Context) {
repo := c.MustGet("repository").(*Repository)
// Is the URL used elsewhere?
repos, _ := getRepositoriesByURI(repo.URI)
log.Println(repos)
if len(repos) > 1 {
repo.AlreadyUsed = true
}
c.JSON(http.StatusOK, repo)
})
repositoriesRoutes.PUT("", func(c *gin.Context) {
@ -417,13 +431,14 @@ func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag
}
type Repository struct {
Id int64 `json:"id"`
IdUser int64 `json:"id_user"`
IdWork int64 `json:"id_work"`
URI string `json:"uri"`
Secret []byte `json:"secret,omitempty"`
LastCheck *time.Time `json:"last_check"`
DroneRef string `json:"drone_ref,omitempty"`
Id int64 `json:"id"`
IdUser int64 `json:"id_user"`
IdWork int64 `json:"id_work"`
URI string `json:"uri"`
Secret []byte `json:"secret,omitempty"`
LastCheck *time.Time `json:"last_check"`
DroneRef string `json:"drone_ref,omitempty"`
AlreadyUsed bool `json:"already_used,omitempty"`
}
func (u *User) GetRepositories() (repositories []*Repository, err error) {
@ -492,7 +507,7 @@ func (u *User) NewRepository(w *Work, uri string) (*Repository, error) {
} else if rid, err := res.LastInsertId(); err != nil {
return nil, err
} else {
return &Repository{rid, u.Id, w.Id, uri, secret, nil, ""}, nil
return &Repository{rid, u.Id, w.Id, uri, secret, nil, "", false}, nil
}
}