Skip to content

Commit

Permalink
refactor(codeowners/generate): slightly de-duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed May 11, 2024
1 parent 07eb6c4 commit b89fc04
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
1 change: 0 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ admin:
documentation:
- changed-files:
- any-glob-to-any-file: README.md

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- run: npm test
if: always() && matrix.node-version != '20.12.2'
- name: run test & emit results to step summary
# code coverage report on 20.x only, as --experimental-test-coverage on node > 20.12.2
# code coverage report on 20.x only, as --experimental-test-coverage on node > 20.12.2
# is not stable (gives varying results over identical runs)
if: always() && matrix.node-version == '20.12.2'
run: |
Expand Down
19 changes: 7 additions & 12 deletions dist/codeowners/generate.js

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

20 changes: 8 additions & 12 deletions src/codeowners/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,34 @@ function generateLine(
pTeamMap: ITeamMap,
): string {
if (pCSTLine.type === "rule") {
const lUserNames = uniq(
pCSTLine.users.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap)),
)
.sort(compareUserNames)
.join(" ");
return (
pCSTLine.filesPattern +
pCSTLine.spaces +
lUserNames +
expandTeamsToUsersString(pCSTLine.users, pTeamMap) +
(pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "")
);
}
if (pCSTLine.type === "section") {
const lUserNames = uniq(
pCSTLine.users.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap)),
)
.sort(compareUserNames)
.join(" ");
return (
(pCSTLine.optional ? "^" : "") +
"[" +
pCSTLine.sectionName +
"]" +
(pCSTLine.minApprovers ? `[${pCSTLine.minApprovers}]` : "") +
pCSTLine.spaces +
lUserNames +
expandTeamsToUsersString(pCSTLine.users, pTeamMap) +
(pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "")
);
}
return pCSTLine.raw;
}

function expandTeamsToUsersString(pUsers: IUser[], pTeamMap: ITeamMap): string {
return uniq(pUsers.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap)))
.sort(compareUserNames)
.join(" ");
}

function expandTeamToUserNames(pUser: IUser, pTeamMap: ITeamMap): string[] {
if (pUser.type === "virtual-team-name") {
return stringifyTeamMembers(pTeamMap, pUser.bareName);
Expand Down
2 changes: 1 addition & 1 deletion src/virtual-code-owners/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function parseSection(
if (lSection.groups.minApprovers) {
lReturnValue.minApprovers = parseInt(
lSection.groups.minApprovers as string,
10
10,
);
}

Expand Down

0 comments on commit b89fc04

Please sign in to comment.