From 20a6bffbdcaf2703bfcb24ff480df214c1efdd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Thu, 10 Aug 2023 13:25:03 +0200 Subject: [PATCH] Fix error in fetch stats script --- site/scripts/stats/fetch-stats.js | 83 +++++++++++++++++-------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/site/scripts/stats/fetch-stats.js b/site/scripts/stats/fetch-stats.js index d6beee678..a5b26673e 100644 --- a/site/scripts/stats/fetch-stats.js +++ b/site/scripts/stats/fetch-stats.js @@ -480,51 +480,60 @@ writeInDataDir('stats.json', baseData) if ( !process.env.ATINTERNET_API_ACCESS_KEY || !process.env.ATINTERNET_API_SECRET_KEY || - !process.env.ZAMMAD_API_SECRET_KEY + !process.env.ZAMMAD_API_SECRET_KEY || + !process.env.CRISP_API_IDENTIFIER || + !process.env.CRISP_API_KEY || + !process.env.GITHUB_API_SECRET ) { const missingEnvVar = (name) => (!process.env[name] ? name : null) - throw new Error( + const error = new Error( `Variables d'environnement manquantes : ${[ missingEnvVar('ATINTERNET_API_ACCESS_KEY'), missingEnvVar('ATINTERNET_API_SECRET_KEY'), missingEnvVar('ZAMMAD_API_SECRET_KEY'), + missingEnvVar('CRISP_API_IDENTIFIER'), + missingEnvVar('CRISP_API_KEY'), + missingEnvVar('GITHUB_API_SECRET'), ] .filter(Boolean) .join(', ')}, nous ne récupérons pas les statistiques d'usage` ) -} -const [ - visitesJours, - visitesMois, - rawSatisfaction, - retoursUtilisateurs, - nbAnswersLast30days, -] = await Promise.all([ - fetchDailyVisits(), - fetchMonthlyVisits(), - fetchApi(buildSatisfactionQuery), - fetchAllUserFeedbackIssues(), - fetchAllUserAnswerStats(), -]) -const satisfaction = uniformiseData(flattenPage(rawSatisfaction)).map( - (page) => { - // eslint-disable-next-line no-unused-vars - const { date, ...satisfactionPage } = { - month: new Date(new Date(page.date).setDate(1)), - ...page, + + console.error(error) +} else { + const [ + visitesJours, + visitesMois, + rawSatisfaction, + retoursUtilisateurs, + nbAnswersLast30days, + ] = await Promise.all([ + fetchDailyVisits(), + fetchMonthlyVisits(), + fetchApi(buildSatisfactionQuery), + fetchAllUserFeedbackIssues(), + fetchAllUserAnswerStats(), + ]) + const satisfaction = uniformiseData(flattenPage(rawSatisfaction)).map( + (page) => { + // eslint-disable-next-line no-unused-vars + const { date, ...satisfactionPage } = { + month: new Date(new Date(page.date).setDate(1)), + ...page, + } + return satisfactionPage } - return satisfactionPage - } -) -writeInDataDir('stats.json', { - visitesJours, - visitesMois: Object.fromEntries( - Object.entries(baseData.visitesMois).map(([key, prev]) => [ - key, - mergePreviousData(prev, visitesMois[key]), - ]) - ), - satisfaction: mergePreviousData(baseData.satisfaction, satisfaction), - retoursUtilisateurs, - nbAnswersLast30days, -}) + ) + writeInDataDir('stats.json', { + visitesJours, + visitesMois: Object.fromEntries( + Object.entries(baseData.visitesMois).map(([key, prev]) => [ + key, + mergePreviousData(prev, visitesMois[key]), + ]) + ), + satisfaction: mergePreviousData(baseData.satisfaction, satisfaction), + retoursUtilisateurs, + nbAnswersLast30days, + }) +}