From 5bcdf76e49dd5cce288c53b2c69bc6889f1012a7 Mon Sep 17 00:00:00 2001 From: Muneeb Zia <31257991+Muneeb147@users.noreply.github.com> Date: Wed, 23 Oct 2024 02:33:16 +0500 Subject: [PATCH] Update dump-ci-stats-to-gcp-logs.js --- source/dump-ci-stats-to-gcp-logs.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/dump-ci-stats-to-gcp-logs.js b/source/dump-ci-stats-to-gcp-logs.js index e6f355d..da1f008 100644 --- a/source/dump-ci-stats-to-gcp-logs.js +++ b/source/dump-ci-stats-to-gcp-logs.js @@ -15,18 +15,25 @@ const apiUrl = `https://api.github.com/repos/${repo}/actions/runs/${runId}`; // Fetch workflow status via GitHub API async function fetchWorkflowStatus() { try { - const response = await axios.get(apiUrl, { + const response = await fetch(apiUrl, { + method: 'GET', headers: { 'Authorization': `Bearer ${githubToken}`, 'Accept': 'application/vnd.github.v3+json', }, }); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + // Extract relevant information - const status = response.data.status; // in_progress, completed, etc. - const conclusion = response.data.conclusion; // success, failure, neutral, cancelled, etc. - const startTime = response.data.created_at; - const endTime = response.data.updated_at; + const status = data.status; // in_progress, completed, etc. + const conclusion = data.conclusion; // success, failure, neutral, cancelled, etc. + const startTime = data.created_at; + const endTime = data.updated_at; const executionTime = (new Date(endTime) - new Date(startTime)) / 1000; // Convert to seconds