deploy-vir 3.4.1 → 3.4.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.
@@ -0,0 +1,15 @@
1
+ import { type DefaultLogFields, type ListLogLine } from 'simple-git';
2
+ /**
3
+ * A git commit.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export type Commit = DefaultLogFields & ListLogLine;
8
+ /**
9
+ * Extract the human author name for a commit. Commits authored by a bot (a name with a `[bot]`
10
+ * suffix, like GitHub's merge queue bot) are attributed to their first non-bot `Co-authored-by:`
11
+ * trailer instead.
12
+ *
13
+ * @category Internal
14
+ */
15
+ export declare function getCommitAuthorName(commit: Readonly<Pick<Commit, 'author_name' | 'body'>>): string;
package/dist/commit.js ADDED
@@ -0,0 +1,19 @@
1
+ const coAuthorRegExp = /^co[- \t]*authored[- \t]*by:(.*)$/gim;
2
+ const botNameSuffix = '[bot]';
3
+ /**
4
+ * Extract the human author name for a commit. Commits authored by a bot (a name with a `[bot]`
5
+ * suffix, like GitHub's merge queue bot) are attributed to their first non-bot `Co-authored-by:`
6
+ * trailer instead.
7
+ *
8
+ * @category Internal
9
+ */
10
+ export function getCommitAuthorName(commit) {
11
+ if (!commit.author_name.endsWith(botNameSuffix)) {
12
+ return commit.author_name;
13
+ }
14
+ const coAuthorName = Array.from(commit.body.matchAll(coAuthorRegExp))
15
+ /** Strip the trailing `<email>` from each trailer. */
16
+ .map((match) => (match[1] || '').split('<')[0]?.trim())
17
+ .find((name) => name && !name.endsWith(botNameSuffix));
18
+ return coAuthorName || commit.author_name;
19
+ }
package/dist/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
2
- import { type Commit, type DeployResult } from './git.js';
2
+ import { type Commit } from './commit.js';
3
+ import { type DeployResult } from './git.js';
3
4
  /**
4
5
  * The full deploy-vir config object.
5
6
  *
package/dist/git.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type DefaultLogFields, type ListLogLine, type SimpleGit } from 'simple-git';
1
+ import { type SimpleGit } from 'simple-git';
2
+ import { type Commit } from './commit.js';
2
3
  import { type DeployVirBranchConfig, type DeployVirHooks, type DeployVirRepoConfig, type NotificationConfig } from './config.js';
3
4
  /**
4
5
  * Find the git remote's name, or create a new one.
@@ -6,12 +7,6 @@ import { type DeployVirBranchConfig, type DeployVirHooks, type DeployVirRepoConf
6
7
  * @category Internal
7
8
  */
8
9
  export declare function getGitRemoteName(git: Readonly<SimpleGit>, repoConfig: Readonly<Pick<DeployVirRepoConfig, 'name' | 'gitUrl'>>): Promise<string>;
