diff --git a/server/handler/badge.go b/server/handler/badge.go
index 98a502de..5fe9d2ff 100644
--- a/server/handler/badge.go
+++ b/server/handler/badge.go
@@ -13,13 +13,34 @@ import (
// badges that indicate the current build status for a repository
// and branch combination.
-var (
- badgeSuccess = []byte(``)
- badgeFailure = []byte(``)
- badgeStarted = []byte(``)
- badgeError = []byte(``)
- badgeNone = []byte(``)
-)
+type badge struct {
+ success, failure, started, err, none []byte
+}
+
+var defaultBadge = badge{
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+}
+
+var badgeStyles = map[string]badge{
+ "flat": badge{
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ },
+ "flat-square": badge{
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ []byte(``),
+ },
+}
// GetBadge accepts a request to retrieve the named
// repo and branhes latest build details from the datastore
@@ -34,15 +55,21 @@ func GetBadge(c web.C, w http.ResponseWriter, r *http.Request) {
owner = c.URLParams["owner"]
name = c.URLParams["name"]
branch = r.FormValue("branch")
+ style = r.FormValue("style")
)
// an SVG response is always served, even when error, so
// we can go ahead and set the content type appropriately.
w.Header().Set("Content-Type", "image/svg+xml")
+ badge, ok := badgeStyles[style]
+ if !ok {
+ badge = defaultBadge
+ }
+
repo, err := datastore.GetRepoName(ctx, host, owner, name)
if err != nil {
- w.Write(badgeNone)
+ w.Write(badge.none)
return
}
if len(branch) == 0 {
@@ -54,21 +81,21 @@ func GetBadge(c web.C, w http.ResponseWriter, r *http.Request) {
// the 'none' badge, instead of throwing
// an error response
if commit == nil {
- w.Write(badgeNone)
+ w.Write(badge.none)
return
}
switch commit.Status {
case model.StatusSuccess:
- w.Write(badgeSuccess)
+ w.Write(badge.success)
case model.StatusFailure:
- w.Write(badgeFailure)
+ w.Write(badge.failure)
case model.StatusError:
- w.Write(badgeError)
+ w.Write(badge.err)
case model.StatusEnqueue, model.StatusStarted:
- w.Write(badgeStarted)
+ w.Write(badge.started)
default:
- w.Write(badgeNone)
+ w.Write(badge.none)
}
}
@@ -88,7 +115,7 @@ func GetCC(c web.C, w http.ResponseWriter, r *http.Request) {
repo, err := datastore.GetRepoName(ctx, host, owner, name)
if err != nil {
- w.Write(badgeNone)
+ w.Write(defaultBadge.none)
return
}
commits, err := datastore.GetCommitList(ctx, repo)