From 8de93539e3ba06d034f23798fd23d3cbf7eb9482 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Jun 2016 14:01:20 -0700 Subject: [PATCH 1/3] use correct content-type for logs --- server/build.go | 7 ++++--- server/login.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/build.go b/server/build.go index e3d50052e..91f7df8d1 100644 --- a/server/build.go +++ b/server/build.go @@ -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) } diff --git a/server/login.go b/server/login.go index a234d3849..af784222e 100644 --- a/server/login.go +++ b/server/login.go @@ -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(), }) From d656b2a75be530cba90bb5a7dee8d8094cd16221 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Jun 2016 14:05:53 -0700 Subject: [PATCH 2/3] add chown command to switch repo owner --- router/router.go | 1 + server/repo.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/router/router.go b/router/router.go index 370d7b8f3..43b7cd4ea 100644 --- a/router/router.go +++ b/router/router.go @@ -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) diff --git a/server/repo.go b/server/repo.go index 08163afb4..2a089e0b2 100644 --- a/server/repo.go +++ b/server/repo.go @@ -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)) } From 769551cb44132533d72c6c6fb44aaad9f92285ec Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Jun 2016 15:20:17 -0700 Subject: [PATCH 3/3] ability to pull full vs partial list --- model/repo.go | 38 +++++++++++++++++++------------------- server/user.go | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/model/repo.go b/model/repo.go index 062f53131..6baaf81f5 100644 --- a/model/repo.go +++ b/model/repo.go @@ -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"` } diff --git a/server/user.go b/server/user.go index e2ab0567d..9f4a377e3 100644 --- a/server/user.go +++ b/server/user.go @@ -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) {