Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto_commit input #438

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: `"[email protected]"`
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