From 5bd12aa64600706c67732f2c393c6c1dd0d61897 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:57:44 +0200 Subject: [PATCH] Show that repo is disabled (#2340) And allow to show badges for disabled repos Fixes 3rd checkbox from https://github.com/woodpecker-ci/woodpecker/discussions/2162#discussion-5498655 ![Screenshot 2023-08-28 at 11-13-23 Woodpecker](https://github.com/woodpecker-ci/woodpecker/assets/80460567/d881f0c5-6225-4921-9d05-a26f27ad5365) --- server/api/badge.go | 4 ++-- server/api/user.go | 25 ++++++++++++++++--------- web/src/assets/locales/en.json | 1 + web/src/views/RepoAdd.vue | 16 +++++++++------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/server/api/badge.go b/server/api/badge.go index e99bc1535..e5c04e7ac 100644 --- a/server/api/badge.go +++ b/server/api/badge.go @@ -61,8 +61,8 @@ func GetBadge(c *gin.Context) { repo, err = _store.GetRepo(repoID) } - if err != nil || !repo.IsActive { - if err == nil || errors.Is(err, types.RecordNotExist) { + if err != nil { + if errors.Is(err, types.RecordNotExist) { c.AbortWithStatus(http.StatusNotFound) return } diff --git a/server/api/user.go b/server/api/user.go index a1b3d4d5c..a15739252 100644 --- a/server/api/user.go +++ b/server/api/user.go @@ -21,6 +21,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gorilla/securecookie" + "github.com/woodpecker-ci/woodpecker/server" "github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/router/middleware/session" @@ -90,15 +91,15 @@ func GetRepos(c *gin.Context) { user := session.User(c) all, _ := strconv.ParseBool(c.Query("all")) - activeRepos, err := _store.RepoList(user, true, true) - if err != nil { - c.String(http.StatusInternalServerError, "Error fetching repository list. %s", err) - return - } - if all { + dbRepos, err := _store.RepoList(user, true, false) + if err != nil { + c.String(http.StatusInternalServerError, "Error fetching repository list. %s", err) + return + } + active := map[model.ForgeRemoteID]*model.Repo{} - for _, r := range activeRepos { + for _, r := range dbRepos { active[r.ForgeRemoteID] = r } @@ -111,10 +112,10 @@ func GetRepos(c *gin.Context) { var repos []*model.Repo for _, r := range _repos { if r.Perm.Push { - if active[r.ForgeRemoteID] != nil && active[r.ForgeRemoteID].IsActive { + if active[r.ForgeRemoteID] != nil { existingRepo := active[r.ForgeRemoteID] existingRepo.Update(r) - existingRepo.IsActive = true + existingRepo.IsActive = active[r.ForgeRemoteID].IsActive repos = append(repos, existingRepo) } else { repos = append(repos, r) @@ -126,6 +127,12 @@ func GetRepos(c *gin.Context) { return } + activeRepos, err := _store.RepoList(user, true, true) + if err != nil { + c.String(http.StatusInternalServerError, "Error fetching repository list. %s", err) + return + } + c.JSON(http.StatusOK, activeRepos) } diff --git a/web/src/assets/locales/en.json b/web/src/assets/locales/en.json index e07b88c14..da94a3de3 100644 --- a/web/src/assets/locales/en.json +++ b/web/src/assets/locales/en.json @@ -68,6 +68,7 @@ "reload": "Reload repositories", "enable": "Enable", "enabled": "Already enabled", + "disabled": "Disabled", "success": "Repository enabled", "list_reloaded": "Repository list reloaded" }, diff --git a/web/src/views/RepoAdd.vue b/web/src/views/RepoAdd.vue index 3c1025333..ecb9a9de1 100644 --- a/web/src/views/RepoAdd.vue +++ b/web/src/views/RepoAdd.vue @@ -13,13 +13,14 @@ > {{ repo.full_name }} {{ $t('repo.enable.enabled') }} -