Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env node
|
||||
// Upserts a sticky PR comment on Gitea identified by COMMENT_MARKER
|
||||
// (default: `<!-- coverage-report -->`). Reads coverage-comment.md from the
|
||||
// workflow's cwd and updates an existing comment if found, otherwise
|
||||
// creates a new one.
|
||||
//
|
||||
// Environment:
|
||||
// GITEA_TOKEN required. PAT with repository write scope.
|
||||
// GITEA_HOST default: git.tool-ctrl.de
|
||||
// REPO "owner/repo" (provided by Gitea workflow context).
|
||||
// PR_NUMBER PR number to post on.
|
||||
// COMMENT_PATH optional, default: coverage-comment.md
|
||||
// COMMENT_MARKER optional, default: <!-- coverage-report -->
|
||||
|
||||
import fs from "node:fs";
|
||||
|
||||
async function main() {
|
||||
const token = process.env.GITEA_TOKEN;
|
||||
const host = process.env.GITEA_HOST || "git.tool-ctrl.de";
|
||||
const repo = process.env.REPO;
|
||||
const prNumber = process.env.PR_NUMBER;
|
||||
const commentPath = process.env.COMMENT_PATH || "coverage-comment.md";
|
||||
const marker = process.env.COMMENT_MARKER || "<!-- coverage-report -->";
|
||||
|
||||
if (!token || !repo || !prNumber) {
|
||||
console.error("post-coverage-gitea-comment: missing GITEA_TOKEN / REPO / PR_NUMBER env vars");
|
||||
process.exit(0); // soft-skip: workflow stays green
|
||||
}
|
||||
if (!fs.existsSync(commentPath)) {
|
||||
console.error(`post-coverage-gitea-comment: ${commentPath} not found, skipping`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const body = fs.readFileSync(commentPath, "utf8");
|
||||
const apiBase = `https://${host}/api/v1/repos/${repo}/issues/${prNumber}/comments`;
|
||||
const headers = {
|
||||
Authorization: `token ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
};
|
||||
|
||||
const listRes = await fetch(apiBase, { headers });
|
||||
if (!listRes.ok) {
|
||||
console.error(`Gitea list-comments failed: ${listRes.status}`);
|
||||
process.exit(0);
|
||||
}
|
||||
const comments = await listRes.json();
|
||||
const existing = Array.isArray(comments) ? comments.find((c) => typeof c.body === "string" && c.body.includes(marker)) : null;
|
||||
|
||||
if (existing) {
|
||||
const updateRes = await fetch(`https://${host}/api/v1/repos/${repo}/issues/comments/${existing.id}`, {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
body: JSON.stringify({ body }),
|
||||
});
|
||||
if (!updateRes.ok) {
|
||||
console.error(`Gitea update-comment failed: ${updateRes.status}`);
|
||||
process.exit(0);
|
||||
}
|
||||
console.log(`coverage comment updated (id=${existing.id})`);
|
||||
} else {
|
||||
const createRes = await fetch(apiBase, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ body }),
|
||||
});
|
||||
if (!createRes.ok) {
|
||||
console.error(`Gitea create-comment failed: ${createRes.status}`);
|
||||
process.exit(0);
|
||||
}
|
||||
console.log("coverage comment created");
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in new issue
Block a user