1 Commits

Author SHA1 Message Date
362656d13e retry failed webhooks 2025-02-08 23:21:42 -05:00
5 changed files with 82 additions and 18 deletions

20
.vscode/launch.json vendored
View File

@@ -5,16 +5,30 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "pwa-node", "type": "node",
"request": "launch", "request": "launch",
"name": "Launch Program", "name": "Launch Program",
"skipFiles": [ "skipFiles": [
"<node_internals>/**" "<node_internals>/**"
], ],
"env": { "env": {
"JOB": "jobs/example.json5" "GPGPASS": "${input:gpgpass}"
}, },
"program": "${workspaceFolder}/index.js" "program": "${workspaceFolder}/bin/artix-metro.mjs",
"args": [
"--job",
"jobs/kde-01.json5"
],
"outFiles": [
"${workspaceFolder}/distribution/*"
]
}
],
"inputs": [
{
"id": "gpgpass",
"type": "promptString",
"description": "Enter your GPG password"
} }
] ]
} }

View File

@@ -57,6 +57,7 @@ _artix_metro_completion() {
COMPREPLY=() COMPREPLY=()
;; ;;
"-j"|"--job") "-j"|"--job")
compopt -o filenames
COMPREPLY=( $(compgen -f -- "$cur") ) COMPREPLY=( $(compgen -f -- "$cur") )
;; ;;
"--workspace") "--workspace")

18
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "artix-metro", "name": "artix-metro",
"version": "3.1.0", "version": "3.1.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "artix-metro", "name": "artix-metro",
"version": "3.1.0", "version": "3.1.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"artix-checkupdates": "1.0.1", "artix-checkupdates": "1.0.1",
@@ -21,7 +21,7 @@
"devDependencies": { "devDependencies": {
"@sindresorhus/tsconfig": "7.0.0", "@sindresorhus/tsconfig": "7.0.0",
"@types/cli-color": "2.0.6", "@types/cli-color": "2.0.6",
"@types/node": "22.10.7", "@types/node": "22.13.1",
"typescript": "5.7.3" "typescript": "5.7.3"
} }
}, },
@@ -63,9 +63,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "22.10.7", "version": "22.13.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.7.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
"integrity": "sha512-V09KvXxFiutGp6B7XkpaDXlNadZxrzajcY50EuoLIpQ6WWYCSvf19lVIazzfIzQvhUN2HjX12spLojTnhuKlGg==", "integrity": "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -758,9 +758,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "22.10.7", "version": "22.13.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.7.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
"integrity": "sha512-V09KvXxFiutGp6B7XkpaDXlNadZxrzajcY50EuoLIpQ6WWYCSvf19lVIazzfIzQvhUN2HjX12spLojTnhuKlGg==", "integrity": "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==",
"dev": true, "dev": true,
"requires": { "requires": {
"undici-types": "~6.20.0" "undici-types": "~6.20.0"

View File

@@ -1,6 +1,6 @@
{ {
"name": "artix-metro", "name": "artix-metro",
"version": "3.1.0", "version": "3.1.1",
"description": "Automate pushing packages to Artix", "description": "Automate pushing packages to Artix",
"keywords": [ "keywords": [
"artix", "artix",
@@ -41,6 +41,6 @@
"typescript": "5.7.3", "typescript": "5.7.3",
"@sindresorhus/tsconfig": "7.0.0", "@sindresorhus/tsconfig": "7.0.0",
"@types/cli-color": "2.0.6", "@types/cli-color": "2.0.6",
"@types/node": "22.10.7" "@types/node": "22.13.1"
} }
} }

View File

@@ -1,7 +1,7 @@
import ky from 'ky'; import ky from 'ky';
import { snooze } from './snooze.mjs'; import { snooze } from './snooze.mjs';
type CiStatus = "pending" | "success" | "error" | "failure"; type CiStatus = "pending" | "success" | "error" | "failure" | "";
interface GiteaConfig { interface GiteaConfig {
protocol?: string; protocol?: string;
@@ -16,7 +16,12 @@ interface Commit {
interface Status { interface Status {
sha: string; sha: string;
state: CiStatus state: CiStatus;
}
interface Hook {
active: boolean;
id: number;
} }
class Gitea { class Gitea {
@@ -95,7 +100,43 @@ class Gitea {
} }
} }
async getHooks(...args: string[]): Promise<Hook[]> {
try {
let headers: HeadersInit = {};
if (this._token) {
headers['Authorization'] = `token ${this._token}`
}
const resp = await ky.get(`${this.getUrlPrefix()}/repos/${args.join('/')}/hooks`, {
headers
});
return await resp.json();
}
catch (err) {
throw err;
}
}
async sendTestWebhook(...args: string[]): Promise<void> {
try {
let headers: HeadersInit = {};
if (this._token) {
headers['Authorization'] = `token ${this._token}`
}
const hook = (await this.getHooks(...args)).find(hook => hook.active === true);
if (!hook) {
throw new Error('No active webhook found');
}
await ky.post(`${this.getUrlPrefix()}/repos/${args.join('/')}/hooks/${hook.id}/tests`, {
headers
});
}
catch (err) {
throw err;
}
}
async waitForBuild(lastHash: string, ...args: string[]): Promise<void> { async waitForBuild(lastHash: string, ...args: string[]): Promise<void> {
let missingStatusCount = 0;
while (true) { while (true) {
let status: Status | null; let status: Status | null;
try { try {
@@ -108,7 +149,15 @@ class Gitea {
await snooze(30000); await snooze(30000);
continue; continue;
} }
if (status.sha !== lastHash) { if (!status.sha && !status.state) {
if (++missingStatusCount > 3) {
console.log('No build info detected. Sending test webhook...');
missingStatusCount = 0;
await this.sendTestWebhook(...args);
}
await snooze(30000);
}
else if (status.sha !== lastHash) {
if (status.state === 'success') { if (status.state === 'success') {
break; break;
} }