deploy-vir 0.2.5 → 0.2.7

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,4 @@
1
- import { addPrefix, capitalizeFirstLetter } from '@augment-vir/common';
1
+ import { addPrefix, capitalizeFirstLetter, log } from '@augment-vir/common';
2
2
  import { joinUrlPaths } from 'url-vir';
3
3
  function truncateString(value, truncateAt = 100) {
4
4
  if (value.length > truncateAt) {
@@ -9,12 +9,11 @@ function truncateString(value, truncateAt = 100) {
9
9
  }
10
10
  }
11
11
  function formatCommit(baseCommitUrl, commit) {
12
- const commitLine = `${commit.hash.slice(0, 7)} (${commit.author_name}) - ${truncateString(commit.message)}`;
13
12
  if (baseCommitUrl) {
14
- return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commitLine}>`;
13
+ return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${commit.author_name}) ${truncateString(commit.message)}`;
15
14
  }
16
15
  else {
17
- return commitLine;
16
+ return `${commit.hash.slice(0, 7)} (${commit.author_name}) ${truncateString(commit.message)}`;
18
17
  }
19
18
  }
20
19
  /**
@@ -81,31 +80,33 @@ export async function sendNotificationToSlack({ branchConfig, deployResult: { de
81
80
  });
82
81
  }
83
82
  async function sendSlackMessage(slackConfig, body) {
83
+ const messageBody = {
84
+ ...body,
85
+ ...(slackConfig.avatarEmoji
86
+ ? {
87
+ icon_emoji: slackConfig.avatarEmoji,
88
+ }
89
+ : {}),
90
+ ...(slackConfig.username
91
+ ? {
92
+ username: slackConfig.username,
93
+ }
94
+ : {}),
95
+ };
84
96
  try {
85
97
  const response = await fetch(slackConfig.webhookUrl, {
86
98
  method: 'POST',
87
99
  headers: {
88
100
  'Content-Type': 'application/json',
89
101
  },
90
- body: JSON.stringify({
91
- ...body,
92
- ...(slackConfig.avatarEmoji
93
- ? {
94
- icon_emoji: slackConfig.avatarEmoji,
95
- }
96
- : {}),
97
- ...(slackConfig.username
98
- ? {
99
- username: slackConfig.username,
100
- }
101
- : {}),
102
- }),
102
+ body: JSON.stringify(messageBody),
103
103
  });
104
104
  if (!response.ok) {
105
105
  throw new Error(`Failed to send Slack webhook: ${response.status}`);
106
106
  }
107
107
  }
108
108
  catch (error) {
109
+ log.error(JSON.stringify(messageBody, null, 4));
109
110
  console.error('Error sending Slack message:', error);
110
111
  }
111
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deploy-vir",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Deploy a branch to another branch with notifications.",
5
5
  "keywords": [
6
6
  "deploy",
@@ -1,4 +1,4 @@
1
- import {addPrefix, capitalizeFirstLetter} from '@augment-vir/common';
1
+ import {addPrefix, capitalizeFirstLetter, log} from '@augment-vir/common';
2
2
  import {type ChatPostMessageArguments, type KnownBlock} from '@slack/web-api';
3
3
  import {joinUrlPaths} from 'url-vir';
4
4
  import {type SlackNotificationConfig} from '../config.js';
@@ -16,12 +16,10 @@ function truncateString(value: string, truncateAt = 100): string {
16
16
  }
17
17
 
18
18
  function formatCommit(baseCommitUrl: string | undefined, commit: Readonly<Commit>) {
19
- const commitLine = `${commit.hash.slice(0, 7)} (${commit.author_name}) - ${truncateString(commit.message)}`;
20
-
21
19
  if (baseCommitUrl) {
22
- return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commitLine}>`;
20
+ return `<${joinUrlPaths(baseCommitUrl, commit.hash)}|${commit.hash.slice(0, 7)}> (${commit.author_name}) ${truncateString(commit.message)}`;
23
21
  } else {
24
- return commitLine;
22
+ return `${commit.hash.slice(0, 7)} (${commit.author_name}) ${truncateString(commit.message)}`;
25
23
  }
26
24
  }
27
25
 
@@ -111,31 +109,34 @@ async function sendSlackMessage(
111
109
  slackConfig: Readonly<Pick<SlackNotificationConfig, 'avatarEmoji' | 'webhookUrl' | 'username'>>,
112
110
  body: Readonly<ChatPostMessageArguments>,
113
111
  ) {
112
+ const messageBody = {
113
+ ...body,
114
+ ...(slackConfig.avatarEmoji
115
+ ? {
116
+ icon_emoji: slackConfig.avatarEmoji,
117
+ }
118
+ : {}),
119
+ ...(slackConfig.username
120
+ ? {
121
+ username: slackConfig.username,
122
+ }
123
+ : {}),
124
+ };
125
+
114
126
  try {
115
127
  const response = await fetch(slackConfig.webhookUrl, {
116
128
  method: 'POST',
117
129
  headers: {
118
130
  'Content-Type': 'application/json',
119
131
  },
120
- body: JSON.stringify({
121
- ...body,
122
- ...(slackConfig.avatarEmoji
123
- ? {
124
- icon_emoji: slackConfig.avatarEmoji,
125
- }
126
- : {}),
127
- ...(slackConfig.username
128
- ? {
129
- username: slackConfig.username,
130
- }
131
- : {}),
132
- }),
132
+ body: JSON.stringify(messageBody),
133
133
  });
134
134
 
135
135
  if (!response.ok) {
136
136
  throw new Error(`Failed to send Slack webhook: ${response.status}`);
137
137
  }
138
138
  } catch (error) {
139
+ log.error(JSON.stringify(messageBody, null, 4));
139
140
  console.error('Error sending Slack message:', error);
140
141
  }
141
142
  }