9
- /**
10
- * A git commit.
11
- *
12
- * @category Internal
13
- */
14
- export type Commit = DefaultLogFields & ListLogLine;
15
10
  /**
16
11
  * All commits involved in a deploy.
17
12
  *
package/dist/git.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { assert, assertWrap, check } from '@augment-vir/assert';
2
2
  import { awaitedBlockingMap, log, logColors } from '@augment-vir/common';
3
3
  import { confirm } from '@inquirer/prompts';
4
+ import { getCommitAuthorName } from './commit.js';
4
5
  import { KnownError } from './known.error.js';
5
6
  import { sendNotifications } from './notifications/send-notifications.js';
6
7
  /**
@@ -65,12 +66,12 @@ export async function pushDeploy(git, branchConfig, repoConfig, remoteName, noti
65
66
  const requiresForcePush = commitsBehind.length > 0;
66
67
  log.info(`\n${requiresForcePush ? 'Only on' : 'Releasing from'} ${logColors.bold}${fromBranch}${logColors.reset}:`);
67
68
  commitsAhead.forEach((commit, index) => {
68
- log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`);
69
+ log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) - ${commit.message}`);
69
70
  });
70
71
  if (requiresForcePush) {
71
72
  log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
72
73
  commitsBehind.forEach((commit, index) => {
73
- log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`);
74
+ log.faint(` ${index + 1}. ${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) - ${commit.message}`);
74
75
  });
75
76
  }
76
77
  const shouldPush = bypassConfirmation ||
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './cli/cli.js';
2
+ export * from './commit.js';
2
3
  export * from './config.js';
3
4
  export * from './git.js';
4
5
  export * from './known.error.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './cli/cli.js';
2
+ export * from './commit.js';
2
3
  export * from './config.js';
3
4
  export * from './git.js';
4
5
  export * from './known.error.js';
@@ -1,5 +1,6 @@
1
1
  import { addPrefix, log, setFirstLetterCasing, StringCase } from '@augment-vir/common';
2
2
  import { joinUrlPaths } from 'url-vir';
3
+ import { getCommitAuthorName } from '../commit.js';
3
4
  function truncateString(value, truncateAt = 100) {
4
5
  if (value.length > truncateAt) {
5
6
  return `${value.slice(0, Math.max(0, truncateAt))}...`;
@@ -10,10 +11,10 @@ function truncateString(value, truncateAt = 100) {
10
11
  }
11
12
  function formatCommit(baseCommitUrl, commit) {
12
13
  if (baseCommitUrl) {
13
- return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${commit.author_name}) ${truncateString(commit.message)}`;
14
+ return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${getCommitAuthorName(commit)}) ${truncateString(commit.message)}`;
14
15
  }
15
16
  else {
16
- return `${commit.hash.slice(0, 7)} (${commit.author_name}) ${truncateString(commit.message)}`;
17
+ return `${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) ${truncateString(commit.message)}`;
17
18
  }
18
19
  }
19
20
  const slackMaxSectionLength = 2500;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-vir",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
4
4
  "description": "Deploy a branch to another branch with notifications.",
5
5
  "keywords": [
6
6
  "deploy",
@@ -32,7 +32,8 @@
32
32
  "format": "virmator format",
33
33
  "lint": "virmator lint fix",
34
34
  "publish": "virmator publish npm run test:all",
35
- "test:all": "npm run compile && runstorm --names spelling,format,docs,deps,lint \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\" \"npm run test:lint\"",
35
+ "test": "virmator test node",
36
+ "test:all": "npm run compile && runstorm --names spelling,format,docs,deps,lint,test \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\" \"npm run test:lint\" \"npm test\"",
36
37
  "test:deps": "virmator deps check",
37
38
  "test:docs": "virmator docs check",
38
39
  "test:format": "virmator format check",
@@ -52,6 +53,7 @@
52
53
  "url-vir": "^2.1.10"
53
54
  },
54
55
  "devDependencies": {
56
+ "@augment-vir/test": "^32.2.1",
55
57
  "@eslint/eslintrc": "^3.3.6",
56
58
  "@eslint/js": "^10.0.1",
57
59
  "@stylistic/eslint-plugin": "^5.10.0",
package/src/commit.ts ADDED
@@ -0,0 +1,33 @@
1
+ import {type DefaultLogFields, type ListLogLine} from 'simple-git';
2
+
3
+ /**
4
+ * A git commit.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export type Commit = DefaultLogFields & ListLogLine;
9
+
10
+ const coAuthorRegExp = /^co[- \t]*authored[- \t]*by:(.*)$/gim;
11
+ const botNameSuffix = '[bot]';
12
+
13
+ /**
14
+ * Extract the human author name for a commit. Commits authored by a bot (a name with a `[bot]`
15
+ * suffix, like GitHub's merge queue bot) are attributed to their first non-bot `Co-authored-by:`
16
+ * trailer instead.
17
+ *
18
+ * @category Internal
19
+ */
20
+ export function getCommitAuthorName(
21
+ commit: Readonly<Pick<Commit, 'author_name' | 'body'>>,
22
+ ): string {
23
+ if (!commit.author_name.endsWith(botNameSuffix)) {
24
+ return commit.author_name;
25
+ }
26
+
27
+ const coAuthorName = Array.from(commit.body.matchAll(coAuthorRegExp))
28
+ /** Strip the trailing `<email>` from each trailer. */
29
+ .map((match) => (match[1] || '').split('<')[0]?.trim())
30
+ .find((name) => name && !name.endsWith(botNameSuffix));
31
+
32
+ return coAuthorName || commit.author_name;
33
+ }
package/src/config.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {type MaybePromise, type PartialWithUndefined} from '@augment-vir/common';
2
- import {type Commit, type DeployResult} from './git.js';
2
+ import {type Commit} from './commit.js';
3
+ import {type DeployResult} from './git.js';
3
4
 
