Make OBS SVG badges theme-aware using Gitea CSS variables #107

Closed
schrodinger wants to merge 3 commits from schrodinger/autogits:main into main
2 changed files with 125 additions and 23 deletions

View File

@@ -41,6 +41,107 @@ const (
AppName = "obs-status-service"
)
const indexHTML = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>openSUSE OBS Status Service</title>
<style>
body {
font-family: sans-serif;
max-width: 900px;
margin: auto;
padding: 20px;
}
input {
width: 100%;
margin: 6px 0;
padding: 6px;
}
button {
padding: 6px 12px;
margin-top: 8px;
}
pre {
background: #f5f5f5;
padding: 10px;
overflow-x: auto;
}
img {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>OBS Status Service</h1>
<p>
This service reports build results from the openSUSE Build Service (OBS)
as easily embeddable SVG images. Repository build results are cached to
provide low-overhead access.
</p>
<h2>Usage</h2>
<p>Requests for individual build results:</p>
<pre>/status/obs:project/package/repo/arch</pre>
<p><em>package, repo and arch are optional.</em></p>
<p>Requests for project results:</p>
<pre>/status/obs:project</pre>
<p>
By default, SVG output is generated. JSON and XML output are available
by setting the <code>Accept</code> request header.
</p>
<h2>Generate Build Result Image</h2>
<label>Project (required)</label>
<input id="project" placeholder="devel:languages:python:Factory">
<label>Package (optional)</label>
<input id="package" placeholder="python313">
<label>Repo &amp; Arch (optional)</label>
<input id="repo" placeholder="openSUSE_Tumbleweed/x86_64">
<button onclick="generate()">Generate</button>
<h3>Link</h3>
<pre id="link"></pre>
<h3>Markdown</h3>
<pre id="markdown"></pre>
<h3>Preview</h3>
<img id="preview" alt="Build status preview">
<script>
function generate() {
const project = document.getElementById("project").value.trim();
const pkg = document.getElementById("package").value.trim();
const repo = document.getElementById("repo").value.trim();
if (!project) {
alert("Project is required");
return;
}
let url = "https://br.opensuse.org/status/" + project;
if (pkg) url += "/" + pkg;
if (repo) url += "/" + repo;
document.getElementById("link").textContent = url;
document.getElementById("markdown").textContent =
"![br](" + url + ")";
document.getElementById("preview").src = url;
}
</script>
</body>
</html>
`
var obs *common.ObsClient
type RepoBuildCounters struct {
@@ -271,8 +372,9 @@ func main() {
res.WriteHeader(500)
return
}
res.WriteHeader(404)
res.Write([]byte("404 page not found\n"))
res.Header().Set("Content-Type", "text/html; charset=utf-8")
res.WriteHeader(http.StatusOK)
res.Write([]byte(indexHTML))
})
http.HandleFunc("GET /status/{Project}", func(res http.ResponseWriter, req *http.Request) {
mime := ParseMimeHeader(req)

View File

@@ -28,46 +28,46 @@ func NewSvg(SvgType int) *SvgWriter {
case SvgType_Package:
svg.out.WriteString(`<defs>
<g id="s">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="green" fill="#efe" rx="5" />
<text x="2.5ex" y="1.1em">succeeded</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-success)" fill="var(--color-success)" fill-opacity="0.15" rx="5" />
<text x="2.5ex" y="1.1em" fill="var(--color-success)">succeeded</text>
</g>
<g id="f">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="red" fill="#fee" rx="5" />
<text x="5ex" y="1.1em">failed</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-danger)" fill="var(--color-danger)" fill-opacity="0.15" rx="5" />
<text x="5ex" y="1.1em" fill="var(--color-danger)">failed</text>
</g>
<g id="b">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="grey" fill="#fbf" rx="5" />
<text x="3.75ex" y="1.1em">blocked</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-warning)" fill="var(--color-warning)" fill-opacity="0.15" rx="5" />
<text x="3.75ex" y="1.1em" fill="var(--color-warning)">blocked</text>
</g>
<g id="broken">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="grey" fill="#fff" rx="5" />
<text x="4.5ex" y="1.1em" stroke="red" fill="red">broken</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-danger)" fill="none" rx="5" />
<text x="4.5ex" y="1.1em" stroke="red" fill="var(--color-danger)">broken</text>
</g>
<g id="build">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="yellow" fill="#664" rx="5" />
<text x="3.75ex" y="1.1em" fill="yellow">building</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-info)" fill="var(--color-info)" fill-opacity="0.15" rx="5" />
<text x="3.75ex" y="1.1em" fill="var(--color-info)">building</text>
</g>
<g id="u">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="yellow" fill="#555" rx="5" />
<text x="2ex" y="1.1em" fill="orange">unresolvable</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-warning)" fill="var(--color-warning)" fill-opacity="0.15" rx="5" />
<text x="2ex" y="1.1em" fill="var(--color-warning)">unresolvable</text>
</g>
<g id="scheduled">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="blue" fill="none" rx="5" />
<text x="3ex" y="1.1em" stroke="none" fill="blue">scheduled</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-info)" fill="none" rx="5" />
<text x="3ex" y="1.1em" stroke="none" fill="var(--color-info)">scheduled</text>
</g>
<g id="d">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="grey" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="grey">disabled</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-text)" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="var(--color-text)">disabled</text>
</g>
<g id="e">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="grey" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="#aaf">excluded</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-text)" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="var(--color-text)">excluded</text>
</g>
<g id="un">
<rect width="15ex" height="1.5em" stroke-width="1" stroke="grey" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="grey">unknown</text>
<rect width="15ex" height="1.5em" stroke-width="1" stroke="var(--color-text)" fill="none" rx="5" />
<text x="4ex" y="1.1em" stroke="none" fill="var(--color-text)">unknown</text>
</g>
<rect id="repotitle" width="100%" height="2em" stroke-width="1" stroke="grey" fill="grey" rx="2" />
<rect id="repotitle" width="100%" height="2em" stroke-width="1" stroke="var(--color-border)" fill="var(--color-bg-subtle)" rx="2" />
</defs>`)
case SvgType_Project: