Skip to content

Commit

Permalink
Introduce git_no_verify to bypass pre-commit and pre-push git hooks (
Browse files Browse the repository at this point in the history
…#279)

* add skip_verification

* Update action.yml

Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>

* propogate config flag suggestion

* add jsdoc

* Update README.md

Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>
  • Loading branch information
tomfuertes and ocean90 authored Aug 28, 2021
1 parent e528ced commit 466df2e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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: `"lint-action@samuelmeuli.com"`

- **`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

0 comments on commit 466df2e

Please sign in to comment.