Skip to content

Commit

Permalink
fix: Only show title for multiline commits (#6)
Browse files Browse the repository at this point in the history
Commits that have a title and a description broke the slack message because of the newline character.
  • Loading branch information
iRoachie authored Jun 29, 2020
1 parent ceac6a0 commit 9fc2263
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- run: npm install
- run: npm test

- uses: iRoachie/[email protected].0
- uses: iRoachie/[email protected].1
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
- uses: actions/checkout@v2
- run: yarn
- run: yarn test
- uses: iRoachie/[email protected].0
- uses: iRoachie/[email protected].1
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
Expand All @@ -132,7 +132,7 @@ jobs:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- uses: iRoachie/[email protected].0
- uses: iRoachie/[email protected].1
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
Expand All @@ -144,7 +144,7 @@ jobs:
needs: [test, lint]
runs-on: ubuntu-latest
steps:
- uses: iRoachie/[email protected].0
- uses: iRoachie/[email protected].1
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
Expand Down
7 changes: 6 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21666,7 +21666,12 @@ const getMessage = () => {
return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${tag.commit}|${commitId}>) for Tag <${tag.url}| ${tag.title}>`;
}

return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${github_1.payload.compare}|${commitId}>) for Commit <${github_1.payload.head_commit.url}| ${github_1.payload.head_commit.message}>`;
const commitMessage = github_1.payload.head_commit.message;
const headCommit = {
title: commitMessage.includes('\n') ? commitMessage.substring(0, commitMessage.indexOf('\n')) : commitMessage,
url: github_1.payload.head_commit.url
};
return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${github_1.payload.compare}|${commitId}>) for Commit <${headCommit.url}| ${headCommit.title}>`;
}

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-github-action",
"version": "1.1.0",
"version": "1.1.1",
"source": "src/index.ts",
"main": "dist/index.js",
"repository": "https://github.com/iRoachie/slack-github-action.git",
Expand Down
10 changes: 9 additions & 1 deletion src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ const getMessage = () => {
return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${tag.commit}|${commitId}>) for Tag <${tag.url}| ${tag.title}>`;
}

const commitMessage = context.payload.head_commit.message;
const headCommit = {
title: commitMessage.includes('\n')
? commitMessage.substring(0, commitMessage.indexOf('\n'))
: commitMessage,
url: context.payload.head_commit.url,
};

// Normal commit push
return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${context.payload.compare}|${commitId}>) for Commit <${context.payload.head_commit.url}| ${context.payload.head_commit.message}>`;
return `Workflow <${runUrl}|${process.env.GITHUB_WORKFLOW}> (<${context.payload.compare}|${commitId}>) for Commit <${headCommit.url}| ${headCommit.title}>`;
}

default:
Expand Down

0 comments on commit 9fc2263

Please sign in to comment.