Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
atr0phy committed Feb 9, 2019
1 parent cab5d50 commit 3499b4a
Show file tree
Hide file tree
Showing 12 changed files with 596 additions and 381 deletions.
8 changes: 8 additions & 0 deletions README.md
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}'` ``
7 changes: 7 additions & 0 deletions docker-compose.yml
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
27 changes: 16 additions & 11 deletions index.js
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);
}
};
Loading

0 comments on commit 3499b4a

Please sign in to comment.