diff --git a/README.md b/README.md index 3f8b5733..d877a080 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,10 @@ jobs: Screenshot of auto-fix commit

+- **`git_name`**: Username for auto-fix commits. Default: `"Lint Action"` + +- **`git_email`**: Email address for auto-fix commits. Default: `"lint-action@samuelmeuli.com"` + - **`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}"` ## Limitations diff --git a/action.yml b/action.yml index 9a375fbc..315ac095 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,14 @@ inputs: description: Whether linters should try to fix code style issues automatically required: false default: false + git_name: + description: Username for auto-fix commits + required: false + default: Lint Action + git_email: + description: Email address for auto-fix commits + required: false + default: "lint-action@samuelmeuli.com" 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 diff --git a/src/git.js b/src/git.js index 2773d1d0..64ca573a 100644 --- a/src/git.js +++ b/src/git.js @@ -69,7 +69,7 @@ function pushChanges() { /** * Updates the global Git configuration with the provided information - * @param {string} name - Git user name + * @param {string} name - Git username * @param {string} email - Git email address */ function setUserInfo(name, email) { diff --git a/src/index.js b/src/index.js index c782a460..c15c8f90 100644 --- a/src/index.js +++ b/src/index.js @@ -7,9 +7,6 @@ const linters = require("./linters"); const { getInput, log } = require("./utils/action"); const { getSummary } = require("./utils/lint-result"); -const GIT_EMAIL = "lint-action@samuelmeuli.com"; -const GIT_NAME = "Lint Action"; - // Abort action on unhandled promise rejections process.on("unhandledRejection", (err) => { log(err, "error"); @@ -22,7 +19,9 @@ process.on("unhandledRejection", (err) => { async function runAction() { const context = getContext(); const autoFix = getInput("auto_fix") === "true"; - const commitMsg = getInput("commit_message", true); + const gitName = getInput("git_name", true); + const gitEmail = getInput("git_email", true); + const commitMessage = getInput("commit_message", true); // If on a PR from fork: Display messages regarding action limitations if (context.eventName === "pull_request" && context.repository.hasFork) { @@ -40,7 +39,7 @@ async function runAction() { if (autoFix) { // Set Git committer username and password - git.setUserInfo(GIT_NAME, GIT_EMAIL); + git.setUserInfo(gitName, gitEmail); } if (context.eventName === "pull_request") { // Fetch and check out PR branch: @@ -90,7 +89,7 @@ async function runAction() { if (autoFix) { // Commit and push auto-fix changes if (git.hasChanges()) { - git.commitChanges(commitMsg.replace(/\${linter}/g, linter.name)); + git.commitChanges(commitMessage.replace(/\${linter}/g, linter.name)); git.pushChanges(); } }