feat: using shields.io for all badges

This commit is contained in:
Carlos Alexandro Becker
2018-12-30 16:33:52 -02:00
parent 3ec84fb54f
commit 5f48725722
23 changed files with 51 additions and 28 deletions

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="88" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#4c1" d="M61 0h27v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="73.5" y="14">A+</text></g></svg>

Before

Width:  |  Height:  |  Size: 357 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="88" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="88" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#4c1" d="M61 0h27v20H61z"/><path fill="url(#b)" d="M0 0h88v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="73.5" y="15" fill="#010101" fill-opacity=".3">A+</text><text x="73.5" y="14">A+</text></g></svg>

Before

Width:  |  Height:  |  Size: 734 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="88" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="88" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#4c1" d="M61 0h27v18H61z"/><path fill="url(#b)" d="M0 0h88v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="73.5" y="14" fill="#010101" fill-opacity=".3">A+</text><text x="73.5" y="13">A+</text></g></svg>

Before

Width:  |  Height:  |  Size: 826 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#4c1" d="M61 0h17v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="68.5" y="14">A</text></g></svg>

Before

Width:  |  Height:  |  Size: 356 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#4c1" d="M61 0h17v20H61z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="68.5" y="15" fill="#010101" fill-opacity=".3">A</text><text x="68.5" y="14">A</text></g></svg>

Before

Width:  |  Height:  |  Size: 732 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="78" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#4c1" d="M61 0h17v18H61z"/><path fill="url(#b)" d="M0 0h78v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="68.5" y="14" fill="#010101" fill-opacity=".3">A</text><text x="68.5" y="13">A</text></g></svg>

Before

Width:  |  Height:  |  Size: 824 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#a4a61d" d="M61 0h17v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="68.5" y="14">B</text></g></svg>

Before

Width:  |  Height:  |  Size: 359 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#a4a61d" d="M61 0h17v20H61z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="68.5" y="15" fill="#010101" fill-opacity=".3">B</text><text x="68.5" y="14">B</text></g></svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="78" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#a4a61d" d="M61 0h17v18H61z"/><path fill="url(#b)" d="M0 0h78v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="68.5" y="14" fill="#010101" fill-opacity=".3">B</text><text x="68.5" y="13">B</text></g></svg>

Before

Width:  |  Height:  |  Size: 827 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#dfb317" d="M61 0h17v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="68.5" y="14">C</text></g></svg>

Before

Width:  |  Height:  |  Size: 359 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#dfb317" d="M61 0h17v20H61z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="68.5" y="15" fill="#010101" fill-opacity=".3">C</text><text x="68.5" y="14">C</text></g></svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="78" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#dfb317" d="M61 0h17v18H61z"/><path fill="url(#b)" d="M0 0h78v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="68.5" y="14" fill="#010101" fill-opacity=".3">C</text><text x="68.5" y="13">C</text></g></svg>

Before

Width:  |  Height:  |  Size: 827 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#fe7d37" d="M61 0h19v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="69.5" y="14">D</text></g></svg>

Before

Width:  |  Height:  |  Size: 359 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="80" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#fe7d37" d="M61 0h19v20H61z"/><path fill="url(#b)" d="M0 0h80v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="69.5" y="15" fill="#010101" fill-opacity=".3">D</text><text x="69.5" y="14">D</text></g></svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="80" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#fe7d37" d="M61 0h19v18H61z"/><path fill="url(#b)" d="M0 0h80v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="69.5" y="14" fill="#010101" fill-opacity=".3">D</text><text x="69.5" y="13">D</text></g></svg>

Before

Width:  |  Height:  |  Size: 827 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#e05d44" d="M61 0h17v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="68.5" y="14">E</text></g></svg>

Before

Width:  |  Height:  |  Size: 359 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#e05d44" d="M61 0h17v20H61z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="68.5" y="15" fill="#010101" fill-opacity=".3">E</text><text x="68.5" y="14">E</text></g></svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="78" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#e05d44" d="M61 0h17v18H61z"/><path fill="url(#b)" d="M0 0h78v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="68.5" y="14" fill="#010101" fill-opacity=".3">E</text><text x="68.5" y="13">E</text></g></svg>

