Skip to content

Commit

Permalink
truncate commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTheodor committed Jun 30, 2024
1 parent e6ce331 commit 002e3d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from '@actions/core'
import * as github from '@actions/github'

import { WebhookClient } from 'discord.js'
import { flatFiles, stripFormat } from './util'
import { flatFiles, stripFormat, truncate } from './util'

type Commit = { author: { name: string; username: any }; message: string; url: string }

Expand Down Expand Up @@ -30,7 +30,7 @@ export async function run() {
.replace('%LINK%', commit.url)
);

const message = rawMessage.replace('%COMMITS%', commits.join('\n'))
const message = rawMessage.replace('%COMMITS%', truncate(commits.join('\n'), 2000 - rawMessage.length))

try {
await webhookClient.send({
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ export function stripFormat(text: string) {

return text
}

export function truncate(text: string, n: number) {
return (text.length > n) ? text.slice(0, n - 3) + '...' : text;
}

0 comments on commit 002e3d8

Please sign in to comment.