virtual-code-owners 4.0.0 → 4.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
@@ -62,6 +62,7 @@ libs/ubc-sales/ @abraham-ableton-ch @boris-bubbleblower-ch @charlotte-ch
62
62
  libs/ubc-after-sales/ @daisy-duck @donald-duck @john-doe-ch @pete-peterson-ch @william-the-fourth-ch
63
63
  libs/ubc-pre-sales/ @averel-dalton-ch @jean-claude-ch @john-galt-ch @valerie-valerton-ch
64
64
  libs/ubc-refund/ @abraham-ableton-ch @boris-bubbleblower-ch @charlotte-charleston-ch @dagny-taggert-ch @daisy-duck @donald-duck @gregory-gregson-ch @jane-doe-ch @john-doe-ch @karl-marx-ch @pete-peterson-ch @william-the-fourth-ch
65
+ libs/ubc-baarden/ jan@example.com korneel@example.com pier@example.com tjorus@example.com
65
66
  ```
66
67
 
67
68
  This is where `virtual-code-owners` comes in.
@@ -104,6 +105,7 @@ libs/ubc-sales/ @ch/sales
104
105
  libs/ubc-after-sales/ @ch/after-sales
105
106
  libs/ubc-pre-sales/ @ch/pre-sales
106
107
  libs/ubc-refund/ @ch/sales @ch/after-sales
108
+ libs/ubc-baarden/ @ch/mannen-met-baarden
107
109
  ```
108
110
 
109
111
  ### virtual-teams.yml
@@ -167,8 +169,9 @@ team name and _virtual-code-owners_ will leave the real name alone.
167
169
 
168
170
  ### Any limitations I should know of?
169
171
 
170
- - Currently only works for _usernames_ to identify team members - not for e-mail
171
- addresses.
172
+ - ~~Currently only works for _user names_ to identify team members - not for e-mail
173
+ addresses.~~
174
+ Works with both user names and e-mail addresses
172
175
  - _virtual-code-owners_ assumes the VIRTUAL-CODEOWNERS.txt is a valid CODEOWNERS
173
176
  file and the virtual-teams.yml is a valid yaml file with teams names as keys
174
177
  and team members as arrays under these. It will likely throw errors when this
@@ -178,7 +181,7 @@ team name and _virtual-code-owners_ will leave the real name alone.
178
181
 
179
182
  Various editors assume an ALL_CAPS file name with `#` characters on various lines
180
183
  to be markdown, and will auto format them as such - making for either very ugly
181
- or in worst cases invalid CODOWNERS files. Usually such autoformatting is not
184
+ or in worst cases invalid CODEOWNERS files. Usually such autoformatting is not
182
185
  present on text files.
183
186
 
184
187
  Apparently these editors know about CODEOWNERS, though so this auto formatting
package/dist/cli.js CHANGED
@@ -1,71 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { VERSION } from "./version.js";
3
- import { readAndConvert } from "./read-and-convert.js";
4
- import { writeFileSync } from "node:fs";
5
- import { EOL } from "node:os";
6
- import { parseArgs } from "node:util";
7
- let lOptions;
8
- try {
9
- let lParsedArgs = parseArgs({
10
- args: process.argv.slice(2),
11
- options: {
12
- virtualCodeOwners: {
13
- type: "string",
14
- short: "v",
15
- default: ".github/VIRTUAL-CODEOWNERS.txt",
16
- },
17
- virtualTeams: {
18
- type: "string",
19
- short: "t",
20
- default: ".github/virtual-teams.yml",
21
- },
22
- codeOwners: { type: "string", short: "c", default: ".github/CODEOWNERS" },
23
- help: { type: "boolean", short: "h", default: false },
24
- version: { type: "boolean", short: "V", default: false },
25
- },
26
- strict: true,
27
- allowPositionals: true,
28
- tokens: false,
29
- });
30
- lOptions = lParsedArgs.values;
31
- if (lOptions.help) {
32
- showHelp();
33
- process.exit(0);
34
- }
35
- if (lOptions.version) {
36
- console.log(VERSION);
37
- process.exit(0);
38
- }
39
- }
40
- catch (pError) {
41
- console.error(`${EOL}ERROR: ${pError.message}${EOL}`);
42
- process.exit(1);
43
- }
44
- function showHelp() {
45
- console.log(`Usage: virtual-code-owners [options]
46
-
47
- Merges a VIRTUAL-CODEOWNERS.txt and a virtual-teams.yml into CODEOWNERS
48
-
49
- Options:
50
- -V, --version output the version number
51
- -v, --virtualCodeOwners [file-name] A CODEOWNERS file with team names in them
52
- that are defined in a virtual teams file
53
- (default: ".github/VIRTUAL-CODEOWNERS.txt")
54
- -t, --virtualTeams [file-name] A YAML file listing teams and their
55
- members
56
- (default: ".github/virtual-teams.yml")
57
- -c, --codeOwners [file-name] The location of the CODEOWNERS file
58
- (default: ".github/CODEOWNERS")
59
- -h, --help display help for command`);
60
- }
61
- try {
62
- const lCodeOwnersContent = readAndConvert(lOptions.virtualCodeOwners, lOptions.virtualTeams);
63
- writeFileSync(lOptions.codeOwners, lCodeOwnersContent, {
64
- encoding: "utf-8",
65
- });
66
- console.error(`${EOL}Wrote ${lOptions.codeOwners}${EOL}`);
67
- }
68
- catch (pError) {
69
- console.error(`ERROR: ${pError.message}`);
70
- process.exitCode = 1;
71
- }
2
+ import { main } from "./main.js";
3
+ main();
@@ -40,7 +40,16 @@ function replaceTeamNames(pUserNames, pTeamMap) {
40
40
  return lReturnValue;
41
41
  }
42
42
  function stringifyTeamMembers(pTeamMap, pTeamName) {
43
- return pTeamMap[pTeamName].map((pUserName) => `@${pUserName}`).join(" ");
43
+ return pTeamMap[pTeamName]
44
+ .map((pUserName) => userNameToCodeOwner(pUserName))
45
+ .join(" ");
46
+ }
47
+ function userNameToCodeOwner(pUserName) {
48
+ const lEmailIshUsernameRE = /^.+@.+$/;
49
+ if (pUserName.match(lEmailIshUsernameRE)) {
50
+ return pUserName;
51
+ }
52
+ return `@${pUserName}`;
44
53
  }
45
54
  function uniqAndSortUserNames(pUserNames) {
46
55
  return Array.from(new Set(pUserNames.split(/\s+/)))
package/dist/main.js ADDED
@@ -0,0 +1,69 @@
1
+ import { VERSION } from "./version.js";
2
+ import { readAndConvert } from "./read-and-convert.js";
3
+ import { writeFileSync } from "node:fs";
4
+ import { EOL } from "node:os";
5
+ import { parseArgs } from "node:util";
6
+ const HELP_MESSAGE = `Usage: virtual-code-owners [options]
7
+
8
+ Merges a VIRTUAL-CODEOWNERS.txt and a virtual-teams.yml into CODEOWNERS
9
+
10
+ Options:
11
+ -V, --version output the version number
12
+ -v, --virtualCodeOwners [file-name] A CODEOWNERS file with team names in them
13
+ that are defined in a virtual teams file
14
+ (default: ".github/VIRTUAL-CODEOWNERS.txt")
15
+ -t, --virtualTeams [file-name] A YAML file listing teams and their
16
+ members
17
+ (default: ".github/virtual-teams.yml")
18
+ -c, --codeOwners [file-name] The location of the CODEOWNERS file
19
+ (default: ".github/CODEOWNERS")
20
+ -h, --help display help for command`;
21
+ export function main(pArguments = process.argv.slice(2), pOutStream = process.stdout, pErrorStream = process.stderr) {
22
+ try {
23
+ let lOptions = getOptions(pArguments);
24
+ if (lOptions.help) {
25
+ pOutStream.write(`${HELP_MESSAGE}${EOL}`);
26
+ return;
27
+ }
28
+ if (lOptions.version) {
29
+ pOutStream.write(`${VERSION}${EOL}`);
30
+ return;
31
+ }
32
+ const lCodeOwnersContent = readAndConvert(lOptions.virtualCodeOwners, lOptions.virtualTeams);
33
+ writeFileSync(lOptions.codeOwners, lCodeOwnersContent, {
34
+ encoding: "utf-8",
35
+ });
36
+ pErrorStream.write(`${EOL}Wrote ${lOptions.codeOwners}${EOL}${EOL}`);
37
+ }
38
+ catch (pError) {
39
+ pErrorStream.write(`${EOL}ERROR: ${pError.message}${EOL}${EOL}`);
40
+ process.exitCode = 1;
41
+ }
42
+ }
43
+ function getOptions(pArguments) {
44
+ return parseArgs({
45
+ args: pArguments,
46
+ options: {
47
+ virtualCodeOwners: {
48
+ type: "string",
49
+ short: "v",
50
+ default: ".github/VIRTUAL-CODEOWNERS.txt",
51
+ },
52
+ virtualTeams: {
53
+ type: "string",
54
+ short: "t",
55
+ default: ".github/virtual-teams.yml",
56
+ },
57
+ codeOwners: {
58
+ type: "string",
59
+ short: "c",
60
+ default: ".github/CODEOWNERS",
61
+ },
62
+ help: { type: "boolean", short: "h", default: false },
63
+ version: { type: "boolean", short: "V", default: false },
64
+ },
65
+ strict: true,
66
+ allowPositionals: true,
67
+ tokens: false,
68
+ }).values;
69
+ }
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import yaml from "js-yaml";
3
- import { convert } from "./convert-virtual-code-owners.js";
3
+ import { convert } from "./convert-to-codeowners.js";
4
4
  export function readAndConvert(pVirtualCodeOwnersFileName, pVirtualTeamsFileName) {
5
5
  const lVirtualCodeOwnersAsAString = readFileSync(pVirtualCodeOwnersFileName, {
6
6
  encoding: "utf-8",
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "4.0.0";
1
+ export const VERSION = "4.1.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-code-owners",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Merges a VIRTUAL-CODEOWNERS.txt and a virtual-teams.yml into CODEOWNERS",
5
5
  "type": "module",
6
6
  "exports": {
@@ -54,9 +54,9 @@
54
54
  "devDependencies": {
55
55
  "@types/js-yaml": "4.0.5",
56
56
  "@types/mocha": "10.0.1",
57
- "@types/node": "20.2.1",
58
- "c8": "7.13.0",
59
- "dependency-cruiser": "13.0.1",
57
+ "@types/node": "20.2.5",
58
+ "c8": "7.14.0",
59
+ "dependency-cruiser": "13.0.2",
60
60
  "husky": "8.0.3",
61
61
  "lint-staged": "13.2.2",
62
62
  "mocha": "10.2.0",
@@ -64,7 +64,7 @@
64
64
  "ts-node": "10.9.1",
65
65
  "typescript": "5.0.4",
66
66
  "upem": "7.3.2",
67
- "watskeburt": "0.11.2"
67
+ "watskeburt": "0.11.3"
68
68
  },
69
69
  "dependencies": {
70
70
  "js-yaml": "4.1.0"