Skip to content

Commit

Permalink
Add commit_message option
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
samuelmeuli committed Jan 6, 2020
1 parent ecf085d commit 8fccb6c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<img src="./.github/screenshots/auto-fix.png" alt="Screenshot of auto-fix commit" width="75%" />

- **`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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8fccb6c

Please sign in to comment.