This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
596 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## description | ||
Slack notification of CodeBuild by Cloudwatch Events | ||
|
||
# how to install | ||
1. `pip3 install --user aws-sam-cli` | ||
1. `docker-compose up -d` | ||
1. `aws --endpoint-url http://localhost:4583 ssm put-parameter --name /development/slack_api_token --value YOUR_API_TOKEN --type String` | ||
1. ``sam local invoke BuildNotifyFunction --event ./test/events/in_progress.json --docker-network `docker network ls | grep build-notify_default | awk '{print $1}'` `` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: '3' | ||
services: | ||
localstack: | ||
image: localstack/localstack | ||
ports: | ||
- 4567-4584:4567-4584 | ||
- 8080:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
const Logger = require('./src/lib/logger'); | ||
const postMessage = require('./src/lib/slack-client'); | ||
const SlackClient = require('./src/lib/slack-client'); | ||
const getParameter = require('./src/lib/ssm-client'); | ||
|
||
const logger = new Logger(); | ||
|
||
const buildStatuses = { | ||
const SLACK_CHANNEL = process.env.SLACK_CHANNEL || ''; | ||
const SLACK_TOKEN_KEY = '/development/slack_api_token'; | ||
const BuildStatus = { | ||
IN_PROGRESS: 'デプロイを開始します', | ||
SUCCEEDED: 'デプロイに成功しました', | ||
FAILED: 'デプロイに失敗しました', | ||
STOPPED: 'デプロイに失敗しました', | ||
}; | ||
|
||
exports.myHandler = async (event) => { | ||
const getText = (buildStatus) => { | ||
let text = buildStatuses[buildStatus] || '一致するステータスがありません'; | ||
if ([buildStatuses.FAILED, buildStatuses.STOPPED].includes(text)) { | ||
const logger = new Logger(); | ||
|
||
exports.handle = async (event) => { | ||
const getText = (status) => { | ||
let text = BuildStatus[status] || '一致するステータスがありません'; | ||
if ([BuildStatus.FAILED, BuildStatus.STOPPED].includes(text)) { | ||
text += `\n ${event.detail['additional-information'].logs['deep-link']}`; | ||
} | ||
return text; | ||
}; | ||
|
||
const message = { | ||
channel: '#develop', | ||
channel: SLACK_CHANNEL, | ||
text: getText(event.detail['build-status']), | ||
icon_emoji: ':rocket:', | ||
username: 'build-notify', | ||
}; | ||
|
||
try { | ||
await postMessage(message); | ||
const token = await getParameter(SLACK_TOKEN_KEY); | ||
const slackClient = new SlackClient(token); | ||
await slackClient.postMessage(message); | ||
} catch (err) { | ||
logger.log(JSON.stringify(err)); | ||
logger.error(err); | ||
} | ||
}; |
Oops, something went wrong.