mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
fix: error out when projectOwner & projectName is not set in .all-contributorsrc file. (#80)
* error message when no project name and project owner is added in the init command * moved error message away from init prompt * 1. placed json parse in try catch 2. added check for owner and name in getcontributionsfromgithub before constructing url * added check before config file is written * changes as per https://github.com/jfmengels/all-contributors-cli/pull/80#pullrequestreview-85678121 * uncommented code * tests added * Added myself to contributors table * test inside utils were moved to github in master branch * changes to validation check, instead of checking for empty string to null obj value * typo fixed * unnecisary check.js file removed
This commit is contained in:
parent
1562a379db
commit
c4a0484759
3 changed files with 40 additions and 4 deletions
|
@ -180,7 +180,9 @@
|
|||
"profile": "https://in.linkedin.com/in/mzubairahmed",
|
||||
"contributions": [
|
||||
"doc",
|
||||
"bug"
|
||||
"bug",
|
||||
"code",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,15 +1,43 @@
|
|||
import configFile from '../config-file'
|
||||
|
||||
const absentFile = './abc'
|
||||
const expected = `Configuration file not found: ${absentFile}`
|
||||
const absentConfileFileExpected = `Configuration file not found: ${absentFile}`
|
||||
const incompleteConfigFilePath = './.all-contributorsrc'
|
||||
const NoOwnerConfigFile = {
|
||||
projectOwner: '',
|
||||
projectName: 'all-contributors-cli',
|
||||
imageSize: 100,
|
||||
commit: false,
|
||||
contributorsPerLine: 6,
|
||||
contributors: [],
|
||||
}
|
||||
const NoNameConfigFile = {
|
||||
projectOwner: 'jfmengels',
|
||||
projectName: '',
|
||||
imageSize: 100,
|
||||
commit: false,
|
||||
contributorsPerLine: 6,
|
||||
contributors: [],
|
||||
}
|
||||
|
||||
test('Reading an absent configuration file throws a helpful error', () => {
|
||||
expect(() => configFile.readConfig(absentFile)).toThrowError(expected)
|
||||
expect(() => configFile.readConfig(absentFile)).toThrowError(
|
||||
absentConfileFileExpected,
|
||||
)
|
||||
})
|
||||
|
||||
test('Writing contributors in an absent configuration file throws a helpful error', async () => {
|
||||
const resolvedError = await configFile
|
||||
.writeContributors(absentFile, [])
|
||||
.catch(e => e)
|
||||
expect(resolvedError.message).toBe(expected)
|
||||
expect(resolvedError.message).toBe(absentConfileFileExpected)
|
||||
})
|
||||
|
||||
test('Should throw error and not allow editing config file if project name or owner is not set', () => {
|
||||
expect(() =>
|
||||
configFile.writeConfig(incompleteConfigFilePath, NoOwnerConfigFile),
|
||||
).toThrow(`Error! Project owner is not set in ${incompleteConfigFilePath}`)
|
||||
expect(() =>
|
||||
configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile),
|
||||
).toThrow(`Error! Project name is not set in ${incompleteConfigFilePath}`)
|
||||
})
|
||||
|
|
|
@ -18,6 +18,12 @@ function readConfig(configPath) {
|
|||
}
|
||||
|
||||
function writeConfig(configPath, content) {
|
||||
if (!content.projectOwner) {
|
||||
throw new Error(`Error! Project owner is not set in ${configPath}`)
|
||||
}
|
||||
if (!content.projectName) {
|
||||
throw new Error(`Error! Project name is not set in ${configPath}`)
|
||||
}
|
||||
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue