feat(self-healing): support dynamic repository based on alert label
continuous-integration/webhook Deploy concluido com sucesso (VPS 4)
continuous-integration/webhook Deploy concluido com sucesso (VPS 4)
This commit is contained in:
@@ -12,14 +12,14 @@ function log(message) {
|
||||
}
|
||||
|
||||
// Envia a Issue para o Gitea
|
||||
function createGiteaIssue(title, body) {
|
||||
function createGiteaIssue(title, body, repoName) {
|
||||
const postData = JSON.stringify({
|
||||
title: title,
|
||||
body: body,
|
||||
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 = {
|
||||
hostname: url.hostname,
|
||||
@@ -38,9 +38,9 @@ function createGiteaIssue(title, body) {
|
||||
res.on('data', chunk => responseData += chunk);
|
||||
res.on('end', () => {
|
||||
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 {
|
||||
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 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 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.
|
||||
`;
|
||||
|
||||
createGiteaIssue(issueTitle, issueBody);
|
||||
createGiteaIssue(issueTitle, issueBody, repoName);
|
||||
});
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
Reference in New Issue
Block a user