Skip to content

Commit

Permalink
Add commit input to prevent commits when auto_fix is enabled (#438)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>
  • Loading branch information
Gismo359 and ocean90 authored Apr 14, 2022
1 parent afd9a54 commit fb64e3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,14 @@ jobs:

- **`continue_on_error`:** Whether the workflow run should also fail when linter failures are detected. Default: `true`

- **`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`
- **`auto_fix`:** Whether linters should try to fix code style issues automatically. If some issues can be fixed, the action will apply the needed changes. Default: `false`

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

- **`commit`:** Whether to commit and push the changes made by `auto_fix`. Default: `true`

- **`git_name`**: Username for auto-fix commits. Default: `"Lint Action"`

- **`git_email`**: Email address for auto-fix commits. Default: `"lint-action@samuelmeuli.com"`
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ inputs:
description: Whether linters should try to fix code style issues automatically
required: false
default: "false"
commit:
description: Whether to commit and push the changes made by auto_fix
required: false
default: "true"
git_no_verify:
description: Bypass the pre-commit and pre-push git hooks
required: false
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,7 @@ const { getSummary } = __nccwpck_require__(9149);
async function runAction() {
const context = getContext();
const autoFix = core.getInput("auto_fix") === "true";
const commit = core.getInput("commit") === "true";
const skipVerification = core.getInput("git_no_verify") === "true";
const continueOnError = core.getInput("continue_on_error") === "true";
const gitName = core.getInput("git_name", { required: true });
Expand Down Expand Up @@ -4400,7 +4401,7 @@ async function runAction() {
hasFailures = true;
}

if (autoFix) {
if (autoFix && commit) {
// Commit and push auto-fix changes
if (git.hasChanges()) {
git.commitChanges(commitMessage.replace(/\${linter}/g, linter.name), skipVerification);
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { getSummary } = require("./utils/lint-result");
async function runAction() {
const context = getContext();
const autoFix = core.getInput("auto_fix") === "true";
const commit = core.getInput("commit") === "true";
const skipVerification = core.getInput("git_no_verify") === "true";
const continueOnError = core.getInput("continue_on_error") === "true";
const gitName = core.getInput("git_name", { required: true });
Expand Down Expand Up @@ -97,7 +98,7 @@ async function runAction() {
hasFailures = true;
}

if (autoFix) {
if (autoFix && commit) {
// Commit and push auto-fix changes
if (git.hasChanges()) {
git.commitChanges(commitMessage.replace(/\${linter}/g, linter.name), skipVerification);
Expand Down

0 comments on commit fb64e3a

Please sign in to comment.