Skip to content

Commit

Permalink
fix: improve formatting for long commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
titenkov committed Dec 7, 2023
1 parent e7c06cc commit 81f43e6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,23 @@ try {
const links = getLinks()

const statusIcon = getStatusIcon(status)

const originalCommitMessage = github.context.payload.head_commit ? github.context.payload.head_commit.message
: (github.context.payload.pull_request && github.context.payload.pull_request.head.label ? github.context.payload.pull_request.head.label : '')

const commitMessage = originalCommitMessage.length > 50 ? originalCommitMessage.substring(0, 50) + '...' : originalCommitMessage
const originalCommitMessage = github.context.payload.head_commit
? github.context.payload.head_commit.message
: github.context.payload.pull_request && github.context.payload.pull_request.head.label
? github.context.payload.pull_request.head.label
: ''

const details = commitMessage
? `>${commitMessage}\n>${links.commit} | By *${sender.name}* on \`${env.branch}\` | ${links.repository}`
: `>By *${sender.name}* on \`${env.branch}\` | ${links.repository}`
const newlineIndex = originalCommitMessage.indexOf('\n');

// Trim commit message to first line
let commitMessage = newlineIndex > -1 ? originalCommitMessage.substring(0, newlineIndex) : originalCommitMessage;
// Trim commit message to 50 characters
commitMessage = commitMessage.length >= 50 ? commitMessage.substring(0, 50) + '...' : commitMessage

const details = commitMessage
? `>${commitMessage}\n>${links.commit} | By *${sender.name}* on \`${env.branch}\``
: `>By *${sender.name}* on \`${env.branch}\``

if (!process.env.SLACK_WEBHOOK_URL) {
core.setFailed('Missing SLACK_WEBHOOK_URL environment variable')
Expand All @@ -150,7 +158,16 @@ try {
text: details
}
]
}
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `:slack: ${links.repository}`
}
],
},
]
}
;(async () => {
Expand Down

0 comments on commit 81f43e6

Please sign in to comment.