deploy-vir 3.6.0 → 3.6.2

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.
@@ -1,4 +1,5 @@
1
1
  import { FlagRequirement, parseArgs } from 'cli-vir';
2
+ import { join } from 'node:path';
2
3
  import { runDeployVirCli } from './cli.js';
3
4
  await runDeployVirCli(parseArgs(process.argv, {
4
5
  y: {
@@ -14,5 +15,6 @@ await runDeployVirCli(parseArgs(process.argv, {
14
15
  },
15
16
  }, {
16
17
  binName: 'deploy-vir',
18
+ packageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
17
19
  importMeta: import.meta,
18
20
  }), process.cwd());
package/dist/commit.d.ts CHANGED
@@ -14,4 +14,23 @@ export type Commit = DefaultLogFields & ListLogLine;
14
14
  *
15
15
  * @category Internal
16
16
  */
17
- export declare function getCommitAuthorName(commit: Readonly<Pick<Commit, 'author_name'> & PartialWithUndefined<Pick<Commit, 'hash' | 'message'>>>): Promise<string>;
17
+ export declare function getCommitAuthorName({ commit, gitUrl, }: Readonly<{
18
+ commit: Readonly<Pick<Commit, 'author_name'> & PartialWithUndefined<Pick<Commit, 'hash' | 'message'>>>;
19
+ gitUrl: string;
20
+ }>): Promise<string>;
21
+ /**
22
+ * Build the `gh` command that reads a pull request's assignees and author.
23
+ *
24
+ * `gh` picks its repo from the current directory's git remotes, which is not necessarily the repo
25
+ * being deployed, so the repo is always pinned with `--repo`. Without that, a pull request number
26
+ * from the deployed repo silently resolves to whatever unrelated pull request shares that number in
27
+ * the current directory's repo.
28
+ *
29
+ * @category Internal
30
+ */
31
+ export declare function buildPullRequestAuthorCommand({ pullRequestNumber, hash, gitUrl, }: Readonly<{
32
+ gitUrl: string;
33
+ } & PartialWithUndefined<{
34
+ pullRequestNumber: string;
35
+ hash: string;
36
+ }>>): string;
package/dist/commit.js CHANGED
@@ -15,28 +15,52 @@ const pullRequestAuthorCache = new Map();
15
15
  *
16
16
  * @category Internal
17
17
  */
18
- export async function getCommitAuthorName(commit) {
18
+ export async function getCommitAuthorName({ commit, gitUrl, }) {
19
19
  const pullRequestAuthorName = await getPullRequestAuthorName({
20
20
  pullRequestNumber: commit.message?.match(pullRequestNumberRegExp)?.[1],
21
21
  hash: commit.hash,
22
+ gitUrl,
22
23
  });
23
24
  return pullRequestAuthorName || commit.author_name;
24
25
  }
25
- function getPullRequestAuthorName({ pullRequestNumber, hash, }) {
26
- const cacheKey = pullRequestNumber || hash;
27
- if (!cacheKey) {
26
+ function getPullRequestAuthorName({ pullRequestNumber, hash, gitUrl, }) {
27
+ const pullRequestKey = pullRequestNumber || hash;
28
+ if (!pullRequestKey) {
28
29
  return Promise.resolve(undefined);
29
30
  }
31
+ /** Each repo gets its own cache entry because pull request numbers repeat across repos. */
32
+ const cacheKey = [
33
+ gitUrl,
34
+ pullRequestKey,
35
+ ].join(' ');
30
36
  const cached = pullRequestAuthorCache.get(cacheKey);
31
37
  if (cached) {
32
38
  return cached;
33
39
  }
34
- const pending = fetchPullRequestAuthorName(pullRequestNumber
35
- ? `gh pr view ${pullRequestNumber} --json assignees,author`
36
- : `gh pr list --search ${cacheKey} --state merged --limit 1 --json assignees,author`);
40
+ const pending = fetchPullRequestAuthorName(buildPullRequestAuthorCommand({
41
+ gitUrl,
42
+ hash,
43
+ pullRequestNumber,
44
+ }));
37
45
  pullRequestAuthorCache.set(cacheKey, pending);
38
46
  return pending;
39
47
  }
48
+ /**
49
+ * Build the `gh` command that reads a pull request's assignees and author.
50
+ *
51
+ * `gh` picks its repo from the current directory's git remotes, which is not necessarily the repo
52
+ * being deployed, so the repo is always pinned with `--repo`. Without that, a pull request number
53
+ * from the deployed repo silently resolves to whatever unrelated pull request shares that number in
54
+ * the current directory's repo.
55
+ *
56
+ * @category Internal
57
+ */
58
+ export function buildPullRequestAuthorCommand({ pullRequestNumber, hash, gitUrl, }) {
59
+ const repoFlag = `--repo '${gitUrl}'`;
60
+ return pullRequestNumber
61
+ ? `gh pr view ${pullRequestNumber} ${repoFlag} --json assignees,author`
62
+ : `gh pr list --search ${hash} ${repoFlag} --state merged --limit 1 --json assignees,author`;
63
+ }
40
64
  async function fetchPullRequestAuthorName(command) {
41
65
  try {
42
66
  const output = await runShellCommand(command, {
package/dist/git.js CHANGED
@@ -68,12 +68,18 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
68
68
  const requiresForcePush = commitsBehind.length > 0;
69
69
  log.info(`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`);
70
70
  await awaitedForEach(commitsAhead, async (commit, index) => {
71
- log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName(commit)}) - ${commit.message}`);
71
+ log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName({
72
+ commit,
73
+ gitUrl: repoConfig.gitUrl,
74
+ })}) - ${commit.message}`);
72
75
  });
73
76
  if (requiresForcePush) {
74
77
  log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
75
78
  await awaitedForEach(commitsBehind, async (commit, index) => {
76
- log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName(commit)}) - ${commit.message}`);
79
+ log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName({
80
+ commit,
81
+ gitUrl: repoConfig.gitUrl,
82
+ })}) - ${commit.message}`);
77
83
  });
78
84
  }
79
85
  const shouldPush = bypassConfirmation ||
@@ -8,7 +8,7 @@ import { type DeployResult } from '../git.js';
8
8
  export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
9
9
  deployResult: Readonly<DeployResult>;
10
10
  branchConfig: Readonly<DeployVirBranchConfig>;
11
- repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'name'>>;
11
+ repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'gitUrl' | 'name'>>;
12
12
  notification: Readonly<Extract<NotificationConfig, {
13
13
  target: Target;
14
14
  }>>;
@@ -9,8 +9,11 @@ function truncateString(value, truncateAt = 100) {
9
9
  return value;
10
10
  }
11
11
  }
12
- async function formatCommit(baseCommitUrl, commit) {
13
- const authorName = await getCommitAuthorName(commit);
12
+ async function formatCommit({ baseCommitUrl, commit, gitUrl, }) {
13
+ const authorName = await getCommitAuthorName({
14
+ commit,
15
+ gitUrl,
16
+ });
14
17
  if (baseCommitUrl) {
15
18
  return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${authorName}) ${truncateString(commit.message)}`;
16
19
  }
@@ -44,8 +47,20 @@ function chunkSectionLines(lines) {
44
47
  * @category Internal
45
48
  */
46
49
  export async function sendNotificationToSlack({ deployResult: { deployCommits: { deployedCommits, overwrittenCommits }, branchStatus: { after, before }, toBranchName, }, hookResult, notification, repoConfig, }) {
47
- const deployedCommitBullets = await Promise.all(deployedCommits.map(async (commit) => await formatCommit(repoConfig.commitBaseUrl, commit)));
48
- const overwrittenCommitBullets = await Promise.all(overwrittenCommits.map(async (commit) => await formatCommit(repoConfig.commitBaseUrl, commit)));
50
+ const deployedCommitBullets = await Promise.all(deployedCommits.map(async (commit) => {
51
+ return await formatCommit({
52
+ baseCommitUrl: repoConfig.commitBaseUrl,
53
+ commit,
54
+ gitUrl: repoConfig.gitUrl,
55
+ });
56
+ }));
57
+ const overwrittenCommitBullets = await Promise.all(overwrittenCommits.map(async (commit) => {
58
+ return await formatCommit({
59
+ baseCommitUrl: repoConfig.commitBaseUrl,
60
+ commit,
61
+ gitUrl: repoConfig.gitUrl,
62
+ });
63
+ }));
49
64
  const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);
50
65
  const overwrittenCommitBulletLines = overwrittenCommitBullets.length
51
66
  ? overwrittenCommitBullets.map((bullet) => `- ${bullet}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-vir",
3
- "version": "3.6.0",
3
+ "version": "3.6.2",
4
4
  "description": "Deploy a branch to another branch with notifications.",
5
5
  "keywords": [
6
6
  "deploy",
@@ -44,39 +44,39 @@
44
44
  "test:update": "npm run test update"
45
45
  },
46
46
  "dependencies": {
47
- "@augment-vir/assert": "^32.2.4",
48
- "@augment-vir/common": "^32.2.4",
49
- "@augment-vir/node": "^32.2.4",
50
- "@inquirer/prompts": "^8.7.0",
51
- "@slack/web-api": "^8.1.1",
52
- "cli-vir": "^1.0.5",
53
- "simple-git": "^3.36.0",
54
- "tsx": "^4.23.13",
47
+ "@augment-vir/assert": "^32.5.0",
48
+ "@augment-vir/common": "^32.5.0",
49
+ "@augment-vir/node": "^32.5.0",
50
+ "@inquirer/prompts": "^8.7.3",
51
+ "@slack/web-api": "^8.2.0",
52
+ "cli-vir": "^1.1.1",
53
+ "simple-git": "^4.0.2",
54
+ "tsx": "^4.23.15",
55
55
  "url-vir": "^2.2.2"
56
56
  },
57
57
  "devDependencies": {
58
- "@augment-vir/test": "^32.2.4",
59
- "@eslint/eslintrc": "^3.3.6",
58
+ "@augment-vir/test": "^32.5.0",
59
+ "@eslint/eslintrc": "^3.3.7",
60
60
  "@eslint/js": "^10.0.1",
61
61
  "@stylistic/eslint-plugin": "^5.10.0",
62
62
  "@stylistic/eslint-plugin-ts": "^4.4.1",
63
- "@types/node": "^26.4.0",
64
- "@typescript-eslint/eslint-plugin": "^8.68.0",
65
- "cspell": "^10.1.1",
66
- "dependency-cruiser": "^18.2.0",
63
+ "@types/node": "^26.6.5",
64
+ "@typescript-eslint/eslint-plugin": "^8.71.1",
65
+ "cspell": "^10.3.6",
66
+ "dependency-cruiser": "^18.5.0",
67
67
  "esbuild": "^0.28.2",
68
- "eslint": "^10.9.1",
68
+ "eslint": "^10.12.0",
69
69
  "eslint-config-prettier": "^10.1.8",
70
- "eslint-plugin-jsdoc": "^64.3.2",
70
+ "eslint-plugin-jsdoc": "^65.3.0",
71
71
  "eslint-plugin-monorepo-cop": "^1.0.2",
72
- "eslint-plugin-playwright": "^2.11.0",
72
+ "eslint-plugin-playwright": "^2.12.1",
73
73
  "eslint-plugin-prettier": "^5.5.6",
74
74
  "eslint-plugin-require-extensions": "^0.1.3",
75
- "eslint-plugin-sonarjs": "^4.2.0",
76
- "eslint-plugin-unicorn": "^74.0.0",
75
+ "eslint-plugin-sonarjs": "^4.2.2",
76
+ "eslint-plugin-unicorn": "^77.0.0",
77
77
  "istanbul-smart-text-reporter": "^1.1.5",
78
- "markdown-code-example-inserter": "^3.0.6",
79
- "npm-check-updates": "^23.1.0",
78
+ "markdown-code-example-inserter": "^3.1.1",
79
+ "npm-check-updates": "^23.1.1",
80
80
  "prettier": "~3.3.3",
81
81
  "prettier-plugin-interpolated-html-tags": "^2.0.2",
82
82
  "prettier-plugin-jsdoc": "^1.8.1",
@@ -84,12 +84,12 @@
84
84
  "prettier-plugin-organize-imports": "^4.3.0",
85
85
  "prettier-plugin-packagejson": "^3.0.2",
86
86
  "prettier-plugin-sort-json": "^4.2.0",
87
- "prettier-plugin-toml": "^2.0.6",
88
- "runstorm": "^1.0.6",
87
+ "prettier-plugin-toml": "^3.0.2",
88
+ "runstorm": "^1.1.0",
89
89
  "typedoc": "^0.28.20",
90
90
  "typescript": "^6.0.3",
91
- "typescript-eslint": "^8.68.0",
92
- "virmator": "^14.33.0"
91
+ "typescript-eslint": "^8.71.1",
92
+ "virmator": "^14.38.0"
93
93
  },
94
94
  "engines": {
95
95
  "node": ">=22"
@@ -1,4 +1,5 @@
1
1
  import {FlagRequirement, parseArgs} from 'cli-vir';
2
+ import {join} from 'node:path';
2
3
  import {runDeployVirCli} from './cli.js';
3
4
 
4
5
  await runDeployVirCli(
@@ -19,6 +20,7 @@ await runDeployVirCli(
19
20
  },
20
21
  {
21
22
  binName: 'deploy-vir',
23
+ packageJsonPath: join(import.meta.dirname, '..', '..', 'package.json'),
22
24
  importMeta: import.meta,
23
25
  },
24
26
  ),
package/src/commit.ts CHANGED
@@ -26,14 +26,19 @@ const pullRequestAuthorCache = new Map<string, Promise<string | undefined>>();
26
26
  *
27
27
  * @category Internal
28
28
  */
29
- export async function getCommitAuthorName(
29
+ export async function getCommitAuthorName({
30
+ commit,
31
+ gitUrl,
32
+ }: Readonly<{
30
33
  commit: Readonly<
31
34
  Pick<Commit, 'author_name'> & PartialWithUndefined<Pick<Commit, 'hash' | 'message'>>
32
- >,
33
- ): Promise<string> {
35
+ >;
36
+ gitUrl: string;
37
+ }>): Promise<string> {
34
38
  const pullRequestAuthorName = await getPullRequestAuthorName({
35
39
  pullRequestNumber: commit.message?.match(pullRequestNumberRegExp)?.[1],
36
40
  hash: commit.hash,
41
+ gitUrl,
37
42
  });
38
43
 
39
44
  return pullRequestAuthorName || commit.author_name;
@@ -42,18 +47,27 @@ export async function getCommitAuthorName(
42
47
  function getPullRequestAuthorName({
43
48
  pullRequestNumber,
44
49
  hash,
50
+ gitUrl,
45
51
  }: Readonly<
46
- PartialWithUndefined<{
52
+ {
53
+ gitUrl: string;
54
+ } & PartialWithUndefined<{
47
55
  pullRequestNumber: string;
48
56
  hash: string;
49
57
  }>
50
58
  >): Promise<string | undefined> {
51
- const cacheKey = pullRequestNumber || hash;
59
+ const pullRequestKey = pullRequestNumber || hash;
52
60
 
53
- if (!cacheKey) {
61
+ if (!pullRequestKey) {
54
62
  return Promise.resolve(undefined);
55
63
  }
56
64
 
65
+ /** Each repo gets its own cache entry because pull request numbers repeat across repos. */
66
+ const cacheKey = [
67
+ gitUrl,
68
+ pullRequestKey,
69
+ ].join(' ');
70
+
57
71
  const cached = pullRequestAuthorCache.get(cacheKey);
58
72
 
59
73
  if (cached) {
@@ -61,15 +75,46 @@ function getPullRequestAuthorName({
61
75
  }
62
76
 
63
77
  const pending = fetchPullRequestAuthorName(
64
- pullRequestNumber
65
- ? `gh pr view ${pullRequestNumber} --json assignees,author`
66
- : `gh pr list --search ${cacheKey} --state merged --limit 1 --json assignees,author`,
78
+ buildPullRequestAuthorCommand({
79
+ gitUrl,
80
+ hash,
81
+ pullRequestNumber,
82
+ }),
67
83
  );
68
84
  pullRequestAuthorCache.set(cacheKey, pending);
69
85
 
70
86
  return pending;
71
87
  }
72
88
 
89
+ /**
90
+ * Build the `gh` command that reads a pull request's assignees and author.
91
+ *
92
+ * `gh` picks its repo from the current directory's git remotes, which is not necessarily the repo
93
+ * being deployed, so the repo is always pinned with `--repo`. Without that, a pull request number
94
+ * from the deployed repo silently resolves to whatever unrelated pull request shares that number in
95
+ * the current directory's repo.
96
+ *
97
+ * @category Internal
98
+ */
99
+ export function buildPullRequestAuthorCommand({
100
+ pullRequestNumber,
101
+ hash,
102
+ gitUrl,
103
+ }: Readonly<
104
+ {
105
+ gitUrl: string;
106
+ } & PartialWithUndefined<{
107
+ pullRequestNumber: string;
108
+ hash: string;
109
+ }>
110
+ >): string {
111
+ const repoFlag = `--repo '${gitUrl}'`;
112
+
113
+ return pullRequestNumber
114
+ ? `gh pr view ${pullRequestNumber} ${repoFlag} --json assignees,author`
115
+ : `gh pr list --search ${hash} ${repoFlag} --state merged --limit 1 --json assignees,author`;
116
+ }
117
+
73
118
  async function fetchPullRequestAuthorName(command: string): Promise<string | undefined> {
74
119
  try {
75
120
  const output = await runShellCommand(command, {
package/src/git.ts CHANGED
@@ -158,7 +158,10 @@ export async function pushDeploy(
158
158
  );
159
159
  await awaitedForEach(commitsAhead, async (commit, index) => {
160
160
  log.faint(
161
- ` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName(commit)}) - ${commit.message}`,
161
+ ` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName({
162
+ commit,
163
+ gitUrl: repoConfig.gitUrl,
164
+ })}) - ${commit.message}`,
162
165
  );
163
166
  });
164
167
 
@@ -166,7 +169,10 @@ export async function pushDeploy(
166
169
  log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
167
170
  await awaitedForEach(commitsBehind, async (commit, index) => {
168
171
  log.faint(
169
- ` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName(commit)}) - ${commit.message}`,
172
+ ` ${index + 1}. ${commit.hash.slice(0, 7)} (${await getCommitAuthorName({
173
+ commit,
174
+ gitUrl: repoConfig.gitUrl,
175
+ })}) - ${commit.message}`,
170
176
  );
171
177
  });
172
178
  }
@@ -15,7 +15,7 @@ import {type DeployResult} from '../git.js';
15
15
  export type NotificationParams<Target extends NotificationTarget = NotificationTarget> = {
16
16
  deployResult: Readonly<DeployResult>;
17
17
  branchConfig: Readonly<DeployVirBranchConfig>;
18
- repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'name'>>;
18
+ repoConfig: Readonly<Pick<DeployVirRepoConfig, 'commitBaseUrl' | 'gitUrl' | 'name'>>;
19
19
  notification: Readonly<Extract<NotificationConfig, {target: Target}>>;
20
20
  hookResult?: Readonly<PostAcceptHookResult> | undefined;
21
21
  };
@@ -15,8 +15,19 @@ function truncateString(value: string, truncateAt = 100): string {
15
15
  }
16
16
  }
17
17
 
18
- async function formatCommit(baseCommitUrl: string | undefined, commit: Readonly<Commit>) {
19
- const authorName = await getCommitAuthorName(commit);
18
+ async function formatCommit({
19
+ baseCommitUrl,
20
+ commit,
21
+ gitUrl,
22
+ }: Readonly<{
23
+ baseCommitUrl: string | undefined;
24
+ commit: Readonly<Commit>;
25
+ gitUrl: string;
26
+ }>) {
27
+ const authorName = await getCommitAuthorName({
28
+ commit,
29
+ gitUrl,
30
+ });
20
31
 
21
32
  if (baseCommitUrl) {
22
33
  return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${authorName}) ${truncateString(commit.message)}`;
@@ -68,12 +79,22 @@ export async function sendNotificationToSlack({
68
79
  repoConfig,
69
80
  }: Readonly<NotificationParams>) {
70
81
  const deployedCommitBullets = await Promise.all(
71
- deployedCommits.map(async (commit) => await formatCommit(repoConfig.commitBaseUrl, commit)),
82
+ deployedCommits.map(async (commit) => {
83
+ return await formatCommit({
84
+ baseCommitUrl: repoConfig.commitBaseUrl,
85
+ commit,
86
+ gitUrl: repoConfig.gitUrl,
87
+ });
88
+ }),
72
89
  );
73
90
  const overwrittenCommitBullets = await Promise.all(
74
- overwrittenCommits.map(
75
- async (commit) => await formatCommit(repoConfig.commitBaseUrl, commit),
76
- ),
91
+ overwrittenCommits.map(async (commit) => {
92
+ return await formatCommit({
93
+ baseCommitUrl: repoConfig.commitBaseUrl,
94
+ commit,
95
+ gitUrl: repoConfig.gitUrl,
96
+ });
97
+ }),
77
98
  );
78
99
 
79
100
  const deployedCommitBulletLines = deployedCommitBullets.map((bullet) => `- ${bullet}`);