Skip to content

Commit 997cf65

Browse files
init
0 parents  commit 997cf65

File tree

9 files changed

+639
-0
lines changed

9 files changed

+639
-0
lines changed

.gitignore

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# parcel-bundler cache (https://parceljs.org/)
61+
.cache
62+
63+
# next.js build output
64+
.next
65+
66+
# nuxt.js build output
67+
.nuxt
68+
69+
# vuepress build output
70+
.vuepress/dist
71+
72+
# Serverless directories
73+
.serverless/
74+
75+
# FuseBox cache
76+
.fusebox/
77+
78+
#DynamoDB Local files
79+
.dynamodb/
80+
81+
.idea/

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:10.13.0-alpine
2+
WORKDIR /app/
3+
COPY package.json ./
4+
COPY yarn.lock ./
5+
RUN yarn install
6+
COPY . ./
7+
CMD ["node", "/app/index.js"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Codefresh plugin for send SMS notification
2+
3+
Codefresh plugin for send SMS notification via Twilio
4+
5+
## Main env variables
6+
- `TWILIO_SID`
7+
- `TWILIO_TOKEN`
8+
- `TWILIO_PHONE_FROM`
9+
- `TWILIO_PHONE_TO`
10+
- `TWILIO_TYPE` - type of message [build, message, hello]
11+
12+
For **message** type you must provide `TWILIO_MESSAGE` env
13+
14+
## Config for codefresh.yml
15+
```
16+
version: '1.0'
17+
...
18+
steps:
19+
...
20+
TestSMS:
21+
title: Test SMS
22+
image: potterua/twilioplugincodefresh:latest
23+
...
24+
...
25+
```

codefresh.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '1.0'
2+
steps:
3+
BuildingDockerImage:
4+
title: 'Building Docker Image'
5+
type: 'build'
6+
dockerfile: 'Dockerfile'
7+
image_name: 'codefresh-io/twilioplugincodefresh'
8+
PushDockerHub:
9+
title: 'Pushing to dockerhub'
10+
type: 'push'
11+
candidate: '${{BuildingDockerImage}}'
12+
tag: 'latest'
13+
registry: 'dockerhub'
14+
image_name: 'codefresh-io/twilioplugincodefresh'
15+

helpers/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
envValid: (envs) => {
3+
for (let env of envs) {
4+
if (!process.env[env]) {
5+
throw Error(`Provide required env ${env} varible!`)
6+
}
7+
}
8+
}
9+
}

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const twilio = require('twilio')
2+
const helpers = require('./helpers')
3+
const types = require('./types')
4+
5+
helpers.envValid(['TWILIO_SID', 'TWILIO_TOKEN', 'TWILIO_PHONE_FROM', 'TWILIO_PHONE_TO'])
6+
7+
const client = twilio(process.env.TWILIO_SID, process.env.TWILIO_TOKEN)
8+
const type = process.env.TWILIO_TYPE || 'default'
9+
10+
helpers.envValid(types[type].env)
11+
message = types[type].message
12+
13+
client.messages
14+
.create({ from: process.env.TWILIO_PHONE_FROM, body: message, to: process.env.TWILIO_PHONE_TO })
15+
.then(message => console.log(message.sid))
16+
.catch(err => {
17+
throw err
18+
})
19+
.done()

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "twillo-plugin",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"twilio": "^3.25.0"
8+
},
9+
"scripts": {
10+
"start": "node ./index.js"
11+
}
12+
}

types/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const types = {
2+
build: {
3+
message: `New build is ready!\nRepo: ${process.env.CF_REPO_NAME}\nBranch: ${process.env.CF_BRANCH_VERSION_NORMALIZED}\nDetail info: ${process.env.CF_BUILD_URL}`,
4+
env: ['CF_REPO_NAME', 'CF_BRANCH_VERSION_NORMALIZED', 'CF_BUILD_URL']
5+
},
6+
default: {
7+
message: `Text: ${process.env.TWILIO_MESSAGE}`,
8+
env: ['TWILIO_MESSAGE']
9+
},
10+
}
11+
12+
module.exports = types

0 commit comments

Comments
 (0)