fix(viewer): externalize repos page inline script to comply with CSP (#758)

* move inline scripts from repos.html to repos.js

* fixup

* fix: include repos.js in embedded assets
This commit is contained in:
Tao Xin 2026-08-07 12:35:17 +09:00 committed by GitHub
parent 3c60eb6af8
commit 6aa3f50033
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 22 deletions

View file

@ -14,7 +14,7 @@ import (
"time"
)
//go:embed templates/*.html static/style.css static/session.js
//go:embed templates/*.html static/style.css static/session.js static/repos.js
var assets embed.FS
func StartServer(addr string) error {

View file

@ -84,10 +84,7 @@ func TestRenderTemplate_WithRepos(t *testing.T) {
`id="repository-search-input"`,
`id="repositories-table"`,
"data-repository-name",
`addEventListener("input"`,
"toLowerCase()",
"name.includes(query)",
"row.hidden",
`src="/static/repos.js"`,
} {
if !strings.Contains(body, required) {
t.Errorf("rendered repository page missing %q", required)

View file

@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 alibaba/open-code-review Contributors
(() => {
const input = document.getElementById("repository-search-input");
const table = document.getElementById("repositories-table");
if (!input || !table) return;
const rows = table.querySelectorAll("tbody tr");
input.addEventListener("input", () => {
const query = input.value.trim().toLowerCase();
rows.forEach((row) => {
const nameCell = row.querySelector("[data-repository-name]");
const name = nameCell ? nameCell.textContent.trim().toLowerCase() : "";
row.hidden = !name.includes(query);
});
});
})();

View file

@ -28,23 +28,7 @@
{{end}}
</tbody>
</table>
<script>
(() => {
const input = document.getElementById("repository-search-input");
const table = document.getElementById("repositories-table");
if (!input || !table) return;
const rows = table.querySelectorAll("tbody tr");
input.addEventListener("input", () => {
const query = input.value.trim().toLowerCase();
rows.forEach((row) => {
const nameCell = row.querySelector("[data-repository-name]");
const name = nameCell ? nameCell.textContent.trim().toLowerCase() : "";
row.hidden = !name.includes(query);
});
});
})();
</script>
<script src="/static/repos.js"></script>
{{else}}
<p>No session data found. Run a code review first.</p>
{{end}}