Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load yaml files using the failsafe schema option #226

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions __tests__/fixtures/labels.failsafe_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## parses colors declared as integer values - different color, update
- # bot
name: ":robot: bot"
color: 123456
description: ""
## parses colors declared as regular text, no hexcode - same color, skip
- # enhancement
name: ":sparkles: enhancement"
color: 0054ca
description: ""
## parses colors declared as string hex codes - same color, skip
- # bug
name: ":bug: bug"
color: "#b60205"
description: ""
# parses regular text for the name field - new label, create
- # new label
name: This is a new label
color: "#0e8a16"
description: ""
# parses regular text for the description field - existing label, update
- # upstream
name: ":eyes: upstream"
color: "fbca04"
description: This is a new description
# parses text for the from_name field - existing label, rename
- # question
name: ":question: :question: question"
color: "3f51b5"
description: ""
from_name: ":question: question"
19 changes: 19 additions & 0 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ const cases = [
delete: 11,
error: 0
}
],
[
'labels.failsafe_schema.yml',
{
githubToken: 'n/a',
yamlFile: path.join(fixturesDir, 'labels.failsafe_schema.yml'),
skipDelete: true,
dryRun: true,
exclude: []
},
{
skip: 2,
exclude: 0,
create: 1,
update: 2,
rename: 1,
delete: 16,
error: 0
}
]
];

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.

2 changes: 1 addition & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class Labeler {
}

private static async loadLabelsFromYAML(yamlFile: fs.PathLike): Promise<Label[]> {
return yaml.load(fs.readFileSync(yamlFile, {encoding: 'utf-8'})) as Promise<Label[]>;
return yaml.load(fs.readFileSync(yamlFile, {encoding: 'utf-8'}), {schema: yaml.FAILSAFE_SCHEMA}) as Promise<Label[]>;
}

private async computeActionLabels(): Promise<Label[]> {
Expand Down