From b23c0b615deee750c8d86ddcd69559cb2a815303 Mon Sep 17 00:00:00 2001 From: Patrik Date: Mon, 18 Jul 2022 15:39:46 +0200 Subject: [PATCH] feat: Config file support closes #161 --- README.md | 2 +- package.json | 2 +- src/parseConfig.js | 79 ++++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index e2ab8e72a..cdefc508e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ jobs: ## Configuration -The action works without configuration, however you can provide options for customization. +The action works without configuration, however you can provide options for customization. You can either use inputs to pass the configuration, or add a `.github/semantic.json` file to your repository. The action inputs will override the configuration file. Lists will be appended. The following terminology helps to understand the configuration options: diff --git a/package.json b/package.json index b4cc7cd0a..68b174966 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,6 @@ "semantic-release": "19.0.2" }, "engines": { - "node": "^16.0.0" + "node": "^18.0.0" } } diff --git a/src/parseConfig.js b/src/parseConfig.js index bbfa85aa4..01815dbf8 100644 --- a/src/parseConfig.js +++ b/src/parseConfig.js @@ -1,92 +1,89 @@ +const {readFileSync} = require('fs'); const ConfigParser = require('./ConfigParser'); module.exports = function parseConfig() { - let types; + const config = JSON.parse( + readFileSync('.github/semantic.json', {encoding: 'utf8'}) + ); + 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; };