4
5
  /**
5
6
  * The full deploy-vir config object.
package/src/git.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import {assert, assertWrap, check} from '@augment-vir/assert';
2
2
  import {awaitedBlockingMap, log, logColors} from '@augment-vir/common';
3
3
  import {confirm} from '@inquirer/prompts';
4
- import {type DefaultLogFields, type ListLogLine, type SimpleGit} from 'simple-git';
4
+ import {type SimpleGit} from 'simple-git';
5
+ import {getCommitAuthorName, type Commit} from './commit.js';
5
6
  import {
6
7
  type DeployNotificationConfig,
7
8
  type DeployVirBranchConfig,
@@ -52,13 +53,6 @@ export async function getGitRemoteName(
52
53
  return newRemoteName;
53
54
  }
54
55
 
55
- /**
56
- * A git commit.
57
- *
58
- * @category Internal
59
- */
60
- export type Commit = DefaultLogFields & ListLogLine;
61
-
62
56
  /**
63
57
  * All commits involved in a deploy.
64
58
  *
@@ -165,7 +159,7 @@ export async function pushDeploy(
165
159
  );
166
160
  commitsAhead.forEach((commit, index) => {
167
161
  log.faint(
168
- ` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
162
+ ` ${index + 1}. ${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) - ${commit.message}`,
169
163
  );
170
164
  });
171
165
 
@@ -173,7 +167,7 @@ export async function pushDeploy(
173
167
  log.info(`\nOnly on ${logColors.bold}${toBranch}${logColors.reset}:`);
174
168
  commitsBehind.forEach((commit, index) => {
175
169
  log.faint(
176
- ` ${index + 1}. ${commit.hash.slice(0, 7)} (${commit.author_name}) - ${commit.message}`,
170
+ ` ${index + 1}. ${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) - ${commit.message}`,
177
171
  );
178
172
  });
179
173
  }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './cli/cli.js';
2
+ export * from './commit.js';
2
3
  export * from './config.js';
3
4
  export * from './git.js';
4
5
  export * from './known.error.js';
@@ -1,8 +1,8 @@
1
1
  import {addPrefix, log, setFirstLetterCasing, StringCase} from '@augment-vir/common';
2
2
  import {type ChatPostMessageArguments, type KnownBlock} from '@slack/web-api';
3
3
  import {joinUrlPaths} from 'url-vir';
4
+ import {getCommitAuthorName, type Commit} from '../commit.js';
4
5
  import {type SlackNotificationConfig} from '../config.js';
5
- import {type Commit} from '../git.js';
6
6
  import {type NotificationParams} from './notification-params.js';
7
7
 
8
8
  export {type ChatPostMessageArguments} from '@slack/web-api';
@@ -17,9 +17,9 @@ function truncateString(value: string, truncateAt = 100): string {
17
17
 
18
18
  function formatCommit(baseCommitUrl: string | undefined, commit: Readonly<Commit>) {
19
19
  if (baseCommitUrl) {
20
- return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${commit.author_name}) ${truncateString(commit.message)}`;
20
+ return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${getCommitAuthorName(commit)}) ${truncateString(commit.message)}`;
21
21
  } else {
22
- return `${commit.hash.slice(0, 7)} (${commit.author_name}) ${truncateString(commit.message)}`;
22
+ return `${commit.hash.slice(0, 7)} (${getCommitAuthorName(commit)}) ${truncateString(commit.message)}`;
23
23
  }
24
24
  }
25
25