Skip to content

Commit 1627f99

Browse files
authored
Merge pull request #3 from ynab/db/better-logging
add support for unfurl_links + better logging
2 parents 1483da3 + bd7f445 commit 1627f99

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Branch Builder
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches: [ main ]
8+
tags-ignore: "**"
9+
workflow_dispatch:
10+
env:
11+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} # github.head_ref for pull_request event and github.ref_name for push event
12+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TEST_TOKEN }}
13+
SLACK_CHANNEL_ID: ${{ secrets.SLACK_TEST_CHANNEL_ID }}
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Test Slack message with default settings
20+
id: basic-message
21+
uses: ./
22+
with:
23+
channel: ${{ env.SLACK_CHANNEL_ID }}
24+
text: 'Test message from <https://github.com/${{ github.repository }}|`${{ github.repository }}`>:\n\nMessage sent from: <https://github.com/${{ github.repository }}/compare/main...${{ env.BRANCH_NAME }}|`${{ env.BRANCH_NAME }}`>\nWorkflow Log: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Run ${{ github.run_id }}>'
25+
- name: Test Slack message with optional inputs specified (reply message + unfurl_links disabled)
26+
uses: ./
27+
with:
28+
channel: ${{ env.SLACK_CHANNEL_ID }}
29+
thread_ts: ${{ steps.basic-message.outputs.ts }}
30+
text: 'Test reply with a link to unfurl (that should _not_ unfurl): <https://aus.youneedabudget.com/|YNAB AU Marketing Site>'
31+
unfurl_links: false

action.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,37 @@ inputs:
1313
text:
1414
description: "The message text to post"
1515
required: true
16+
unfurl_links:
17+
description: "Whether links in the message should be unfurled"
18+
type: boolean
19+
default: true
1620
outputs:
1721
ts:
1822
description: "The timestamp ID of the message that was just posted"
23+
value: ${{steps.slack-post-message.outputs.ts}}
1924
branding:
2025
icon: 'tag'
2126
color: 'blue'
2227
runs:
2328
using: 'composite'
2429
steps:
25-
- run: |
26-
{
27-
echo "ts=<<EOF"
28-
curl --silent --show-error -X POST -H "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" -H "Content-Type: application/json; charset=utf-8" --url https://slack.com/api/chat.postMessage \
29-
-d "{\"channel\": \"${{ inputs.channel }}\", \"thread_ts\":\"${{ inputs.thread_ts }}\", \"text\":\"${{ inputs.text }}\"}" \
30-
| jq --raw-output '.ts'
31-
echo "EOF"
32-
} >> "$GITHUB_OUTPUT"
30+
- name: Validate required inputs
3331
shell: bash
32+
run: |
33+
[[ "${{ inputs.channel }}" ]] || { echo "required input 'channel' not specified" ; exit 1; }
34+
[[ "${{ inputs.text }}" ]] || { echo "required input 'text' not specified" ; exit 1; }
35+
- name: POST to chat.postMessage API
36+
id: slack-post-message
37+
shell: bash
38+
run: |
39+
response=$(curl --fail-with-body --silent --show-error \
40+
--request POST \
41+
--header "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" \
42+
--header "Content-Type: application/json; charset=utf-8" \
43+
--url https://slack.com/api/chat.postMessage \
44+
--data '{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \
45+
)
46+
echo "Slack message API response:\n$response"
47+
ts=$(echo "$response" | jq --raw-output '.ts')
48+
echo "Setting ts output to $ts"
49+
echo "ts=$ts" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)