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)
This commit is contained in:
qwerty287 2023-08-28 18:57:44 +02:00 committed by GitHub
parent 25225d4902
commit 5bd12aa646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 18 deletions

View file

@ -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
}

View file

@ -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 all {
dbRepos, err := _store.RepoList(user, true, false)
if err != nil {
c.String(http.StatusInternalServerError, "Error fetching repository list. %s", err)
return
}
if all {
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)
}

View file

@ -68,6 +68,7 @@
"reload": "Reload repositories",
"enable": "Enable",
"enabled": "Already enabled",
"disabled": "Disabled",
"success": "Repository enabled",
"list_reloaded": "Repository list reloaded"
},

View file

@ -13,13 +13,14 @@
>
<span class="text-wp-text-100">{{ repo.full_name }}</span>
<span v-if="repo.active" class="ml-auto text-wp-text-alt-100">{{ $t('repo.enable.enabled') }}</span>
<div v-else class="ml-auto flex items-center">
<Badge v-if="repo.id" class="<md:hidden mr-2" :label="$t('repo.enable.disabled')" />
<Button
v-if="!repo.active"
class="ml-auto"
:text="$t('repo.enable.enable')"
:is-loading="isActivatingRepo && repoToActivate?.forge_remote_id === repo.forge_remote_id"
@click="activateRepo(repo)"
/>
</div>
</ListItem>
</div>
</Scaffold>
@ -30,6 +31,7 @@ import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import Badge from '~/components/atomic/Badge.vue';
import Button from '~/components/atomic/Button.vue';
import ListItem from '~/components/atomic/ListItem.vue';
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';