mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-22 17:36:53 +00:00
Do not store inactive repos (#1658)
Do not sync repos with forge if the repo is not necessary in DB. In the DB, only repos that were active once or repos that are currently active are stored. When trying to enable new repos, the repos list is fetched from the forge instead and displayed directly. In addition to this, the forge func `Perm` was removed and is now merged with `Repo`. Solves a TODO on RepoBatch. --------- Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
@@ -21,8 +21,8 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server"
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||
"github.com/woodpecker-ci/woodpecker/server/store/types"
|
||||
@@ -94,8 +94,7 @@ func SetPerm() gin.HandlerFunc {
|
||||
repo := Repo(c)
|
||||
perm := new(model.Perm)
|
||||
|
||||
switch {
|
||||
case user != nil:
|
||||
if user != nil {
|
||||
var err error
|
||||
perm, err = _store.PermFind(user, repo)
|
||||
if err != nil {
|
||||
@@ -103,10 +102,12 @@ func SetPerm() gin.HandlerFunc {
|
||||
user.Login, repo.FullName, err)
|
||||
}
|
||||
if time.Unix(perm.Synced, 0).Add(time.Hour).Before(time.Now()) {
|
||||
perm, err = server.Config.Services.Forge.Perm(c, user, repo)
|
||||
_repo, err := server.Config.Services.Forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err == nil {
|
||||
log.Debug().Msgf("Synced user permission for %s %s", user.Login, repo.FullName)
|
||||
perm = _repo.Perm
|
||||
perm.Repo = repo
|
||||
perm.RepoID = repo.ID
|
||||
perm.UserID = user.ID
|
||||
perm.Synced = time.Now().Unix()
|
||||
if err := _store.PermUpsert(perm); err != nil {
|
||||
@@ -127,10 +128,7 @@ func SetPerm() gin.HandlerFunc {
|
||||
perm.Admin = true
|
||||
}
|
||||
|
||||
switch {
|
||||
case repo.Visibility == model.VisibilityPublic:
|
||||
perm.Pull = true
|
||||
case repo.Visibility == model.VisibilityInternal && user != nil:
|
||||
if repo.Visibility == model.VisibilityPublic || (repo.Visibility == model.VisibilityInternal && user != nil) {
|
||||
perm.Pull = true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user