func GetBuildLast(c *gin.Context) { repo := session.Repo(c) branch := c.DefaultQuery("branch", repo.Branch) build, err := store.GetBuildLast(c, repo, branch) if err != nil { c.String(http.StatusInternalServerError, err.Error()) return } jobs, _ := store.GetJobList(c, build) out := struct { *model.Build Jobs []*model.Job `json:"jobs"` }{build, jobs} c.IndentedJSON(http.StatusOK, &out) }
func GetBadge(c *gin.Context) { repo, err := store.GetRepoOwnerName(c, c.Param("owner"), c.Param("name"), ) if err != nil { c.AbortWithStatus(404) return } // an SVG response is always served, even when error, so // we can go ahead and set the content type appropriately. c.Writer.Header().Set("Content-Type", "image/svg+xml") // if no commit was found then display // the 'none' badge, instead of throwing // an error response branch := c.Query("branch") if len(branch) == 0 { branch = repo.Branch } build, err := store.GetBuildLast(c, repo, branch) if err != nil { c.String(404, badgeNone) return } switch build.Status { case model.StatusSuccess: c.String(200, badgeSuccess) case model.StatusFailure: c.String(200, badgeFailure) case model.StatusError, model.StatusKilled: c.String(200, badgeError) case model.StatusPending, model.StatusRunning: c.String(200, badgeStarted) default: c.String(404, badgeNone) } }