@review-vir/common 2.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
- export * from './parse-primary-reviewers.js';
1
+ export * from './parse-description-users.js';
2
+ export * from './parse-inserted-code-owners.js';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export * from './parse-primary-reviewers.js';
1
+ export * from './parse-description-users.js';
2
+ export * from './parse-inserted-code-owners.js';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Accepts a pull request text body, expected to be in plain text format (not markdown) and parses
3
+ * out tagged primary reviewers from strings that look like:
4
+ *
5
+ * `primary reviewer: @username, @otherUsername`
6
+ *
7
+ * Which will return the following output:
8
+ *
9
+ * `['username', 'otherUsername']`
10
+ */
11
+ export declare function parseDescriptionUsers({ triggerText, bodyText, }: {
12
+ /**
13
+ * The start of the line for which usernames need to be parsed out of. An `'s'` is automatically
14
+ * allowed at the end of this text. Case insensitive.
15
+ *
16
+ * @example
17
+ *
18
+ * - `'primary reviewer'`
19
+ * - `'code owner'`
20
+ */
21
+ triggerText: string;
22
+ bodyText: string;
23
+ }): string[];
@@ -0,0 +1,23 @@
1
+ import { removePrefix, safeMatch } from '@augment-vir/common';
2
+ /**
3
+ * Accepts a pull request text body, expected to be in plain text format (not markdown) and parses
4
+ * out tagged primary reviewers from strings that look like:
5
+ *
6
+ * `primary reviewer: @username, @otherUsername`
7
+ *
8
+ * Which will return the following output:
9
+ *
10
+ * `['username', 'otherUsername']`
11
+ */
12
+ export function parseDescriptionUsers({ triggerText, bodyText, }) {
13
+ const [, match,] = safeMatch(bodyText, new RegExp(`${triggerText}s?\\W+((?:@[^@]+)+)(?:\n\n|$|\n#)`, 'i'));
14
+ if (!match) {
15
+ return [];
16
+ }
17
+ const [, restrictedMatch,] = safeMatch(match, /((?:@[\w-]+[^\w@]*)+)/);
18
+ const userTags = Array.from(restrictedMatch?.matchAll(/@[\w-]+/g) || []);
19
+ return userTags.map((userTag) => removePrefix({
20
+ value: userTag[0],
21
+ prefix: '@',
22
+ }));
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,7 +1,13 @@
1
1
  {
2
2
  "name": "@review-vir/common",
3
- "version": "2.0.0",
4
- "keywords": [],
3
+ "version": "3.1.0",
4
+ "description": "Common functionality that review-vir primary uses but other external packages need as well.",
5
+ "keywords": [
6
+ "review-vir",
7
+ "primary reviewers",
8
+ "vir",
9
+ "code owners"
10
+ ],
5
11
  "homepage": "https://github.com/review-vir/review-vir",
6
12
  "bugs": {
7
13
  "url": "https://github.com/review-vir/review-vir/issues"
@@ -10,7 +16,7 @@
10
16
  "type": "git",
11
17
  "url": "git+https://github.com/review-vir/review-vir.git"
12
18
  },
13
- "license": "(MIT or CC0 1.0)",
19
+ "license": "(MIT OR CC0-1.0)",
14
20
  "author": {
15
21
  "name": "electrovir",
16
22
  "url": "https://github.com/electrovir"
@@ -29,20 +35,20 @@
29
35
  "test:docs": "virmator docs check"
30
36
  },
31
37
  "dependencies": {
32
- "@augment-vir/assert": "^30.2.0",
33
- "@augment-vir/common": "^30.2.0"
38
+ "@augment-vir/assert": "^32.2.1",
39
+ "@augment-vir/common": "^32.2.1"
34
40
  },
35
41
  "devDependencies": {
36
- "@augment-vir/test": "^30.2.0",
37
- "@web/dev-server-esbuild": "^1.0.2",
38
- "@web/test-runner": "^0.19.0",
39
- "@web/test-runner-commands": "^0.9.0",
40
- "@web/test-runner-playwright": "^0.11.0",
41
- "@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",
42
48
  "istanbul-smart-text-reporter": "^1.1.5",
43
- "markdown-code-example-inserter": "^3.0.0",
44
- "typedoc": "^0.26.8",
45
- "typescript": "^5.6.2"
49
+ "markdown-code-example-inserter": "^3.0.6",
50
+ "typedoc": "^0.28.20",
51
+ "typescript": "^6.0.3"
46
52
  },
47
53
  "engines": {
48
54
  "node": ">=22"
@@ -1,13 +0,0 @@
1
- /**
2
- * Accepts a pull request text body, expected to be in plain text format (not markdown) and parses
3
- * out tagged primary reviewers from strings that look like:
4
- *
5
- * `primary reviewer: @username, @otherUsername`
6
- *
7
- * Which will return the following output:
8
- *
9
- * `['username', 'otherUsername']`
10
- */
11
- export declare function parsePrimaryReviewers({ bodyText }: {
12
- bodyText: string;
13
- }): string[];
@@ -1,19 +0,0 @@
1
- import { removePrefix, safeMatch } from '@augment-vir/common';
2
- /**
3
- * Accepts a pull request text body, expected to be in plain text format (not markdown) and parses
4
- * out tagged primary reviewers from strings that look like:
5
- *
6
- * `primary reviewer: @username, @otherUsername`
7
- *
8
- * Which will return the following output:
9
- *
10
- * `['username', 'otherUsername']`
11
- */
12
- export function parsePrimaryReviewers({ bodyText }) {
13
- const [, match,] = safeMatch(bodyText, /primary reviewers?\W+((?:@[^@\s]+(?:\s|$))+)/i);
14
- if (!match) {
15
- return [];
16
- }
17
- const userTags = Array.from(match.matchAll(/@[\w-]+/g));
18
- return userTags.map((userTag) => removePrefix({ value: userTag[0], prefix: '@' }));
19
- }