package server import ( "fmt" log "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "github.com/drone/drone/model" "github.com/drone/drone/shared/httputil" "github.com/drone/drone/store" ) var ( badgeSuccess = `buildbuildsuccesssuccess` badgeFailure = `buildbuildfailurefailure` badgeStarted = `buildbuildstartedstarted` badgeError = `buildbuilderrorerror` badgeNone = `buildbuildnonenone` ) 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 { log.Warning(err) c.String(200, 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(200, badgeNone) } } func GetCC(c *gin.Context) { repo, err := store.GetRepoOwnerName(c, c.Param("owner"), c.Param("name"), ) if err != nil { c.AbortWithStatus(404) return } builds, err := store.GetBuildList(c, repo) if err != nil || len(builds) == 0 { c.AbortWithStatus(404) return } url := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, builds[0].Number) cc := model.NewCC(repo, builds[0], url) c.XML(200, cc) }