mirror of
https://github.com/Noratrieb/vps.git
synced 2026-01-16 01:25:09 +01:00
update with script
This commit is contained in:
parent
cc78321417
commit
4631ff2a1d
4 changed files with 50 additions and 9 deletions
31
newinfra/update-my-projects.mjs
Normal file
31
newinfra/update-my-projects.mjs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import fs from "node:fs/promises";
|
||||
|
||||
const path = `${import.meta.dirname}/nix/my-projects.json`;
|
||||
const projects = JSON.parse(await fs.readFile(path));
|
||||
|
||||
let hasChanges = false;
|
||||
|
||||
for (const [name, commit] of Object.entries(projects)) {
|
||||
const res = await fetch(
|
||||
`https://api.github.com/repos/Noratrieb/${name}/commits/HEAD`
|
||||
);
|
||||
if (!res.ok) {
|
||||
throw new Error(
|
||||
`get commit for ${name}: ${res.status} - ${await res.text()}`
|
||||
);
|
||||
}
|
||||
const body = await res.json();
|
||||
const latestCommit = body.sha;
|
||||
|
||||
if (commit !== latestCommit) {
|
||||
console.log(
|
||||
`${name} changed from ${commit} -> ${latestCommit} (${body.commit.message})`
|
||||
);
|
||||
projects[name] = latestCommit;
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasChanges) {
|
||||
await fs.writeFile(path, JSON.stringify(projects, null, 2) + "\n");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue