Skip to content

Commit

Permalink
feat: 'from' and 'to' will be verified to be valid git commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Abakumov authored and Abakumov committed Feb 22, 2022
1 parent 76cc459 commit 7d8f07c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const XML_FILE_EXTENSION = 'xml'

module.exports = config => {
const cliHelper = new CLIHelper(config)
cliHelper.validateGitSha()
cliHelper.validateConfig()

const metadata = metadataManager.getDefinition(
Expand Down
21 changes: 21 additions & 0 deletions src/utils/cliHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@ const git = require('git-state')
const dirExist = dir => fs.existsSync(dir) && fs.statSync(dir).isDirectory()
const fileExist = file => fs.statSync(file).isFile()

const commitCheckParams = ['cat-file', 'commit']
const childProcess = require('child_process')

class CLIHelper {
constructor(config) {
this.config = config
this.repoSetup = new RepoSetup(config)
}

validateGitSha() {
const errors = []
;['to', 'from'].forEach(field => {
const { status } = childProcess.spawnSync(
'git',
[...commitCheckParams, this.config[field]],
{ cwd: this.config.repo }
)
if (status != 0) {
errors.push(`${field} ${this.config[field]} is not a valid commit`)
}
})

if (errors.length > 0) {
throw new Error(errors.join(', '))
}
}

validateConfig() {
this._sanitizeConfig()
const errors = []
Expand Down

0 comments on commit 7d8f07c

Please sign in to comment.