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 git_no_verify flag for potential hook issue #279

Merged
merged 5 commits into from
Aug 28, 2021
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ jobs:

- **`git_email`**: Email address for auto-fix commits. Default: `"[email protected]"`

- **`git_no_verify`**: Bypass the pre-commit and pre-push git hooks. Default: `false`

- **`commit_message`**: Template for auto-fix commit messages. The `${linter}` variable can be used to insert the name of the linter. Default: `"Fix code style issues with ${linter}"`

- **`check_name`**: Template for the [name of the check run](https://docs.github.com/en/rest/reference/checks#create-a-check-run). Use this to ensure unique names when the action is used more than once in a workflow. The `${linter}` and `${dir}` variables can be used to insert the name and directory of the linter. Default: `"${linter}"`
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"
git_no_verify:
description: Bypass the pre-commit and pre-push git hooks
required: false
default: "false"
git_name:
description: Username for auto-fix commits
required: false
Expand Down
10 changes: 6 additions & 4 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ function checkOutRemoteBranch(context) {
/**
* Stages and commits all changes using Git
* @param {string} message - Git commit message
* @param {boolean} skipVerification - Skip Git verification
*/
function commitChanges(message) {
function commitChanges(message, skipVerification) {
core.info(`Committing changes`);
run(`git commit -am "${message}"`);
run(`git commit -am "${message}"${skipVerification ? " --no-verify" : ""}`);
}

/**
Expand All @@ -67,10 +68,11 @@ function hasChanges() {

/**
* Pushes all changes to the remote repository
* @param {boolean} skipVerification - Skip Git verification
*/
function pushChanges() {
function pushChanges(skipVerification) {
core.info("Pushing changes with Git");
run("git push");
run(`git push${skipVerification ? " --no-verify" : ""}`);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions 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 skipVerification = core.getInput("git_no_verify") === "true";
const continueOnError = core.getInput("continue_on_error") === "true";
const gitName = core.getInput("git_name", { required: true });
const gitEmail = core.getInput("git_email", { required: true });
Expand Down Expand Up @@ -98,8 +99,8 @@ async function runAction() {
if (autoFix) {
// Commit and push auto-fix changes
if (git.hasChanges()) {
git.commitChanges(commitMessage.replace(/\${linter}/g, linter.name));
git.pushChanges();
git.commitChanges(commitMessage.replace(/\${linter}/g, linter.name), skipVerification);
git.pushChanges(skipVerification);
}
}

Expand Down