Skip to content

Commit

Permalink
refactor: implement error hierarchy for "from" and "to" parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Mar 30, 2022
1 parent 7bf4bac commit fa3dd68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions __tests__/unit/lib/utils/cliHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe(`test if the application`, () => {
})
expect.assertions(1)
await expect(cliHelper.validateConfig()).rejects.toThrow(
'--to is not a git expression'
`--to is blank: '${emptyString}'`
)
})

Expand All @@ -147,7 +147,7 @@ describe(`test if the application`, () => {
})
expect.assertions(1)
await expect(cliHelper.validateConfig()).rejects.toThrow(
'--from is not a git expression'
`--from is blank: '${emptyString}'`
)
})

Expand All @@ -161,7 +161,7 @@ describe(`test if the application`, () => {
})
expect.assertions(1)
await expect(cliHelper.validateConfig()).rejects.toThrow(
`--to ${notHeadSHA} is not a valid sha pointer`
`--to is not a valid sha pointer: '${notHeadSHA}'`
)
})

Expand All @@ -175,7 +175,7 @@ describe(`test if the application`, () => {
})
expect.assertions(1)
await expect(cliHelper.validateConfig()).rejects.toThrow(
`--from ${notHeadSHA} is not a valid sha pointer`
`--from is not a valid sha pointer: '${notHeadSHA}'`
)
})
})
32 changes: 16 additions & 16 deletions src/utils/cliHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ class CLIHelper {
async _validateGitSha() {
const errors = []
await Promise.all(
['to', 'from'].map(async field => {
if (isBlank(this.config[field])) {
errors.push(
`--${field} ${this.config[field]} is not a git expression`
)
}

const refType = await getStreamContent(
spawn('git', [...commitCheckParams, this.config[field]], {
cwd: this.config.repo,
})
['to', 'from']
.filter(
field =>
!isBlank(this.config[field]) ||
errors.push(`--${field} is blank: '${this.config[field]}'`)
)
if (refType?.replace(/\s/g, '') !== COMMIT_REF_TYPE) {
errors.push(
`--${field} ${this.config[field]} is not a valid sha pointer`
.map(async field => {
const refType = await getStreamContent(
spawn('git', [...commitCheckParams, this.config[field]], {
cwd: this.config.repo,
})
)
}
})
if (refType?.replace(/\s/g, '') !== COMMIT_REF_TYPE) {
errors.push(
`--${field} is not a valid sha pointer: '${this.config[field]}'`
)
}
})
)

return errors
Expand Down

0 comments on commit fa3dd68

Please sign in to comment.