mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-24 08:02:18 +02:00
Merge pull request #1678 from bradrydzewski/master
adds a query parameter to pull active repos vs all repos
This commit is contained in:
commit
f10d4679ee
@ -11,23 +11,23 @@ type RepoLite struct {
|
|||||||
//
|
//
|
||||||
// swagger:model repo
|
// swagger:model repo
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
ID int64 `json:"id" meddler:"repo_id,pk"`
|
ID int64 `json:"id,omitempty" meddler:"repo_id,pk"`
|
||||||
UserID int64 `json:"-" meddler:"repo_user_id"`
|
UserID int64 `json:"-" meddler:"repo_user_id"`
|
||||||
Owner string `json:"owner" meddler:"repo_owner"`
|
Owner string `json:"owner" meddler:"repo_owner"`
|
||||||
Name string `json:"name" meddler:"repo_name"`
|
Name string `json:"name" meddler:"repo_name"`
|
||||||
FullName string `json:"full_name" meddler:"repo_full_name"`
|
FullName string `json:"full_name" meddler:"repo_full_name"`
|
||||||
Avatar string `json:"avatar_url" meddler:"repo_avatar"`
|
Avatar string `json:"avatar_url,omitempty" meddler:"repo_avatar"`
|
||||||
Link string `json:"link_url" meddler:"repo_link"`
|
Link string `json:"link_url,omitempty" meddler:"repo_link"`
|
||||||
Kind string `json:"scm" meddler:"repo_scm"`
|
Kind string `json:"scm,omitempty" meddler:"repo_scm"`
|
||||||
Clone string `json:"clone_url" meddler:"repo_clone"`
|
Clone string `json:"clone_url,omitempty" meddler:"repo_clone"`
|
||||||
Branch string `json:"default_branch" meddler:"repo_branch"`
|
Branch string `json:"default_branch,omitempty" meddler:"repo_branch"`
|
||||||
Timeout int64 `json:"timeout" meddler:"repo_timeout"`
|
Timeout int64 `json:"timeout,omitempty" meddler:"repo_timeout"`
|
||||||
IsPrivate bool `json:"private" meddler:"repo_private"`
|
IsPrivate bool `json:"private,omitempty" meddler:"repo_private"`
|
||||||
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
|
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
|
||||||
IsStarred bool `json:"starred,omitempty" meddler:"-"`
|
IsStarred bool `json:"starred,omitempty" meddler:"-"`
|
||||||
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
|
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
|
||||||
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
|
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
|
||||||
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
|
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
|
||||||
AllowTag bool `json:"allow_tags" meddler:"repo_allow_tags"`
|
AllowTag bool `json:"allow_tags" meddler:"repo_allow_tags"`
|
||||||
Hash string `json:"-" meddler:"repo_hash"`
|
Hash string `json:"-" meddler:"repo_hash"`
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|||||||
// requires push permissions
|
// requires push permissions
|
||||||
repo.PATCH("", session.MustPush, server.PatchRepo)
|
repo.PATCH("", session.MustPush, server.PatchRepo)
|
||||||
repo.DELETE("", session.MustPush, server.DeleteRepo)
|
repo.DELETE("", session.MustPush, server.DeleteRepo)
|
||||||
|
repo.POST("/chown", session.MustPush, server.ChownRepo)
|
||||||
|
|
||||||
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
|
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
|
||||||
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)
|
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)
|
||||||
|
@ -26,7 +26,7 @@ func GetBuilds(c *gin.Context) {
|
|||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.IndentedJSON(http.StatusOK, builds)
|
c.JSON(http.StatusOK, builds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuild(c *gin.Context) {
|
func GetBuild(c *gin.Context) {
|
||||||
@ -54,7 +54,7 @@ func GetBuild(c *gin.Context) {
|
|||||||
Jobs []*model.Job `json:"jobs"`
|
Jobs []*model.Job `json:"jobs"`
|
||||||
}{build, jobs}
|
}{build, jobs}
|
||||||
|
|
||||||
c.IndentedJSON(http.StatusOK, &out)
|
c.JSON(http.StatusOK, &out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuildLast(c *gin.Context) {
|
func GetBuildLast(c *gin.Context) {
|
||||||
@ -73,7 +73,7 @@ func GetBuildLast(c *gin.Context) {
|
|||||||
Jobs []*model.Job `json:"jobs"`
|
Jobs []*model.Job `json:"jobs"`
|
||||||
}{build, jobs}
|
}{build, jobs}
|
||||||
|
|
||||||
c.IndentedJSON(http.StatusOK, &out)
|
c.JSON(http.StatusOK, &out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuildLogs(c *gin.Context) {
|
func GetBuildLogs(c *gin.Context) {
|
||||||
@ -111,6 +111,7 @@ func GetBuildLogs(c *gin.Context) {
|
|||||||
// TODO implement limited streaming to avoid crashing the browser
|
// TODO implement limited streaming to avoid crashing the browser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Header("Content-Type", "application/json")
|
||||||
stream.Copy(c.Writer, r)
|
stream.Copy(c.Writer, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ func GetLoginToken(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.IndentedJSON(http.StatusOK, &tokenPayload{
|
c.JSON(http.StatusOK, &tokenPayload{
|
||||||
Access: tokenstr,
|
Access: tokenstr,
|
||||||
Expires: exp - time.Now().Unix(),
|
Expires: exp - time.Now().Unix(),
|
||||||
})
|
})
|
||||||
|
@ -136,6 +136,19 @@ func PatchRepo(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, repo)
|
c.JSON(http.StatusOK, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChownRepo(c *gin.Context) {
|
||||||
|
repo := session.Repo(c)
|
||||||
|
user := session.User(c)
|
||||||
|
repo.UserID = user.ID
|
||||||
|
|
||||||
|
err := store.UpdateRepo(c, repo)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, repo)
|
||||||
|
}
|
||||||
|
|
||||||
func GetRepo(c *gin.Context) {
|
func GetRepo(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, session.Repo(c))
|
c.JSON(http.StatusOK, session.Repo(c))
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
|
|
||||||
"github.com/drone/drone/cache"
|
"github.com/drone/drone/cache"
|
||||||
|
"github.com/drone/drone/model"
|
||||||
"github.com/drone/drone/router/middleware/session"
|
"github.com/drone/drone/router/middleware/session"
|
||||||
"github.com/drone/drone/shared/token"
|
"github.com/drone/drone/shared/token"
|
||||||
"github.com/drone/drone/store"
|
"github.com/drone/drone/store"
|
||||||
@ -35,26 +36,55 @@ func GetFeed(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetRepos(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 {
|
if flush {
|
||||||
log.Debugf("Evicting repository cache for user %s.", user.Login)
|
log.Debugf("Evicting repository cache for user %s.", user.Login)
|
||||||
cache.DeleteRepos(c, user)
|
cache.DeleteRepos(c, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
repos, err := cache.GetRepos(c, user)
|
remote, err := cache.GetRepos(c, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, "Error fetching repository list. %s", err)
|
c.String(500, "Error fetching repository list. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repos_, err := store.GetRepoListOf(c, repos)
|
repos, err := store.GetRepoListOf(c, remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, "Error fetching repository list. %s", err)
|
c.String(500, "Error fetching repository list. %s", err)
|
||||||
return
|
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) {
|
func GetRemoteRepos(c *gin.Context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user