Skip to content

Commit

Permalink
Merge pull request #218 from crazy-max/fix-non-iterable
Browse files Browse the repository at this point in the history
fix intermediate values
  • Loading branch information
crazy-max authored Oct 26, 2024
2 parents cc5d04c + a69137f commit 9d4405d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
19 changes: 12 additions & 7 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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<Label[]> => {
return <Promise<Label[]>>(repoLabels as unknown);
return <Promise<Label[]>>JSON.parse(fs.readFileSync(path.join(fixturesDir, 'repoLabels.json'), 'utf-8'));
});

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: []
Expand All @@ -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']
Expand All @@ -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']
Expand All @@ -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: []
Expand Down Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"matcher": "^3.0.0"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
Expand Down
25 changes: 10 additions & 15 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand All @@ -308,26 +310,19 @@ export class Labeler {
}

private async getRepoLabel(name: string): Promise<Label | undefined> {
for (const repoLabel of await this.repoLabels) {
if (name == repoLabel.name) {
return repoLabel;
}
}
return undefined;
const repoLabels = await this.repoLabels;
return repoLabels.find(repoLabel => repoLabel.name === name);
}

private async getFileLabel(name: string): Promise<Label | undefined> {
for (const fileLabel of await this.fileLabels) {
if (name == fileLabel.name || name == fileLabel.from_name) {
return fileLabel;
}
}
return undefined;
const fileLabels = await this.fileLabels;
return fileLabels.find(fileLabel => name === fileLabel.name || name === fileLabel.from_name);
}

async printRepoLabels() {
const labels = Array<Label>();
for (const repoLabel of await this.repoLabels) {
const repoLabels = await this.repoLabels;
for (const repoLabel of repoLabels) {
labels.push({
name: repoLabel.name,
color: repoLabel.color,
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,13 @@ __metadata:
languageName: node
linkType: hard

"@types/js-yaml@npm:^4.0.9":
version: 4.0.9
resolution: "@types/js-yaml@npm:4.0.9"
checksum: e5e5e49b5789a29fdb1f7d204f82de11cb9e8f6cb24ab064c616da5d6e1b3ccfbf95aa5d1498a9fbd3b9e745564e69b4a20b6c530b5a8bbb2d4eb830cda9bc69
languageName: node
linkType: hard

"@types/json-schema@npm:^7.0.12":
version: 7.0.12
resolution: "@types/json-schema@npm:7.0.12"
Expand Down Expand Up @@ -3216,6 +3223,7 @@ __metadata:
dependencies:
"@actions/core": ^1.10.0
"@actions/github": ^5.1.1
"@types/js-yaml": ^4.0.9
"@types/node": ^20.6.0
"@typescript-eslint/eslint-plugin": ^6.6.0
"@typescript-eslint/parser": ^6.6.0
Expand Down

0 comments on commit 9d4405d

Please sign in to comment.