From 8fccb6c8ce4d1c66fb5700bdb5b188b775c927f0 Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Mon, 6 Jan 2020 10:19:58 +0100 Subject: [PATCH] Add `commit_message` option Closes #8 --- README.md | 4 +++- action.yml | 4 ++++ src/index.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d58a3a09..67241df3 100644 --- a/README.md +++ b/README.md @@ -147,12 +147,14 @@ All linters are disabled by default. To enable a linter, simply set the option w - **`[linter]_extensions`:** Extensions of files to check with the linter. Example: `eslint_extensions: js,ts` to lint both JavaScript and TypeScript files with ESLint. Default: See [`action.yml`](./action.yml) - **`[linter]_dir`:** Directory where the linting command should be run. Example: `eslint_dir: server/` if ESLint is installed in the `server` subdirectory. Default: `.` -Besides the linter-specific options, there's a general `auto_fix` setting: +Besides the linter-specific options, there are a few global settings: - **`auto_fix`:** Whether linters should try to fix code style issues automatically. If some issues can be fixed, the action will commit and push the changes to the corresponding branch. Default: `false` Screenshot of auto-fix commit +- **`commit_message`**: Template for auto-fix commit messages. The `${linter}` variable can be used to insert the name of the linter which has created the auto-fix. Default: `Fix code style issues with ${linter}` + ## Development ### Contributing diff --git a/action.yml b/action.yml index adaeefdb..57f32e87 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: description: Whether linters should try to fix code style issues automatically required: false default: false + commit_message: + description: 'Template for auto-fix commit messages. The "${linter}" variable can be used to insert the name of the linter which has created the auto-fix' + required: false + default: "Fix code style issues with ${linter}" # CSS diff --git a/src/index.js b/src/index.js index e28e3a2b..8f42a036 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ process.on("unhandledRejection", err => { async function runAction() { const github = getGithubInfo(); const autoFix = getInput("auto_fix") === "true"; + const commitMsg = getInput("commit_message", true); setGitUserInfo(GIT_NAME, GIT_EMAIL); @@ -55,7 +56,7 @@ async function runAction() { const results = linter.lint(lintDirAbs, fileExtList, autoFix); if (autoFix) { log("Committing and pushing changes…"); - commitChanges(`Fix code style issues with ${linter.name}`); + commitChanges(commitMsg.replace(/\${linter}/g, linter.name)); pushChanges(github); } const resultsParsed = linter.parseResults(github.workspace, results);