Skip to content

Commit

Permalink
fix: amend comments, for reals now
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Jul 19, 2018
1 parent 92cd032 commit 7fc6069
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/git-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ const exec = require('child_process').execSync

const _ = require('lodash')

function setupRemote (info) {
let remote = `git@github.com:${info.repoSlug}`
if (info.gitUrl) remote = info.gitUrl

if (process.env.GH_TOKEN) {
if (remote.slice(0, 5) !== 'https') remote = `https://github.com/${info.repoSlug}`
const urlParsed = url.parse(remote)
urlParsed.auth = process.env.GH_TOKEN
remote = url.format(urlParsed)
}
exec(`git remote add gk-origin ${remote} || git remote set-url gk-origin ${remote}`)
}

module.exports = {
getNumberOfCommitsOnBranch: function getNumberOfCommitsOnBranch (branch) {
const refArgument = `$(git for-each-ref '--format=%(refname)' refs/ | grep /${branch} | head -1)`
Expand All @@ -29,6 +42,7 @@ module.exports = {
)
},
hasLockfileCommit: function hasLockfileCommit (info) {
setupRemote(info)
const defaultBranch = process.env.GK_LOCK_DEFAULT_BRANCH || 'master'
// CI clones are often shallow clones. Let’s make sure we have enough to work with
// https://stackoverflow.com/a/44036486/242298
Expand Down Expand Up @@ -77,17 +91,5 @@ module.exports = {
return branch
? branch.match(/^origin\/(.+)/)[1]
: exec('git rev-parse --abbrev-ref HEAD').toString().trim()
},
setupRemote: function getRemote (info) {
let remote = `git@github.com:${info.repoSlug}`
if (info.gitUrl) remote = info.gitUrl

if (process.env.GH_TOKEN) {
if (remote.slice(0, 5) !== 'https') remote = `https://github.com/${info.repoSlug}`
const urlParsed = url.parse(remote)
urlParsed.auth = process.env.GH_TOKEN
remote = url.format(urlParsed)
}
exec(`git remote add gk-origin ${remote} || git remote set-url gk-origin ${remote}`)
}
}
8 changes: 8 additions & 0 deletions test/__snapshots__/update.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`monorepo: no package.json 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand All @@ -13,6 +14,7 @@ Array [

exports[`monorepo: no root and one sub package 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand All @@ -38,6 +40,7 @@ https://npm.im/greenkeeper-lockfile\\"",

exports[`monorepo: no root and two sub package 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down Expand Up @@ -70,6 +73,7 @@ https://npm.im/greenkeeper-lockfile\\"",

exports[`monorepo: no root and two sub package at different levels 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down Expand Up @@ -102,6 +106,7 @@ https://npm.im/greenkeeper-lockfile\\"",

exports[`monorepo: root and one sub package 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down Expand Up @@ -134,6 +139,7 @@ https://npm.im/greenkeeper-lockfile\\"",

exports[`monorepo: root and two sub package 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down Expand Up @@ -173,6 +179,7 @@ https://npm.im/greenkeeper-lockfile\\"",

exports[`monorepo: root and two sub package at different levels 1`] = `
Array [
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down Expand Up @@ -214,6 +221,7 @@ exports[`monorepo: root package 1`] = `
Array [
"git config remote.origin.url",
"git config remote.origin.url",
"git remote add gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git || git remote set-url gk-origin git@github.com:greenkeeperio/greenkeeper-lockfile.git",
"git config --replace-all remote.origin.fetch +refs/heads/*:refs/remotes/origin/*",
"git fetch gk-origin",
"git stash",
Expand Down
11 changes: 11 additions & 0 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ function testFixture (fixtureDirectory, noLog) {
if (!noLog) exec.withArgs(`git show --oneline --name-only origin/greenkeeper/my-dependency-1.0.0...master | grep -E '(package-lock.json|npm-shrinkwrap.json|yarn.lock)'`).throws({status: 1, stdout: '', stderr: ''})

process.chdir(path.join(__dirname, fixtureDirectory))

let oldGhToken = false
if (process.env.GH_TOKEN) {
oldGhToken = process.env.GH_TOKEN
delete process.env.GH_TOKEN
}

update()

if (oldGhToken) {
process.env.GH_TOKEN = oldGhToken
}

expect(exec.getCalls().map(call => call.args[0])).toMatchSnapshot()
}

Expand Down

0 comments on commit 7fc6069

Please sign in to comment.