Skip to content

Commit 44ac39c

Browse files
authored
fix: multiline and long commit message break formatting (#8)
* fix: multiline and long commit message break formatting * chore: bump package name
1 parent f0ff0bb commit 44ac39c

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

dist/main/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12102,7 +12102,8 @@ function postSlackNotification(slackToken, slackChannel, environment, status, co
1210212102
if ((payloadForPushes === null || payloadForPushes === void 0 ? void 0 : payloadForPushes.compare) !== undefined) {
1210312103
const beforeSha = payloadForPushes.before.slice(0, 7);
1210412104
const afterShaMessage = (_a = payloadForPushes.head_commit.message) !== null && _a !== void 0 ? _a : '';
12105-
commitText = `<${payloadForPushes.compare}|${beforeSha} ⇢ ${afterSha} ${afterShaMessage}>`;
12105+
const shortShaMessage = trimEllipsis(afterShaMessage.replace(/(\r\n|\n|\r).*$/gm, ''), 60); // keep only some first symbols of the first line
12106+
commitText = `<${payloadForPushes.compare}|${beforeSha} ⇢ ${afterSha} ${shortShaMessage}>`;
1210612107
}
1210712108
// message formatting reference - https://api.slack.com/reference/surfaces/formatting
1210812109
const text = `<${repoUrl}|${repo.repo}> deployment 🚀 to <${deploymentUrl}|${environment}> by @${actor} completed with ${status} ${statusIcon} - ${commitText}`;
@@ -12124,6 +12125,9 @@ function postSlackNotification(slackToken, slackChannel, environment, status, co
1212412125
});
1212512126
}
1212612127
exports.postSlackNotification = postSlackNotification;
12128+
function trimEllipsis(str, length) {
12129+
return str.length > length ? `${str.substring(0, length)}...` : str;
12130+
}
1212712131

1212812132

1212912133
/***/ }),

dist/post/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11969,7 +11969,8 @@ function postSlackNotification(slackToken, slackChannel, environment, status, co
1196911969
if ((payloadForPushes === null || payloadForPushes === void 0 ? void 0 : payloadForPushes.compare) !== undefined) {
1197011970
const beforeSha = payloadForPushes.before.slice(0, 7);
1197111971
const afterShaMessage = (_a = payloadForPushes.head_commit.message) !== null && _a !== void 0 ? _a : '';
11972-
commitText = `<${payloadForPushes.compare}|${beforeSha} ⇢ ${afterSha} ${afterShaMessage}>`;
11972+
const shortShaMessage = trimEllipsis(afterShaMessage.replace(/(\r\n|\n|\r).*$/gm, ''), 60); // keep only some first symbols of the first line
11973+
commitText = `<${payloadForPushes.compare}|${beforeSha} ⇢ ${afterSha} ${shortShaMessage}>`;
1197311974
}
1197411975
// message formatting reference - https://api.slack.com/reference/surfaces/formatting
1197511976
const text = `<${repoUrl}|${repo.repo}> deployment 🚀 to <${deploymentUrl}|${environment}> by @${actor} completed with ${status} ${statusIcon} - ${commitText}`;
@@ -11991,6 +11992,9 @@ function postSlackNotification(slackToken, slackChannel, environment, status, co
1199111992
});
1199211993
}
1199311994
exports.postSlackNotification = postSlackNotification;
11995+
function trimEllipsis(str, length) {
11996+
return str.length > length ? `${str.substring(0, length)}...` : str;
11997+
}
1199411998

1199511999

1199612000
/***/ }),

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "action-deploy",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"private": true,
55
"description": "Action to manage GitHub deployments",
66
"main": "lib/main.js",

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export async function postSlackNotification (
6464
if (payloadForPushes?.compare !== undefined) {
6565
const beforeSha = payloadForPushes.before.slice(0, 7)
6666
const afterShaMessage = payloadForPushes.head_commit.message ?? ''
67-
commitText = `<${payloadForPushes.compare}|${beforeSha}${afterSha} ${afterShaMessage}>`
67+
const shortShaMessage = trimEllipsis(afterShaMessage.replace(/(\r\n|\n|\r).*$/gm, ''), 60) // keep only some first symbols of the first line
68+
commitText = `<${payloadForPushes.compare}|${beforeSha}${afterSha} ${shortShaMessage}>`
6869
}
6970

7071
// message formatting reference - https://api.slack.com/reference/surfaces/formatting
@@ -84,3 +85,7 @@ export async function postSlackNotification (
8485
core.error(error)
8586
}
8687
}
88+
89+
function trimEllipsis (str: string, length: number): string {
90+
return str.length > length ? `${str.substring(0, length)}...` : str
91+
}

0 commit comments

Comments
 (0)