didn't realize gin supports net.Context. Change to support Context pattern!

This commit is contained in:
Brad Rydzewski
2015-10-21 16:14:02 -07:00
parent af2ef2347a
commit cfdfbcfd3b
56 changed files with 1495 additions and 1051 deletions

View File

@@ -6,14 +6,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/drone/drone/model"
"github.com/drone/drone/router/middleware/context"
"github.com/drone/drone/router/middleware/session"
"github.com/drone/drone/shared/token"
"github.com/drone/drone/store"
)
func GetCommit(c *gin.Context) {
db := context.Database(c)
repo := session.Repo(c)
parsed, err := token.ParseRequest(c.Request, func(t *token.Token) (string, error) {
@@ -34,7 +32,7 @@ func GetCommit(c *gin.Context) {
branch = repo.Branch
}
build, err := model.GetBuildCommit(db, repo, commit, branch)
build, err := store.GetBuildCommit(c, repo, commit, branch)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
@@ -44,7 +42,6 @@ func GetCommit(c *gin.Context) {
}
func GetPullRequest(c *gin.Context) {
db := context.Database(c)
repo := session.Repo(c)
refs := fmt.Sprintf("refs/pull/%s/head", c.Param("number"))
@@ -60,7 +57,7 @@ func GetPullRequest(c *gin.Context) {
return
}
build, err := model.GetBuildRef(db, repo, refs)
build, err := store.GetBuildRef(c, repo, refs)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
@@ -70,7 +67,6 @@ func GetPullRequest(c *gin.Context) {
}
func RedirectSha(c *gin.Context) {
db := context.Database(c)
repo := session.Repo(c)
commit := c.Param("sha")
@@ -79,7 +75,7 @@ func RedirectSha(c *gin.Context) {
branch = repo.Branch
}
build, err := model.GetBuildCommit(db, repo, commit, branch)
build, err := store.GetBuildCommit(c, repo, commit, branch)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
@@ -90,11 +86,10 @@ func RedirectSha(c *gin.Context) {
}
func RedirectPullRequest(c *gin.Context) {
db := context.Database(c)
repo := session.Repo(c)
refs := fmt.Sprintf("refs/pull/%s/head", c.Param("number"))
build, err := model.GetBuildRef(db, repo, refs)
build, err := store.GetBuildRef(c, repo, refs)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return