1 | _ = require 'lodash'
|
2 | path = require 'path'
|
3 | url = require 'url'
|
4 | yaml = require 'node-yaml'
|
5 | debug = require('debug')('deploy-state-util:travis-service')
|
6 |
|
7 | class TravisService
|
8 | constructor: ({ config }) ->
|
9 | throw new Error 'Missing config argument' unless config?
|
10 | @travisYml = path.join process.cwd(), '.travis.yml'
|
11 | @webhookUrl = url.format {
|
12 | hostname: config['deploy-state'].hostname,
|
13 | protocol: 'https',
|
14 | slashes: true,
|
15 | pathname: '/deployments/travis-ci'
|
16 | }
|
17 |
|
18 | configure: ({ isPrivate }, callback) =>
|
19 | yaml.read @travisYml, (error, data) =>
|
20 | return callback error if error?
|
21 | type = 'com' if isPrivate
|
22 | type ?= 'org'
|
23 | _.set data, 'notifications.webhooks', "#{@webhookUrl}/#{type}"
|
24 | yaml.write @travisYml, data, callback
|
25 |
|
26 | module.exports = TravisService
|