From 1f8b43fcfb4c4c944b18dc8d22a1577186aa1725 Mon Sep 17 00:00:00 2001 From: Yutaka Kamei Date: Sat, 30 Mar 2024 23:20:14 +0900 Subject: [PATCH] Call setup() and settle() --- dist/index.js | 35 +++++++++++++++++++------------- src/main.ts | 56 +++++++++++++++++++++++++++------------------------ 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/dist/index.js b/dist/index.js index 71d4212..e3385cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82919,21 +82919,28 @@ xychart-beta const main = async () => { const now = new Date(); const input = new Input(); - const apiClient = new GitHubAPIClient(input.token, new GitHubActionsCacheStore()); - const repository = new GitHubRepository(input.owner, input.repo, apiClient); - const workflows = await repository.getWorkflows(input.only); - const charts = await Promise.all(workflows.map(async (w) => { - const runs = await repository.getWorkflowRuns(w, { - status: input.status, - }); - const usages = await Promise.all(runs.map((r) => repository.getWorkflowRunUsage(r))); - return new MermaidXYChart(w, runs, usages, input); - })); - const issueContent = new GitHubIssueContent(charts, `GitHub Workflow Metrics on ${now.toDateString()}`, [], [input.label]); - for (const issue of await repository.getIssues([input.label])) { - await repository.closeIssue(issue); + const cacheStore = new GitHubActionsCacheStore(); + await cacheStore.setup(); + try { + const apiClient = new GitHubAPIClient(input.token, cacheStore); + const repository = new GitHubRepository(input.owner, input.repo, apiClient); + const workflows = await repository.getWorkflows(input.only); + const charts = await Promise.all(workflows.map(async (w) => { + const runs = await repository.getWorkflowRuns(w, { + status: input.status, + }); + const usages = await Promise.all(runs.map((r) => repository.getWorkflowRunUsage(r))); + return new MermaidXYChart(w, runs, usages, input); + })); + const issueContent = new GitHubIssueContent(charts, `GitHub Workflow Metrics on ${now.toDateString()}`, [], [input.label]); + for (const issue of await repository.getIssues([input.label])) { + await repository.closeIssue(issue); + } + await repository.createIssue(issueContent); + } + finally { + await cacheStore.settle(); } - await repository.createIssue(issueContent); }; /* harmony default export */ const src_main = (main); diff --git a/src/main.ts b/src/main.ts index c2a8abc..237f921 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,33 +8,37 @@ import { MermaidXYChart } from "./MermaidXYChart"; const main = async () => { const now = new Date(); const input = new Input(); - const apiClient = new GitHubAPIClient( - input.token, - new GitHubActionsCacheStore(), - ); - const repository = new GitHubRepository(input.owner, input.repo, apiClient); - const workflows = await repository.getWorkflows(input.only); - const charts = await Promise.all( - workflows.map(async (w) => { - const runs = await repository.getWorkflowRuns(w, { - status: input.status, - }); - const usages = await Promise.all( - runs.map((r) => repository.getWorkflowRunUsage(r)), - ); - return new MermaidXYChart(w, runs, usages, input); - }), - ); - const issueContent = new GitHubIssueContent( - charts, - `GitHub Workflow Metrics on ${now.toDateString()}`, - [], - [input.label], - ); - for (const issue of await repository.getIssues([input.label])) { - await repository.closeIssue(issue); + const cacheStore = new GitHubActionsCacheStore(); + await cacheStore.setup(); + + try { + const apiClient = new GitHubAPIClient(input.token, cacheStore); + const repository = new GitHubRepository(input.owner, input.repo, apiClient); + const workflows = await repository.getWorkflows(input.only); + const charts = await Promise.all( + workflows.map(async (w) => { + const runs = await repository.getWorkflowRuns(w, { + status: input.status, + }); + const usages = await Promise.all( + runs.map((r) => repository.getWorkflowRunUsage(r)), + ); + return new MermaidXYChart(w, runs, usages, input); + }), + ); + const issueContent = new GitHubIssueContent( + charts, + `GitHub Workflow Metrics on ${now.toDateString()}`, + [], + [input.label], + ); + for (const issue of await repository.getIssues([input.label])) { + await repository.closeIssue(issue); + } + await repository.createIssue(issueContent); + } finally { + await cacheStore.settle(); } - await repository.createIssue(issueContent); }; export default main;