1
0
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:
Brad Rydzewski 2016-06-14 15:26:26 -07:00 committed by GitHub
commit f10d4679ee
6 changed files with 73 additions and 28 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

@ -103,6 +103,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
// requires push permissions
repo.PATCH("", session.MustPush, server.PatchRepo)
repo.DELETE("", session.MustPush, server.DeleteRepo)
repo.POST("/chown", session.MustPush, server.ChownRepo)
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)

View File

@ -26,7 +26,7 @@ func GetBuilds(c *gin.Context) {
c.AbortWithStatus(http.StatusInternalServerError)
return
}
c.IndentedJSON(http.StatusOK, builds)
c.JSON(http.StatusOK, builds)
}
func GetBuild(c *gin.Context) {
@ -54,7 +54,7 @@ func GetBuild(c *gin.Context) {
Jobs []*model.Job `json:"jobs"`
}{build, jobs}
c.IndentedJSON(http.StatusOK, &out)
c.JSON(http.StatusOK, &out)
}
func GetBuildLast(c *gin.Context) {
@ -73,7 +73,7 @@ func GetBuildLast(c *gin.Context) {
Jobs []*model.Job `json:"jobs"`
}{build, jobs}
c.IndentedJSON(http.StatusOK, &out)
c.JSON(http.StatusOK, &out)
}
func GetBuildLogs(c *gin.Context) {
@ -111,6 +111,7 @@ func GetBuildLogs(c *gin.Context) {
// TODO implement limited streaming to avoid crashing the browser
}
c.Header("Content-Type", "application/json")
stream.Copy(c.Writer, r)
}

View File

@ -152,7 +152,7 @@ func GetLoginToken(c *gin.Context) {
return
}
c.IndentedJSON(http.StatusOK, &tokenPayload{
c.JSON(http.StatusOK, &tokenPayload{
Access: tokenstr,
Expires: exp - time.Now().Unix(),
})

View File

@ -136,6 +136,19 @@ func PatchRepo(c *gin.Context) {
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) {
c.JSON(http.StatusOK, session.Repo(c))
}

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) {