func RedirectPullRequest(c *gin.Context) { repo := session.Repo(c) refs := fmt.Sprintf("refs/pull/%s/head", c.Param("number")) build, err := store.GetBuildRef(c, repo, refs) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } path := fmt.Sprintf("/%s/%s/%d", repo.Owner, repo.Name, build.Number) c.Redirect(http.StatusSeeOther, path) }
func GetPullRequest(c *gin.Context) { repo := session.Repo(c) refs := fmt.Sprintf("refs/pull/%s/head", c.Param("number")) parsed, err := token.ParseRequest(c.Request, func(t *token.Token) (string, error) { return repo.Hash, nil }) if err != nil { c.AbortWithError(http.StatusBadRequest, err) return } if parsed.Text != repo.FullName { c.AbortWithStatus(http.StatusUnauthorized) return } build, err := store.GetBuildRef(c, repo, refs) if err != nil { c.AbortWithError(http.StatusNotFound, err) return } c.JSON(http.StatusOK, build) }