coverage/main.go

37 lines
908 B
Go

package main
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
"strconv"
"strings"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/upload/go", uploadGo)
r.HandleFunc("/badge/commit/{commit}.svg", BadgeFromCommit)
r.HandleFunc("/badge/{project}/{tag}.svg", BadgeFromProject)
_ = http.ListenAndServe(":8080", r)
}
func parseCoverage(content string) float64 {
var totalStatements = 0
var totalRun = 0
lines := strings.Split(content, "\n")
for _, line := range lines[1 : len(lines)-1] { // Skip first line (which is not relevant)
sl := strings.Split(line, " ")
statements, _ := strconv.Atoi(sl[len(sl)-2])
runCount, _ := strconv.Atoi(sl[len(sl)-1])
totalStatements += statements
if runCount != 0 {
totalRun += statements
}
}
fmt.Printf("DEBUG :: TotalStatements: %d, TotalRunCount: %d\n", totalStatements, totalRun)
return float64(totalRun) / float64(totalStatements)
}