-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add debug logs, set process.env.GK_LOCK_DEBUG =1 to enable
- Loading branch information
Showing
1 changed file
with
9 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const url = require('url') | |
const exec = require('child_process').execSync | ||
|
||
const _ = require('lodash') | ||
const DEBUG = process.env.GK_LOCK_DEBUG || false | ||
|
||
function setupRemote (info) { | ||
let remote = `[email protected]:${info.repoSlug}` | ||
|
@@ -56,28 +57,35 @@ module.exports = { | |
exec(`git stash`) | ||
exec(`git checkout ${defaultBranch}`) | ||
|
||
DEBUG && console.log('sucessfully funged the git repo, so we can diff this branch against the default branch') | ||
|
||
const reset = () => exec(`git checkout -`) | ||
|
||
try { | ||
const gitShowCmd = `git show --oneline --name-only origin/${info.branchName}...${defaultBranch}` | ||
const grepCmd = `grep -E '(package-lock.json|npm-shrinkwrap.json|yarn.lock)'` | ||
DEBUG && console.log(`about to run ${gitShowCmd} | ${grepCmd}`) | ||
exec(`${gitShowCmd} | ${grepCmd}`) | ||
} catch (e) { | ||
if (e.status === 1 && | ||
e.stdout.toString() === '' && | ||
e.stderr.toString() === '') { // grep didn’t find anything, and we are fine with that | ||
reset() | ||
DEBUG && console.log('grep found no matching commits: ') | ||
return false // no commits | ||
} else if (e.status > 1) { // git or grep errored | ||
reset() | ||
DEBUG && console.log('git or grep errored') | ||
throw e | ||
} else { | ||
// git succeeded, grep failed to match anything, but no error occured, e.g.: no commit yet | ||
// git succeeded, grep failed to match anything, but no error occured, i,e.: no commit yet | ||
DEBUG && console.log('git succeeded, grep failed to match anything, but no error occured, i.e.: no commit yet') | ||
reset() | ||
return false | ||
} | ||
} | ||
// git succeeded, grep found a match, we have a commit already | ||
DEBUG && console.log('git succeeded, grep foudn a match, we have a commit already') | ||
reset() | ||
return true | ||
}, | ||
|