-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde9529
commit 1563df5
Showing
4 changed files
with
84 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const inquirer = require('inquirer'); | ||
const { readdir } = require('fs'); | ||
const { promisify } = require('util'); | ||
const { spawn, exec } = require('child_process'); | ||
const { spinner } = require('../../utils/spinner'); | ||
const { logger } = require('../../utils/logger'); | ||
const { hasGit } = require('../../utils/hasGit'); | ||
|
||
const readDirAsync = promisify(readdir); | ||
|
||
const getShas = () => new Promise((resolve) => { | ||
const gitLog = exec('git log --format=format:%H'); | ||
gitLog.stdout.on('data', (data) => { | ||
resolve(data.split('\n').filter(x => x !== '')); | ||
}); | ||
}); | ||
|
||
const review = async({ userId }) => { | ||
const currentWorkingDir = process.cwd(); | ||
const files = await readDirAsync(currentWorkingDir); | ||
const itHasGit = hasGit(files); | ||
if (itHasGit) { | ||
const shas = await getShas(); | ||
const choices = ['HEAD^', ...shas]; | ||
const { sha = 'HEAD^' } = inquirer.prompt([{ | ||
name: 'sha', | ||
message: 'From which commit do you want to review?', | ||
type: 'list', | ||
default: 'HEAD^', | ||
choices | ||
}]); | ||
|
||
spinner.start(); | ||
const reset = spawn('git', ['reset', sha]); | ||
reset.on('close', (code) => spinner.stop()); | ||
} else { | ||
spinner.stop(); | ||
logger.log('No git'); | ||
} | ||
|
||
// return process.exit(0); | ||
}; | ||
|
||
module.exports = { | ||
review | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { find, isNil } = require('ramda'); | ||
|
||
const hasGit = files => !isNil(find(f => f === '.git', files)); | ||
|
||
module.exports = { | ||
hasGit | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { hasGit } = require('./index'); | ||
|
||
describe('utils/hasGit', () => { | ||
test('it has git', async() => { | ||
const files = [ | ||
'pizza', | ||
'kebab', | ||
'sushi', | ||
'.git' | ||
]; | ||
|
||
const itHasGit = await hasGit(files); | ||
expect(itHasGit).toBe(true); | ||
}); | ||
test('it doesn\'t has git', async() => { | ||
const files = [ | ||
'pizza', | ||
'kebab', | ||
'sushi' | ||
]; | ||
|
||
const itHasGit = await hasGit(files); | ||
expect(itHasGit).toBe(false); | ||
}); | ||
}); |