Skip to content

Commit

Permalink
Merge pull request #226 from pjpires/yaml-failsafe-schema
Browse files Browse the repository at this point in the history
Load yaml files using the failsafe schema option
  • Loading branch information
crazy-max authored Jan 30, 2025
2 parents 01de93b + c0910be commit 98f4f2b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
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

0 comments on commit 98f4f2b

Please # to comment.