virtual-code-owners 8.0.5 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -143,7 +143,10 @@ libs/baarden/ jan@example.com korneel@example.com pier@example.com tjorus@
|
|
|
143
143
|
|
|
144
144
|
### Any gotcha's?
|
|
145
145
|
|
|
146
|
-
It won't check whether the users or teams you entered exist.
|
|
146
|
+
- It won't check whether the users or teams you entered exist.
|
|
147
|
+
- Only relevant when you're on GitLab: Section heading support is experimental
|
|
148
|
+
and when generating labeler.yml default section owners aren't expanded to
|
|
149
|
+
section rules.
|
|
147
150
|
|
|
148
151
|
### Do I have to run this each time I edit `VIRTUAL-CODEOWNERS.txt`?
|
|
149
152
|
|
|
@@ -207,6 +210,10 @@ user/team names but doesn't verify their existence in the project.
|
|
|
207
210
|
|
|
208
211
|
- valid user/team names start with an `@` or are an e-mail address
|
|
209
212
|
- valid rules have a file pattern and at least one user/team name
|
|
213
|
+
- valid sections headings comply with the syntax described over at [GitLab](https://docs.gitlab.com/ee/user/project/codeowners/reference.html#sections)
|
|
214
|
+
> different from GitLab's syntax the line `[bla @group` is not interpreted
|
|
215
|
+
> as a rule, but as an erroneous section heading. This behaviour might change
|
|
216
|
+
> to be the same as GitLab's in future releases without a major version bump.
|
|
210
217
|
|
|
211
218
|
### I want to specify different locations for the files (e.g. because I'm using GitLab)
|
|
212
219
|
|
|
@@ -26,20 +26,32 @@ export default function generateCodeOwners(
|
|
|
26
26
|
}
|
|
27
27
|
function generateLine(pCSTLine, pTeamMap) {
|
|
28
28
|
if (pCSTLine.type === "rule") {
|
|
29
|
-
const lUserNames = uniq(
|
|
30
|
-
pCSTLine.users.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap)),
|
|
31
|
-
)
|
|
32
|
-
.sort(compareUserNames)
|
|
33
|
-
.join(" ");
|
|
34
29
|
return (
|
|
35
30
|
pCSTLine.filesPattern +
|
|
36
31
|
pCSTLine.spaces +
|
|
37
|
-
|
|
32
|
+
expandTeamsToUsersString(pCSTLine.users, pTeamMap) +
|
|
33
|
+
(pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "")
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (pCSTLine.type === "section-heading") {
|
|
37
|
+
return (
|
|
38
|
+
(pCSTLine.optional ? "^" : "") +
|
|
39
|
+
"[" +
|
|
40
|
+
pCSTLine.sectionName +
|
|
41
|
+
"]" +
|
|
42
|
+
(pCSTLine.minApprovers ? `[${pCSTLine.minApprovers}]` : "") +
|
|
43
|
+
pCSTLine.spaces +
|
|
44
|
+
expandTeamsToUsersString(pCSTLine.users, pTeamMap) +
|
|
38
45
|
(pCSTLine.inlineComment ? ` #${pCSTLine.inlineComment}` : "")
|
|
39
46
|
);
|
|
40
47
|
}
|
|
41
48
|
return pCSTLine.raw;
|
|
42
49
|
}
|
|
50
|
+
function expandTeamsToUsersString(pUsers, pTeamMap) {
|
|
51
|
+
return uniq(pUsers.flatMap((pUser) => expandTeamToUserNames(pUser, pTeamMap)))
|
|
52
|
+
.sort(compareUserNames)
|
|
53
|
+
.join(" ");
|
|
54
|
+
}
|
|
43
55
|
function expandTeamToUserNames(pUser, pTeamMap) {
|
|
44
56
|
if (pUser.type === "virtual-team-name") {
|
|
45
57
|
return stringifyTeamMembers(pTeamMap, pUser.bareName);
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "8.0
|
|
1
|
+
export const VERSION = "8.1.0";
|
|
@@ -19,6 +19,9 @@ function parseLine(pUntreatedLine, pTeamMap, pLineNo) {
|
|
|
19
19
|
if (lTrimmedLine.startsWith("#")) {
|
|
20
20
|
return { type: "comment", line: pLineNo, raw: pUntreatedLine };
|
|
21
21
|
}
|
|
22
|
+
if (lTrimmedLine.startsWith("[") || lTrimmedLine.startsWith("^[")) {
|
|
23
|
+
return parseSection(pUntreatedLine, pLineNo, pTeamMap);
|
|
24
|
+
}
|
|
22
25
|
if (!lRule?.groups) {
|
|
23
26
|
if (lTrimmedLine === "") {
|
|
24
27
|
return { type: "empty", line: pLineNo, raw: pUntreatedLine };
|
|
@@ -35,6 +38,40 @@ function parseLine(pUntreatedLine, pTeamMap, pLineNo) {
|
|
|
35
38
|
raw: pUntreatedLine,
|
|
36
39
|
};
|
|
37
40
|
}
|
|
41
|
+
function parseSection(pUntreatedLine, pLineNo, pTeamMap) {
|
|
42
|
+
const lTrimmedLine = pUntreatedLine.trim();
|
|
43
|
+
const lCommentSplitLine = lTrimmedLine.split(/\s*#/);
|
|
44
|
+
const lSection = lCommentSplitLine[0]?.match(
|
|
45
|
+
/^(?<optionalIndicator>\^)?\[(?<sectionName>[^\]]+)\](\[(?<minApprovers>[0-9]+)\])?(?<spaces>\s+)(?<userNames>.*)$/,
|
|
46
|
+
);
|
|
47
|
+
if (!lSection?.groups) {
|
|
48
|
+
return lTrimmedLine.endsWith("]")
|
|
49
|
+
? {
|
|
50
|
+
type: "section-without-users",
|
|
51
|
+
line: pLineNo,
|
|
52
|
+
raw: pUntreatedLine,
|
|
53
|
+
}
|
|
54
|
+
: {
|
|
55
|
+
type: "unknown",
|
|
56
|
+
line: pLineNo,
|
|
57
|
+
raw: pUntreatedLine,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const lReturnValue = {
|
|
61
|
+
type: "section-heading",
|
|
62
|
+
line: pLineNo,
|
|
63
|
+
optional: lSection.groups.optionalIndicator === "^",
|
|
64
|
+
sectionName: lSection.groups.sectionName,
|
|
65
|
+
spaces: lSection.groups.spaces,
|
|
66
|
+
users: parseUsers(lSection.groups.userNames, pTeamMap),
|
|
67
|
+
inlineComment: lTrimmedLine.split(/\s*#/)[1] ?? "",
|
|
68
|
+
raw: pUntreatedLine,
|
|
69
|
+
};
|
|
70
|
+
if (lSection.groups.minApprovers) {
|
|
71
|
+
lReturnValue.minApprovers = parseInt(lSection.groups.minApprovers, 10);
|
|
72
|
+
}
|
|
73
|
+
return lReturnValue;
|
|
74
|
+
}
|
|
38
75
|
function parseUsers(pUserNamesString, pTeamMap) {
|
|
39
76
|
const lUserNames = pUserNamesString.split(/\s+/);
|
|
40
77
|
return lUserNames.map((pUserName, pIndex) => {
|
|
@@ -25,7 +25,7 @@ function reportAnomalies(pFileName, pAnomalies) {
|
|
|
25
25
|
return pAnomalies
|
|
26
26
|
.map((pAnomaly) => {
|
|
27
27
|
if (pAnomaly.type === "invalid-line") {
|
|
28
|
-
return `${pFileName}:${pAnomaly.line}:1 invalid line - neither a rule, comment nor empty: "${pAnomaly.raw}"`;
|
|
28
|
+
return `${pFileName}:${pAnomaly.line}:1 invalid line - neither a rule, section heading, comment nor empty: "${pAnomaly.raw}"`;
|
|
29
29
|
} else {
|
|
30
30
|
return (
|
|
31
31
|
`${pFileName}:${pAnomaly.line}:1 invalid user or team name "${pAnomaly.raw}" (#${pAnomaly.userNumberWithinLine} on this line). ` +
|