feat(self-healing): support dynamic repository based on alert label
continuous-integration/webhook Deploy concluido com sucesso (VPS 4)

This commit is contained in:
2026-05-13 07:55:57 +02:00
parent 4a9ebb5992
commit 9efc2e7394
+6 -5
View File
@@ -12,14 +12,14 @@ function log(message) {
} }
// Envia a Issue para o Gitea // Envia a Issue para o Gitea
function createGiteaIssue(title, body) { function createGiteaIssue(title, body, repoName) {
const postData = JSON.stringify({ const postData = JSON.stringify({
title: title, title: title,
body: body, body: body,
assignees: [GITEA_REPO_OWNER] assignees: [GITEA_REPO_OWNER]
}); });
const url = new URL(`${GITEA_API_URL}/repos/${GITEA_REPO_OWNER}/${GITEA_REPO_NAME}/issues`); const url = new URL(`${GITEA_API_URL}/repos/${GITEA_REPO_OWNER}/${repoName}/issues`);
const options = { const options = {
hostname: url.hostname, hostname: url.hostname,
@@ -38,9 +38,9 @@ function createGiteaIssue(title, body) {
res.on('data', chunk => responseData += chunk); res.on('data', chunk => responseData += chunk);
res.on('end', () => { res.on('end', () => {
if (res.statusCode === 201) { if (res.statusCode === 201) {
log(`Sucesso: Issue criada no Gitea para o alerta.`); log(`Sucesso: Issue criada no Gitea para o repositório ${repoName}`);
} else { } else {
log(`Erro ao criar Issue no Gitea (HTTP ${res.statusCode}): ${responseData}`); log(`Erro ao criar Issue no Gitea no repositório ${repoName} (HTTP ${res.statusCode}): ${responseData}`);
} }
}); });
}); });
@@ -79,6 +79,7 @@ const server = http.createServer((req, res) => {
const alertName = alert.labels.alertname || 'Alerta Sem Nome'; const alertName = alert.labels.alertname || 'Alerta Sem Nome';
const vpsName = alert.labels.vps || 'Desconhecida'; const vpsName = alert.labels.vps || 'Desconhecida';
const repoName = alert.labels.repo || GITEA_REPO_NAME;
const summary = alert.annotations.summary || alert.annotations.description || 'Nenhum sumário fornecido.'; const summary = alert.annotations.summary || alert.annotations.description || 'Nenhum sumário fornecido.';
const fullLogs = alert.annotations.logs || 'Sem logs anexados.'; const fullLogs = alert.annotations.logs || 'Sem logs anexados.';
@@ -109,7 +110,7 @@ ${fullLogs}
> 3. Implemente a correção, realize os testes locais e execute o commit/push. > 3. Implemente a correção, realize os testes locais e execute o commit/push.
`; `;
createGiteaIssue(issueTitle, issueBody); createGiteaIssue(issueTitle, issueBody, repoName);
}); });
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });