@review-vir/common 3.0.0 → 3.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/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './parse-description-users.js';
2
+ export * from './parse-inserted-code-owners.js';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './parse-description-users.js';
2
+ export * from './parse-inserted-code-owners.js';
@@ -16,5 +16,8 @@ export function parseDescriptionUsers({ triggerText, bodyText, }) {
16
16
  }
17
17
  const [, restrictedMatch,] = safeMatch(match, /((?:@[\w-]+[^\w@]*)+)/);
18
18
  const userTags = Array.from(restrictedMatch?.matchAll(/@[\w-]+/g) || []);
19
- return userTags.map((userTag) => removePrefix({ value: userTag[0], prefix: '@' }));
19
+ return userTags.map((userTag) => removePrefix({
20
+ value: userTag[0],
21
+ prefix: '@',
22
+ }));
20
23
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Parses the code owners that pull-request-vir inserts into a pull request's _raw markdown_ body.
3
+ *
4
+ * Pull-request-vir wraps its code owners in HTML comment delimiters and lists each owner on its own
5
+ * line followed by a collapsible list of their owned files:
6
+ *
7
+ * <!-- code owners start -->
8
+ * **Code owners**:
9
+ * (at)username1
10
+ * <details>
11
+ * <summary>Owned files</summary>
12
+ *
13
+ * - [some/file.ts](https://...)
14
+ *
15
+ * </details>
16
+ * (at)username2
17
+ * ...
18
+ * <!-- code owners end -->
19
+ *
20
+ * Returns the owner usernames (e.g. `['username1', 'username2']`), or `undefined` when the body
21
+ * contains no inserted code owners block (so callers can fall back to other detection).
22
+ *
23
+ * This must run against the raw markdown `body`, not the rendered `bodyText`: GitHub strips HTML
24
+ * comments (and the `<details>` structure) out of `bodyText`, removing the delimiters that bound
25
+ * the block and interleaving the owners with their owned-file text.
26
+ */
27
+ export declare function parseInsertedCodeOwners(body: string): string[] | undefined;
@@ -0,0 +1,46 @@
1
+ import { removeDuplicates, removePrefix, safeMatch } from '@augment-vir/common';
2
+ const insertedCodeOwnersRegExp = /<!-- code owners start -->([\S\s]*?)<!-- code owners end -->/i;
3
+ const fileLinkLineRegExp = /^\s*-\s/;
4
+ const userTagRegExp = /@[\w-]+/g;
5
+ /**
6
+ * Parses the code owners that pull-request-vir inserts into a pull request's _raw markdown_ body.
7
+ *
8
+ * Pull-request-vir wraps its code owners in HTML comment delimiters and lists each owner on its own
9
+ * line followed by a collapsible list of their owned files:
10
+ *
11
+ * <!-- code owners start -->
12
+ * **Code owners**:
13
+ * (at)username1
14
+ * <details>
15
+ * <summary>Owned files</summary>
16
+ *
17
+ * - [some/file.ts](https://...)
18
+ *
19
+ * </details>
20
+ * (at)username2
21
+ * ...
22
+ * <!-- code owners end -->
23
+ *
24
+ * Returns the owner usernames (e.g. `['username1', 'username2']`), or `undefined` when the body
25
+ * contains no inserted code owners block (so callers can fall back to other detection).
26
+ *
27
+ * This must run against the raw markdown `body`, not the rendered `bodyText`: GitHub strips HTML
28
+ * comments (and the `<details>` structure) out of `bodyText`, removing the delimiters that bound
29
+ * the block and interleaving the owners with their owned-file text.
30
+ */
31
+ export function parseInsertedCodeOwners(body) {
32
+ const [, block,] = safeMatch(body, insertedCodeOwnersRegExp);
33
+ if (block == undefined) {
34
+ return undefined;
35
+ }
36
+ /** Drop owned-file link lines so scoped paths (e.g. `@types/...`) aren't read as owners. */
37
+ const ownerLines = block
38
+ .split('\n')
39
+ .filter((line) => !fileLinkLineRegExp.test(line))
40
+ .join('\n');
41
+ const userTags = Array.from(ownerLines.matchAll(userTagRegExp));
42
+ return removeDuplicates(userTags.map((userTag) => removePrefix({
43
+ value: userTag[0],
44
+ prefix: '@',
45
+ })));
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@review-vir/common",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Common functionality that review-vir primary uses but other external packages need as well.",
5
5
  "keywords": [
6
6
  "review-vir",
@@ -16,7 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git+https://github.com/review-vir/review-vir.git"
18
18
  },
19
- "license": "(MIT or CC0 1.0)",
19
+ "license": "(MIT OR CC0-1.0)",
20
20
  "author": {
21
21
  "name": "electrovir",
22
22
  "url": "https://github.com/electrovir"
@@ -35,20 +35,20 @@
35
35
  "test:docs": "virmator docs check"
36
36
  },
37
37
  "dependencies": {
38
- "@augment-vir/assert": "^31.1.1",
39
- "@augment-vir/common": "^31.1.1"
38
+ "@augment-vir/assert": "^32.2.1",
39
+ "@augment-vir/common": "^32.2.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@augment-vir/test": "^31.1.1",
43
- "@web/dev-server-esbuild": "^1.0.3",
44
- "@web/test-runner": "^0.19.0",
45
- "@web/test-runner-commands": "^0.9.0",
46
- "@web/test-runner-playwright": "^0.11.0",
47
- "@web/test-runner-visual-regression": "^0.10.0",
42
+ "@augment-vir/test": "^32.2.1",
43
+ "@web/dev-server-esbuild": "^2.0.0",
44
+ "@web/test-runner": "^1.0.0",
45
+ "@web/test-runner-commands": "^1.0.1",
46
+ "@web/test-runner-playwright": "^1.0.0",
47
+ "@web/test-runner-visual-regression": "^1.0.1",
48
48
  "istanbul-smart-text-reporter": "^1.1.5",
49
- "markdown-code-example-inserter": "^3.0.3",
50
- "typedoc": "^0.27.4",
51
- "typescript": "~5.6.3"
49
+ "markdown-code-example-inserter": "^3.0.6",
50
+ "typedoc": "^0.28.20",
51
+ "typescript": "^6.0.3"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"