1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00

ability to pull full vs partial list

This commit is contained in:
Brad Rydzewski 2016-06-14 15:20:17 -07:00
parent d656b2a75b
commit 769551cb44
2 changed files with 54 additions and 24 deletions

View File

@ -11,23 +11,23 @@ type RepoLite struct {
//
// swagger:model repo
type Repo struct {
ID int64 `json:"id" meddler:"repo_id,pk"`
UserID int64 `json:"-" meddler:"repo_user_id"`
Owner string `json:"owner" meddler:"repo_owner"`
Name string `json:"name" meddler:"repo_name"`
FullName string `json:"full_name" meddler:"repo_full_name"`
Avatar string `json:"avatar_url" meddler:"repo_avatar"`
Link string `json:"link_url" meddler:"repo_link"`
Kind string `json:"scm" meddler:"repo_scm"`
Clone string `json:"clone_url" meddler:"repo_clone"`
Branch string `json:"default_branch" meddler:"repo_branch"`
Timeout int64 `json:"timeout" meddler:"repo_timeout"`
IsPrivate bool `json:"private" meddler:"repo_private"`
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
IsStarred bool `json:"starred,omitempty" meddler:"-"`
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
AllowTag bool `json:"allow_tags" meddler:"repo_allow_tags"`
Hash string `json:"-" meddler:"repo_hash"`
ID int64 `json:"id,omitempty" meddler:"repo_id,pk"`
UserID int64 `json:"-" meddler:"repo_user_id"`
Owner string `json:"owner" meddler:"repo_owner"`
Name string `json:"name" meddler:"repo_name"`
FullName string `json:"full_name" meddler:"repo_full_name"`
Avatar string `json:"avatar_url,omitempty" meddler:"repo_avatar"`
Link string `json:"link_url,omitempty" meddler:"repo_link"`
Kind string `json:"scm,omitempty" meddler:"repo_scm"`
Clone string `json:"clone_url,omitempty" meddler:"repo_clone"`
Branch string `json:"default_branch,omitempty" meddler:"repo_branch"`
Timeout int64 `json:"timeout,omitempty" meddler:"repo_timeout"`
IsPrivate bool `json:"private,omitempty" meddler:"repo_private"`
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
IsStarred bool `json:"starred,omitempty" meddler:"-"`
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
AllowTag bool `json:"allow_tags" meddler:"repo_allow_tags"`
Hash string `json:"-" meddler:"repo_hash"`
}

View File

@ -10,6 +10,7 @@ import (
"github.com/gorilla/securecookie"
"github.com/drone/drone/cache"
"github.com/drone/drone/model"
"github.com/drone/drone/router/middleware/session"
"github.com/drone/drone/shared/token"
"github.com/drone/drone/store"
@ -35,26 +36,55 @@ func GetFeed(c *gin.Context) {
}
func GetRepos(c *gin.Context) {
user := session.User(c)
var (
user = session.User(c)
all, _ = strconv.ParseBool(c.Query("all"))
flush, _ = strconv.ParseBool(c.Query("flush"))
)
flush, _ := strconv.ParseBool(c.Query("flush"))
if flush {
log.Debugf("Evicting repository cache for user %s.", user.Login)
cache.DeleteRepos(c, user)
}
repos, err := cache.GetRepos(c, user)
remote, err := cache.GetRepos(c, user)
if err != nil {
c.String(500, "Error fetching repository list. %s", err)
return
}
repos_, err := store.GetRepoListOf(c, repos)
repos, err := store.GetRepoListOf(c, remote)
if err != nil {
c.String(500, "Error fetching repository list. %s", err)
return
}
c.JSON(http.StatusOK, repos_)
if !all {
c.JSON(http.StatusOK, repos)
return
}
// below we combine the two lists to include both active and inactive
// repositories. This is displayed on the settings screen to enable
// toggling on / off repository settings.
repom := map[string]bool{}
for _, repo := range repos {
repom[repo.FullName] = true
}
for _, repo := range remote {
if repom[repo.FullName] {
continue
}
repos = append(repos, &model.Repo{
Avatar: repo.Avatar,
FullName: repo.FullName,
Owner: repo.Owner,
Name: repo.Name,
})
}
c.JSON(http.StatusOK, repos)
}
func GetRemoteRepos(c *gin.Context) {