From b3ff7bdeff0c3fa0617b4e80dbd617272c224ed8 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:41:24 +0200 Subject: [PATCH] fix intermediate values --- __tests__/labeler.test.ts | 19 ++++++++++++------- src/labeler.ts | 25 ++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/__tests__/labeler.test.ts b/__tests__/labeler.test.ts index b8729bf..2655a4d 100644 --- a/__tests__/labeler.test.ts +++ b/__tests__/labeler.test.ts @@ -1,11 +1,15 @@ import {describe, expect, jest, test} from '@jest/globals'; +import * as fs from 'fs'; +import * as path from 'path'; + import {Inputs} from '../src/context'; import {Label, Labeler, LabelStatus} from '../src/labeler'; -import repoLabels from './fixtures/repoLabels.json'; +const fixturesDir = path.join(__dirname, 'fixtures'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any jest.spyOn(Labeler.prototype as any, 'getRepoLabels').mockImplementation((): Promise => { - return >(repoLabels as unknown); + return >JSON.parse(fs.readFileSync(path.join(fixturesDir, 'repoLabels.json'), 'utf-8')); }); const cases = [ @@ -13,7 +17,7 @@ const cases = [ 'labels.update.yml', { githubToken: 'n/a', - yamlFile: './__tests__/fixtures/labels.update.yml', + yamlFile: path.join(fixturesDir, 'labels.update.yml'), skipDelete: true, dryRun: true, exclude: [] @@ -32,7 +36,7 @@ const cases = [ 'labels.exclude1.yml', { githubToken: 'n/a', - yamlFile: './__tests__/fixtures/labels.exclude1.yml', + yamlFile: path.join(fixturesDir, 'labels.exclude1.yml'), skipDelete: true, dryRun: true, exclude: ['* d*', '*enhancement', '*fix'] @@ -51,7 +55,7 @@ const cases = [ 'labels.exclude2.yml', { githubToken: 'n/a', - yamlFile: './__tests__/fixtures/labels.exclude2.yml', + yamlFile: path.join(fixturesDir, 'labels.exclude2.yml'), skipDelete: true, dryRun: true, exclude: ['*fix'] @@ -70,7 +74,7 @@ const cases = [ 'labels.hexcodes.yml', { githubToken: 'n/a', - yamlFile: './__tests__/fixtures/labels.hexcodes.yml', + yamlFile: path.join(fixturesDir, 'labels.hexcodes.yml'), skipDelete: true, dryRun: true, exclude: [] @@ -106,7 +110,8 @@ describe('run', () => { delete: 0, error: 0 }; - for (const label of await labeler.labels) { + const labels = await labeler.labels; + for (const label of labels) { switch (label.ghaction_status) { case LabelStatus.Exclude: { res.exclude++; diff --git a/src/labeler.ts b/src/labeler.ts index f57d9fe..32f0f54 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -212,7 +212,8 @@ export class Labeler { ); } - for (const fileLabel of await this.fileLabels) { + const fileLabels = await this.fileLabels; + for (const fileLabel of fileLabels) { // Allow color hex codes (e.g., '#cccccc') to be set even though GitHub's API requires the # sign not to be present. fileLabel.color = this.sanitizeColorString(fileLabel.color); @@ -285,7 +286,8 @@ export class Labeler { } // Delete - for (const repoLabel of await this.repoLabels) { + const repoLabels = await this.repoLabels; + for (const repoLabel of repoLabels) { if (await this.getFileLabel(repoLabel.name)) { continue; } @@ -308,26 +310,19 @@ export class Labeler { } private async getRepoLabel(name: string): Promise