* Wait for report to be ready and download it * @param {string} reportId - The unique identifier of the generated report * @returns {Promise } Parsed report data from Crowdin
(reportId)
| 71 | * @returns {Promise<CrowdinReportData>} Parsed report data from Crowdin |
| 72 | */ |
| 73 | async function downloadReport(reportId) { |
| 74 | log.info(`Waiting up to ${REPORT_TIMEOUT_MS / 1000}s for report ${reportId} to finish`); |
| 75 | |
| 76 | await waitForCondition( |
| 77 | async () => { |
| 78 | const {status, progress} = await checkReportStatus(reportId); |
| 79 | log.debug(`Report status: ${status}, progress: ${progress}%`); |
| 80 | |
| 81 | switch (status) { |
| 82 | case REPORT_STATUS.finished: |
| 83 | return true; |
| 84 | case REPORT_STATUS.inProgress: |
| 85 | case REPORT_STATUS.created: |
| 86 | return false; |
| 87 | default: |
| 88 | throw new Error(`Report generation failed with status '${status}'`); |
| 89 | } |
| 90 | }, |
| 91 | { |
| 92 | waitMs: REPORT_TIMEOUT_MS, |
| 93 | intervalMs: 2000, |
| 94 | }, |
| 95 | ); |
| 96 | |
| 97 | const {data: downloadData} = await performApiRequest(`/reports/${reportId}/download`); |
| 98 | log.info('Downloading report data'); |
| 99 | |
| 100 | // Download the report file |
| 101 | const tmpFile = await tempDir.path({prefix: 'crowdin-report', suffix: '.json'}); |
| 102 | try { |
| 103 | await net.downloadFile(downloadData.url, tmpFile, {isMetered: false}); |
| 104 | const content = await fs.readFile(tmpFile, 'utf8'); |
| 105 | return JSON.parse(content); |
| 106 | } finally { |
| 107 | await fs.rimraf(tmpFile); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Process report data and group by language and translator |
no test coverage detected