Skip to content

Commit

Permalink
feat: fall back to ssh key git access (#29)
Browse files Browse the repository at this point in the history
* Fall back to ssh key git access
On Travis, the environment is automatically equipped with a deploy key. By default, the deploy key is [read-write](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys), so this might work out of the box. Users always have the option of creating separate users and managing keys with user keys.
  • Loading branch information
skeggse authored and christophwitzko committed Jun 7, 2017
1 parent 590bc5f commit 1e989ef
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const info = require('./ci-services')()
const env = process.env

module.exports = function upload () {
if (!env.GH_TOKEN) {
throw new Error('Please provide a GitHub token as "GH_TOKEN" environment variable')
}

if (!info.branchName.startsWith(config.branchPrefix)) {
return console.error('Not a Greenkeeper branch')
}
Expand All @@ -28,7 +24,14 @@ module.exports = function upload () {
return console.error('Only uploading on one build job')
}

exec(`git remote add gk-origin https://${env.GH_TOKEN}@github.com/${info.repoSlug}`)
if (env.GH_TOKEN) {
// Use the GH_TOKEN if provided.
exec(`git remote add gk-origin https://${env.GH_TOKEN}@github.com/${info.repoSlug}`)
} else {
// Otherwise, assume an SSH key is available.
exec(`git remote add gk-origin git@github.com:${info.repoSlug}`)
}

exec(`git push gk-origin HEAD:${info.branchName}`)
}

Expand Down

0 comments on commit 1e989ef

Please sign in to comment.