Before

Width:  |  Height:  |  Size: 827 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><g shape-rendering="crispEdges"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#e05d44" d="M61 0h17v20H61z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="14">go report</text><text x="68.5" y="14">F</text></g></svg>

Before

Width:  |  Height:  |  Size: 359 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="78" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v20H0z"/><path fill="#e05d44" d="M61 0h17v20H61z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="30.5" y="15" fill="#010101" fill-opacity=".3">go report</text><text x="30.5" y="14">go report</text><text x="68.5" y="15" fill="#010101" fill-opacity=".3">F</text><text x="68.5" y="14">F</text></g></svg>

Before

Width:  |  Height:  |  Size: 735 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><mask id="a"><rect width="78" height="18" rx="4" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h61v18H0z"/><path fill="#e05d44" d="M61 0h17v18H61z"/><path fill="url(#b)" d="M0 0h78v18H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="31.5" y="14" fill="#010101" fill-opacity=".3">go report</text><text x="31.5" y="13">go report</text><text x="68.5" y="14" fill="#010101" fill-opacity=".3">F</text><text x="68.5" y="13">F</text></g></svg>

Before

Width:  |  Height:  |  Size: 827 B

View File

@@ -4,15 +4,10 @@ import (
"fmt"
"log"
"net/http"
"strings"
"github.com/gojp/goreportcard/check"
)
func badgePath(grade check.Grade, style string) string {
return fmt.Sprintf("assets/badges/%s_%s.svg", strings.ToLower(string(grade)), strings.ToLower(style))
}
// BadgeHandler handles fetching the badge images
func BadgeHandler(w http.ResponseWriter, r *http.Request, repo string) {
resp, err := newChecksResp(repo, false)
@@ -30,6 +25,26 @@ func BadgeHandler(w http.ResponseWriter, r *http.Request, repo string) {
return
}
w.Header().Set("Cache-control", "no-store, no-cache, must-revalidate")
http.ServeFile(w, r, badgePath(resp.Grade, style))
http.Redirect(w, r, badgeURL(resp.Grade, style), http.StatusTemporaryRedirect)
}
func badgeURL(grade check.Grade, style string) string {
var color string
switch grade {
case check.GradeAPlus:
color = "brightgreen"
case check.GradeA:
color = "green"
case check.GradeB:
color = "yellowgreen"
case check.GradeC:
color = "yellow"
case check.GradeD:
color = "orange"
case check.GradeE:
fallthrough
case check.GradeF:
color = "red"
}
return fmt.Sprintf("https://img.shields.io/badge/go%%20report-%s-%s.svg?style=%s", grade, color, style)
}

29
handlers/badge_test.go Normal file
View File

@@ -0,0 +1,29 @@
package handlers
import (
"testing"
"github.com/gojp/goreportcard/check"
)
func TestBadgeURL(t *testing.T) {
for grade, expectedURL := range map[check.Grade]string{
check.GradeAPlus: "https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=for-the-badge",
check.GradeA: "https://img.shields.io/badge/go%20report-A-green.svg?style=for-the-badge",
check.GradeB: "https://img.shields.io/badge/go%20report-B-yellowgreen.svg?style=for-the-badge",
check.GradeC: "https://img.shields.io/badge/go%20report-C-yellow.svg?style=for-the-badge",
check.GradeD: "https://img.shields.io/badge/go%20report-D-orange.svg?style=for-the-badge",
check.GradeE: "https://img.shields.io/badge/go%20report-E-red.svg?style=for-the-badge",
check.GradeF: "https://img.shields.io/badge/go%20report-F-red.svg?style=for-the-badge",
} {
grade := grade
expectedURL := expectedURL
t.Run(string(grade), func(t *testing.T) {
t.Parallel()
got := badgeURL(grade, "for-the-badge")
if got != expectedURL {
t.Errorf("expected %s, got %s", expectedURL, got)
}
})
}
}