Add link to blocked BR in package summary #98

Open
michals wants to merge 1 commits from michals/autogits:linkify into main
2 changed files with 35 additions and 13 deletions

View File

@@ -103,16 +103,6 @@ func ProjectStatusSummarySvg(res []*common.BuildResult) []byte {
return ret.GenerateSvg() return ret.GenerateSvg()
} }
func LinkToBuildlog(R *common.BuildResult, S *common.PackageBuildStatus) string {
if R != nil && S != nil {
switch S.Code {
case "succeeded", "failed", "building":
return "/buildlog/" + url.PathEscape(R.Project) + "/" + url.PathEscape(S.Package) + "/" + url.PathEscape(R.Repository) + "/" + url.PathEscape(R.Arch)
}
}
return ""
}
func DeleteExceptPkg(pkg string) func(*common.PackageBuildStatus) bool { func DeleteExceptPkg(pkg string) func(*common.PackageBuildStatus) bool {
return func(item *common.PackageBuildStatus) bool { return func(item *common.PackageBuildStatus) bool {
multibuild_prefix := pkg + ":" multibuild_prefix := pkg + ":"
@@ -155,8 +145,7 @@ func PackageStatusSummarySvg(pkg string, res []*common.BuildResult) []byte {
for _, s := range r.Status { for _, s := range r.Status {
if s.Package == pkg { if s.Package == pkg {
link := LinkToBuildlog(r, s) ret.WritePackageStatus(r, s)
ret.WritePackageStatus(link, r.Arch, s.Code, s.Details)
} }
} }
} }

View File

@@ -6,6 +6,8 @@ import (
"html" "html"
"net/url" "net/url"
"slices" "slices"
"src.opensuse.org/autogits/common"
) )
type SvgWriter struct { type SvgWriter struct {
@@ -19,6 +21,23 @@ const (
SvgType_Project SvgType_Project
) )
func LinkToBuildlogAlways(R *common.BuildResult, S *common.PackageBuildStatus) string {
if R != nil && S != nil {
return "/buildlog/" + url.PathEscape(R.Project) + "/" + url.PathEscape(S.Package) + "/" + url.PathEscape(R.Repository) + "/" + url.PathEscape(R.Arch)
}
return ""
}
func LinkToBuildlog(R *common.BuildResult, S *common.PackageBuildStatus) string {
if R != nil && S != nil {
switch S.Code {
case "succeeded", "failed", "building":
LinkToBuildlogAlways(R, S)
}
}
return ""
}
func NewSvg(SvgType int) *SvgWriter { func NewSvg(SvgType int) *SvgWriter {
svg := &SvgWriter{} svg := &SvgWriter{}
svg.header = []byte(`<svg version="2.0" overflow="auto" width="40ex" height="`) svg.header = []byte(`<svg version="2.0" overflow="auto" width="40ex" height="`)
@@ -89,7 +108,11 @@ func (svg *SvgWriter) WriteSubtitle(subtitle string) {
svg.ypos += 2 svg.ypos += 2
} }
func (svg *SvgWriter) WritePackageStatus(loglink, arch, status, detail string) { func (svg *SvgWriter) WritePackageStatus(r *common.BuildResult, s *common.PackageBuildStatus) {
loglink := LinkToBuildlogAlways(r, s)
arch := r.Arch
status := s.Code
detail := s.Details
StatusToSVG := func(S string) string { StatusToSVG := func(S string) string {
switch S { switch S {
case "succeeded": case "succeeded":
@@ -112,8 +135,18 @@ func (svg *SvgWriter) WritePackageStatus(loglink, arch, status, detail string) {
return "un" return "un"
} }
if len(loglink) > 0 {
u, err := url.Parse(loglink)
if err == nil {
svg.out.WriteString(`<a href="` + u.String() + `" target="_blank" rel="noopener">`)
}
}
svg.out.WriteString(`<text fill="#113" x="5ex" y="` + fmt.Sprint(svg.ypos-.6) + `em">` + html.EscapeString(arch) + `</text>`) svg.out.WriteString(`<text fill="#113" x="5ex" y="` + fmt.Sprint(svg.ypos-.6) + `em">` + html.EscapeString(arch) + `</text>`)
if len(loglink) > 0 {
svg.out.WriteString(`</a>`)
}
svg.out.WriteString(`<g>`) svg.out.WriteString(`<g>`)
loglink = LinkToBuildlog(r, s)
if len(loglink) > 0 { if len(loglink) > 0 {
u, err := url.Parse(loglink) u, err := url.Parse(loglink)
if err == nil { if err == nil {