coverage/main.go

38 lines
909 B
Go

package main
import (
"fmt"
"net/http"
"strconv"
"strings"
"github.com/gorilla/mux"
)
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)
}