@review-vir/common 3.0.0 → 3.1.1

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Defines the Markdown that identifies a code owners block in a pull request description.
3
+ *
4
+ * @category Main
5
+ */
6
+ export declare const codeOwnersMarkdown: Readonly<{
7
+ blockEnd: "<!-- code owners end -->";
8
+ blockStart: "<!-- code owners start -->";
9
+ heading: "## Code Owners";
10
+ }>;
11
+ /**
12
+ * Formats the code owners content that pull-request-vir writes into a pull request description.
13
+ *
14
+ * @category Main
15
+ */
16
+ export declare function createCodeOwnersMarkdownBlock(content: string): string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Defines the Markdown that identifies a code owners block in a pull request description.
3
+ *
4
+ * @category Main
5
+ */
6
+ export const codeOwnersMarkdown = Object.freeze({
7
+ blockEnd: '<!-- code owners end -->',
8
+ blockStart: '<!-- code owners start -->',
9
+ heading: '## Code Owners',
10
+ });
11
+ /**
12
+ * Formats the code owners content that pull-request-vir writes into a pull request description.
13
+ *
14
+ * @category Main
15
+ */
16
+ export function createCodeOwnersMarkdownBlock(content) {
17
+ return [
18
+ codeOwnersMarkdown.blockStart,
19
+ codeOwnersMarkdown.heading,
20
+ content,
21
+ codeOwnersMarkdown.blockEnd,
22
+ ].join('\n');
23
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from './code-owners-markdown.js';
1
2
  export * from './parse-description-users.js';
3
+ export * from './parse-inserted-code-owners.js';
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
+ export * from './code-owners-markdown.js';
1
2
  export * from './parse-description-users.js';
3
+ 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,47 @@
1
+ import { removeDuplicates, removePrefix, safeMatch } from '@augment-vir/common';
2
+ import { codeOwnersMarkdown } from './code-owners-markdown.js';
3
+ const insertedCodeOwnersRegExp = new RegExp(String.raw `${codeOwnersMarkdown.blockStart}([\S\s]*?)${codeOwnersMarkdown.blockEnd}`, 'i');
4
+ const fileLinkLineRegExp = /^\s*-\s/;
5
+ const userTagRegExp = /@[\w-]+/g;
6
+ /**
7
+ * Parses the code owners that pull-request-vir inserts into a pull request's _raw markdown_ body.
8
+ *
9
+ * Pull-request-vir wraps its code owners in HTML comment delimiters and lists each owner on its own
10
+ * line followed by a collapsible list of their owned files:
11
+ *
12
+ * <!-- code owners start -->
13
+ * ## Code Owners
14
+ * (at)username1
15
+ * <details>
16
+ * <summary>Owned files</summary>
17
+ *
18
+ * - [some/file.ts](https://...)
19
+ *
20
+ * </details>
21
+ * (at)username2
22
+ * ...
23
+ * <!-- code owners end -->
24
+ *
25
+ * Returns the owner usernames (e.g. `['username1', 'username2']`), or `undefined` when the body
26
+ * contains no inserted code owners block (so callers can fall back to other detection).
27
+ *
28
+ * This must run against the raw markdown `body`, not the rendered `bodyText`: GitHub strips HTML
29
+ * comments (and the `<details>` structure) out of `bodyText`, removing the delimiters that bound
30
+ * the block and interleaving the owners with their owned-file text.
31
+ */
32
+ export function parseInsertedCodeOwners(body) {
33
+ const [, block,] = safeMatch(body, insertedCodeOwnersRegExp);
34
+ if (block == undefined) {
35
+ return undefined;
36
+ }
37
+ /** Drop owned-file link lines so scoped paths (e.g. `@types/...`) aren't read as owners. */
38
+ const ownerLines = block
39
+ .split('\n')
40
+ .filter((line) => !fileLinkLineRegExp.test(line))
41
+ .join('\n');
42
+ const userTags = Array.from(ownerLines.matchAll(userTagRegExp));
43
+ return removeDuplicates(userTags.map((userTag) => removePrefix({
44
+ value: userTag[0],
45
+ prefix: '@',
46
+ })));
47
+ }
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.1",
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"