@ -1,43 +1,43 @@
#!/usr/bin/env node
#!/usr/bin/env node
const slackup = require ( 'slackup' )
const slackup = require ( 'slackup' ) ;
const fetch = require ( 'node-fetch' )
const fetch = require ( 'node-fetch' ) ;
const repo = process . env . TRAVIS_REPO_SLUG
const repo = process . env . TRAVIS_REPO_SLUG ;
const commit = process . env . TRAVIS_COMMIT
const commit = process . env . TRAVIS_COMMIT ;
const branch = process . env . TRAVIS_BRANCH
const branch = process . env . TRAVIS_BRANCH ;
const apiKey = process . env . SLACK_API_KEY
const apiKey = process . env . SLACK_API_KEY ;
const channel = process . env . SLACK_CHANNEL
const channel = process . env . SLACK_CHANNEL ;
const githubToken = process . env . GITHUB_API_KEY
const githubToken = process . env . GITHUB_API_KEY ;
const currentNodeVersion = process . env . TRAVIS_NODE_VERSION
const currentNodeVersion = process . env . TRAVIS_NODE_VERSION ;
const regex = /^(node|7)\.*/
const regex = /^(node|7)\.*/ ;
// Skip if not on a zeit repo
// Skip if not on a zeit repo
if ( ! /^zeit\// . test ( repo ) ) {
if ( ! /^zeit\// . test ( repo ) ) {
console . log ( 'not a zeit repo' )
console . log ( 'not a zeit repo' ) ;
process . exit ( 0 )
process . exit ( 0 ) ;
}
}
if ( ! apiKey ) {
if ( ! apiKey ) {
console . log ( '$SLACKUP_TOKEN not found' )
console . log ( '$SLACKUP_TOKEN not found' ) ;
process . exit ( 0 )
process . exit ( 0 ) ;
}
}
if ( ! channel ) {
if ( ! channel ) {
console . log ( '$SLACKUP_CHANNEL not found' )
console . log ( '$SLACKUP_CHANNEL not found' ) ;
process . exit ( 0 )
process . exit ( 0 ) ;
}
}
if ( ! githubToken ) {
if ( ! githubToken ) {
console . log ( '$GITHUB_TOKEN not found' )
console . log ( '$GITHUB_TOKEN not found' ) ;
process . exit ( 0 )
process . exit ( 0 ) ;
}
}
const opts = {
const opts = {
headers : {
headers : {
authorization : ` token ${ githubToken } `
authorization : ` token ${ githubToken } `
}
}
}
} ;
fetch ( ` https://api.github.com/repos/ ${ repo } /commits/ ${ commit } ` , opts )
fetch ( ` https://api.github.com/repos/ ${ repo } /commits/ ${ commit } ` , opts )
. then ( res => res . json ( ) )
. then ( res => res . json ( ) )
@ -48,25 +48,25 @@ fetch(`https://api.github.com/repos/${repo}/commits/${commit}`, opts)
} ) )
} ) )
. then ( async res => {
. then ( async res => {
if ( regex . test ( currentNodeVersion ) ) {
if ( regex . test ( currentNodeVersion ) ) {
const message = ` :package: Here are the binaries for the branch * ${ branch } * of * ${ repo } * (commit <https://github.com/ ${ repo } /commit/ ${ commit } | ${ commit . substr ( 0 , 7 ) } > by < ${ res . authorUrl } | ${ res . authorName } >): `
const message = ` :package: Here are the binaries for the branch * ${ branch } * of * ${ repo } * (commit <https://github.com/ ${ repo } /commit/ ${ commit } | ${ commit . substr ( 0 , 7 ) } > by < ${ res . authorUrl } | ${ res . authorName } >): ` ;
const binaries = [
const binaries = [
` ${ __ dirname } /../../packed/now-macos ` ,
` ${ __ dirname } /../../packed/now-macos ` ,
` ${ __ dirname } /../../packed/now-linux ` ,
` ${ __ dirname } /../../packed/now-linux ` ,
` ${ __ dirname } /../../packed/now-win.exe `
` ${ __ dirname } /../../packed/now-win.exe `
]
] ;
try {
try {
await slackup ( { apiKey , channel , type : 'message' , message } )
await slackup ( { apiKey , channel , type : 'message' , message } ) ;
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 0 ] } )
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 0 ] } ) ;
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 1 ] } )
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 1 ] } ) ;
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 2 ] } )
await slackup ( { apiKey , channel , type : 'file' , filePath : binaries [ 2 ] } ) ;
} catch ( err ) {
} catch ( err ) {
console . log ( ` Couldn't send messages/files to Slack ` , err )
console . log ( ` Couldn't send messages/files to Slack ` , err ) ;
}
}
} else {
} else {
const message = ` :white_check_mark: Build succeded on Node ${ currentNodeVersion } (commit <https://github.com/ ${ repo } /commit/ ${ commit } | ${ commit . substr ( 0 , 7 ) } > by < ${ res . authorUrl } | ${ res . authorName } >) `
const message = ` :white_check_mark: Build succeded on Node ${ currentNodeVersion } (commit <https://github.com/ ${ repo } /commit/ ${ commit } | ${ commit . substr ( 0 , 7 ) } > by < ${ res . authorUrl } | ${ res . authorName } >) ` ;
await slackup ( { apiKey , channel , type : 'message' , message } )
await slackup ( { apiKey , channel , type : 'message' , message } ) ;
}
}
} )
} )
. catch ( console . error )
. catch ( console . error ) ;