forked from git-workflow/autogits
Compare commits
1 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| d24b8446c0 |
@@ -439,3 +439,60 @@ func main() {
|
||||
log.Fatal(http.ListenAndServeTLS(*listen, *cert, *key, nil))
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectStatusBarSvg(res []*common.BuildResult) []byte {
|
||||
// TODO: Implement custom SVG output with just one bar
|
||||
// [success-other-failures] n / total
|
||||
|
||||
if len(res) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
list := common.BuildResultList{
|
||||
Result: res,
|
||||
}
|
||||
package_names := list.GetPackageList()
|
||||
maxLen := 0
|
||||
for _, p := range package_names {
|
||||
maxLen = max(maxLen, len(p))
|
||||
}
|
||||
|
||||
// width := float32(len(list.Result))*1.5 + float32(maxLen)*0.8
|
||||
// height := 1.5*float32(maxLen) + 30
|
||||
ret := NewSvg(SvgType_Project)
|
||||
|
||||
status := make([]RepoBuildCounters, len(res))
|
||||
|
||||
for i, repo := range res {
|
||||
status[i].Arch = repo.Arch
|
||||
status[i].Repository = repo.Repository
|
||||
status[i].Status = repo.Code
|
||||
status[i].BuildStatusCounter = make(map[string]int)
|
||||
|
||||
for _, pkg := range repo.Status {
|
||||
status[i].BuildStatusCounter[pkg.Code]++
|
||||
}
|
||||
}
|
||||
slices.SortFunc(status, func(a, b RepoBuildCounters) int {
|
||||
if r := strings.Compare(a.Repository, b.Repository); r != 0 {
|
||||
return r
|
||||
}
|
||||
return strings.Compare(a.Arch, b.Arch)
|
||||
})
|
||||
repoName := ""
|
||||
ret.ypos = 3.0
|
||||
for _, repo := range status {
|
||||
if repo.Repository != repoName {
|
||||
repoName = repo.Repository
|
||||
ret.WriteTitle(repoName)
|
||||
}
|
||||
|
||||
ret.WriteSubtitle(repo.Arch)
|
||||
statuses := slices.Sorted(maps.Keys(repo.BuildStatusCounter))
|
||||
for _, status := range statuses {
|
||||
ret.WriteProjectStatus(res[0].Project, repo.Repository, repo.Arch, status, repo.BuildStatusCounter[status])
|
||||
}
|
||||
}
|
||||
|
||||
return ret.GenerateSvg()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
@@ -82,3 +84,14 @@ func TestStatusSvg(t *testing.T) {
|
||||
os.WriteFile("testpackage.svg", PackageStatusSummarySvg("pkg2", data), 0o777)
|
||||
os.WriteFile("testproject.svg", ProjectStatusSummarySvg(data), 0o777)
|
||||
}
|
||||
|
||||
func TestStatusBarSvg(t *testing.T) {
|
||||
ObsUrl = &[]string{"http://nothing.is.here"}[0]
|
||||
content, err := os.ReadFile("test-data/python-pytest.json")
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
}
|
||||
var data []*common.BuildResult
|
||||
json.Unmarshal(content, &data)
|
||||
os.WriteFile("python-pytest.svg", ProjectStatusBarSvg(data), 0o777)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user