Skip to content

Commit

Permalink
Add support for specifying the Slack channel ID to be included in the…
Browse files Browse the repository at this point in the history
… payload (#607)

This is necessary with the changes in the slack-github-action v2, where it
expects the full payload to be passed to it, rather than having the channel ID
set separately.
  • Loading branch information
Tenzer authored Nov 15, 2024
1 parent 0115ab6 commit 242fc3a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Three different output formats are supplied, plain text, Markdown and for Slack.
# Default: true
chronological: ''

# Channel ID to include in the Slack payload
#
# Default: ''
slack channel: ''

# Template for the message to be included before the list of changes to Slack.
#
# Supports Markdown and makes the following variables available:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
chronological:
description: Output changes in chronological order
default: true
slack channel:
description: Channel ID to include in the Slack message payload
default: ""
slack template:
description: |
Message template to be used for line above the Slack output.
Expand Down
5 changes: 3 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ export function getMarkdownFormat(commits: Commit[]): string {
return lines.join('\n')
}

export function getSlackFormat(commits: Commit[], since: string, until: string, slackTemplate: string): string {
export function getSlackFormat(
commits: Commit[],
since: string,
until: string,
slackTemplate: string,
slackChannel: string
): string {
const lines = []

for (const commit of commits) {
Expand Down Expand Up @@ -101,6 +107,7 @@ export function getSlackFormat(commits: Commit[], since: string, until: string,
const now = new Date()

const result = {
channel: slackChannel,
blocks: [
{
type: 'section',
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ async function run(): Promise<void> {

core.setOutput('plain-text', formatting.getPlainTextFormat(commits))
core.setOutput('markdown', formatting.getMarkdownFormat(commits))
core.setOutput('slack', formatting.getSlackFormat(commits, since, until, core.getInput('slack template')))
core.setOutput(
'slack',
formatting.getSlackFormat(commits, since, until, core.getInput('slack template'), core.getInput('slack channel'))
)
}

run()

0 comments on commit 242fc3a

Please sign in to comment.