forked from amannn/action-semantic-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes amannn#161
- Loading branch information
Showing
2 changed files
with
50 additions
and
42 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 |
---|---|---|
@@ -1,92 +1,100 @@ | ||
const {readFileSync} = require('fs'); | ||
const ConfigParser = require('./ConfigParser'); | ||
|
||
module.exports = function parseConfig() { | ||
let types; | ||
let config = {}; | ||
try { | ||
config = JSON.parse( | ||
readFileSync('.github/semantic.json', {encoding: 'utf8'}) | ||
); | ||
} catch (error) { | ||
if (error instanceof SyntaxError) { | ||
throw new Error( | ||
'The semantic.json file is not valid JSON. Please fix the syntax errors: ' + | ||
error.message | ||
); | ||
} | ||
// skipping if the file doesn't exist | ||
} | ||
|
||
if (process.env.INPUT_TYPES) { | ||
types = ConfigParser.parseEnum(process.env.INPUT_TYPES); | ||
config.types = [ | ||
...config.types, | ||
...ConfigParser.parseEnum(process.env.INPUT_TYPES) | ||
]; | ||
} | ||
|
||
let scopes; | ||
if (process.env.INPUT_SCOPES) { | ||
scopes = ConfigParser.parseEnum(process.env.INPUT_SCOPES); | ||
config.scopes = [ | ||
...config.scopes, | ||
...ConfigParser.parseEnum(process.env.INPUT_SCOPES) | ||
]; | ||
} | ||
|
||
let requireScope; | ||
if (process.env.INPUT_REQUIRESCOPE) { | ||
requireScope = ConfigParser.parseBoolean(process.env.INPUT_REQUIRESCOPE); | ||
config.requireScope = ConfigParser.parseBoolean( | ||
process.env.INPUT_REQUIRESCOPE | ||
); | ||
} | ||
|
||
let disallowScopes; | ||
if (process.env.INPUT_DISALLOWSCOPES) { | ||
disallowScopes = ConfigParser.parseEnum(process.env.INPUT_DISALLOWSCOPES); | ||
config.disallowScopes = [ | ||
...config.disallowScopes, | ||
...ConfigParser.parseEnum(process.env.INPUT_DISALLOWSCOPES) | ||
]; | ||
} | ||
|
||
let subjectPattern; | ||
if (process.env.INPUT_SUBJECTPATTERN) { | ||
subjectPattern = ConfigParser.parseString(process.env.INPUT_SUBJECTPATTERN); | ||
config.subjectPattern = ConfigParser.parseString( | ||
process.env.INPUT_SUBJECTPATTERN | ||
); | ||
} | ||
|
||
let subjectPatternError; | ||
if (process.env.INPUT_SUBJECTPATTERNERROR) { | ||
subjectPatternError = ConfigParser.parseString( | ||
config.subjectPatternError = ConfigParser.parseString( | ||
process.env.INPUT_SUBJECTPATTERNERROR | ||
); | ||
} | ||
|
||
let headerPattern; | ||
if (process.env.INPUT_HEADERPATTERN) { | ||
headerPattern = ConfigParser.parseString(process.env.INPUT_HEADERPATTERN); | ||
config.headerPattern = ConfigParser.parseString( | ||
process.env.INPUT_HEADERPATTERN | ||
); | ||
} | ||
|
||
let headerPatternCorrespondence; | ||
if (process.env.INPUT_HEADERPATTERNCORRESPONDENCE) { | ||
headerPatternCorrespondence = ConfigParser.parseString( | ||
config.headerPatternCorrespondence = ConfigParser.parseString( | ||
process.env.INPUT_HEADERPATTERNCORRESPONDENCE | ||
); | ||
} | ||
|
||
let wip; | ||
if (process.env.INPUT_WIP) { | ||
wip = ConfigParser.parseBoolean(process.env.INPUT_WIP); | ||
config.wip = ConfigParser.parseBoolean(process.env.INPUT_WIP); | ||
} | ||
|
||
let validateSingleCommit; | ||
if (process.env.INPUT_VALIDATESINGLECOMMIT) { | ||
validateSingleCommit = ConfigParser.parseBoolean( | ||
config.validateSingleCommit = ConfigParser.parseBoolean( | ||
process.env.INPUT_VALIDATESINGLECOMMIT | ||
); | ||
} | ||
|
||
let validateSingleCommitMatchesPrTitle; | ||
if (process.env.INPUT_VALIDATESINGLECOMMITMATCHESPRTITLE) { | ||
validateSingleCommitMatchesPrTitle = ConfigParser.parseBoolean( | ||
config.validateSingleCommitMatchesPrTitle = ConfigParser.parseBoolean( | ||
process.env.INPUT_VALIDATESINGLECOMMITMATCHESPRTITLE | ||
); | ||
} | ||
|
||
let githubBaseUrl; | ||
if (process.env.INPUT_GITHUBBASEURL) { | ||
githubBaseUrl = ConfigParser.parseString(process.env.INPUT_GITHUBBASEURL); | ||
config.githubBaseUrl = ConfigParser.parseString( | ||
process.env.INPUT_GITHUBBASEURL | ||
); | ||
} | ||
|
||
let ignoreLabels; | ||
if (process.env.INPUT_IGNORELABELS) { | ||
ignoreLabels = ConfigParser.parseEnum(process.env.INPUT_IGNORELABELS); | ||
config.ignoreLabels = ConfigParser.parseEnum( | ||
process.env.INPUT_IGNORELABELS | ||
); | ||
} | ||
|
||
return { | ||
types, | ||
scopes, | ||
requireScope, | ||
disallowScopes, | ||
wip, | ||
subjectPattern, | ||
subjectPatternError, | ||
headerPattern, | ||
headerPatternCorrespondence, | ||
validateSingleCommit, | ||
validateSingleCommitMatchesPrTitle, | ||
githubBaseUrl, | ||
ignoreLabels | ||
}; | ||
return config; | ||
}; |