UNPKG

827 Btext/coffeescriptView Raw
1_ = require 'lodash'
2path = require 'path'
3url = require 'url'
4yaml = require 'node-yaml'
5debug = require('debug')('deploy-state-util:travis-service')
6
7class 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
26module.exports = TravisService