Skip to content

Commit

Permalink
feat(labeler.yml)!: changes --emitLabeler to emit labeler@v5 format l…
Browse files Browse the repository at this point in the history
…abeler.yml - BREAKING (#163)

## Description

- changes the --emitLabeler output so it supports the labeler v5 format

## Motivation and Context

actions/labeler [changed their configuration format in a breaking
fashion](actions/labeler#712)


## How Has This Been Tested?

- [x] green ci
- [x] updated non-regression tests
- [x] generating a labeler.yml and running it against the new version of
actions/labeler - see [action run
7194463872](https://github.com/sverweij/virtual-code-owners/actions/runs/7194463872/job/19595044485?pr=163)

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij authored Dec 13, 2023
1 parent 0f607a8 commit 8a4d890
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 27 deletions.
20 changes: 13 additions & 7 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
#

vco:
- "**"
- README.md
- changed-files:
- any-glob-to-any-file: "**"
- any-glob-to-any-file: README.md

vco-admins:
- .github/**
- tools/**
- changed-files:
- any-glob-to-any-file: .github/**
- any-glob-to-any-file: tools/**

tools:
- tools/**
- changed-files:
- any-glob-to-any-file: tools/**

admin:
- .github/**
- changed-files:
- any-glob-to-any-file: .github/**

documentation:
- README.md
- changed-files:
- any-glob-to-any-file: README.md

2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
- uses: actions/labeler@v5
with:
sync-labels: true
dot: true
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ npx virtual-code-owners --emitLabeler
If you have an alternate file location for the `labeler.yml` you can specify that
with virtual-code-owner's `--labelerLocation` parameter.

> [!NOTE]
> actions/labeler changed the labeler.yml format from v4 to v5.
>
> - virtual-code-owners < 8.0.0 generates labeler.yml v4 format,
> - virtual-code-owners >= 8.0.0 generates labeler.yml v5 format.
>
> see [actions/labeler#v5](https://github.com/actions/labeler/blob/8558fd74291d67161a8a78ce36a881fa63b766a9/README.md)
> for details on the v5 format.

### What validations does virtual-code-owners perform?

virtual-code-owners checks for basic CODEOWNERS format errors and invalid
Expand Down
9 changes: 7 additions & 2 deletions dist/labeler-yml/generate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions src/labeler-yml/__fixtures__/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
ch/after-sales:
- libs/ubc-after-sales/**
- libs/ubc-refund/**
- changed-files:
- any-glob-to-any-file: libs/ubc-after-sales/**
- any-glob-to-any-file: libs/ubc-refund/**

ch/sales:
- libs/ubc-sales/**
- libs/ubc-refund/**
- changed-files:
- any-glob-to-any-file: libs/ubc-sales/**
- any-glob-to-any-file: libs/ubc-refund/**

ch/pre-sales:
- libs/ubc-pre-sales/**
- changed-files:
- any-glob-to-any-file: libs/ubc-pre-sales/**

ch/ux:
- apps/ux-portal/**
- libs/components/**
- changed-files:
- any-glob-to-any-file: apps/ux-portal/**
- any-glob-to-any-file: libs/components/**

ch/transversal:
- .github/**
- apps/framework/**
- apps/ux-portal/**
- changed-files:
- any-glob-to-any-file: .github/**
- any-glob-to-any-file: apps/framework/**
- any-glob-to-any-file: apps/ux-portal/**

ch/mannen-met-baarden:
- libs/ubc-baarden/**
- changed-files:
- any-glob-to-any-file: libs/ubc-baarden/**
12 changes: 8 additions & 4 deletions src/labeler-yml/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => {
},
];
const lExpected = `the-a-team:
- knakkerdeknak/**
- changed-files:
- any-glob-to-any-file: knakkerdeknak/**
`;
equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected);
Expand All @@ -108,7 +109,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => {
},
];
const lExpected = `baarden:
- "**"
- changed-files:
- any-glob-to-any-file: "**"
`;
equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected);
Expand All @@ -134,7 +136,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => {
},
];
const lExpected = `baarden:
- "*/src/vlaai/*"
- changed-files:
- any-glob-to-any-file: "*/src/vlaai/*"
`;
equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected);
Expand All @@ -160,7 +163,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => {
},
];
const lExpected = `# some header or other${EOL}baarden:
- src/vlaai/**
- changed-files:
- any-glob-to-any-file: src/vlaai/**
`;
equal(
Expand Down
9 changes: 7 additions & 2 deletions src/labeler-yml/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export default function generateLabelerYml(
let lReturnValue = pGeneratedWarning;
for (const lTeamName in pTeamMap) {
const lPatternsForTeam = getPatternsForTeam(pCodeOwners, lTeamName)
.map((pPattern) => ` - ${transformForYamlAndMinimatch(pPattern)}${EOL}`)
.map(
(pPattern) =>
` - any-glob-to-any-file: ${transformForYamlAndMinimatch(
pPattern,
)}${EOL}`,
)
.join("");

if (lPatternsForTeam) {
lReturnValue += `${lTeamName}:${EOL}${lPatternsForTeam}${EOL}`;
lReturnValue += `${lTeamName}:${EOL} - changed-files:${EOL}${lPatternsForTeam}${EOL}`;
}
}
return lReturnValue;
Expand Down

0 comments on commit 8a4d890

Please sign in to comment.