Skip to content

Commit

Permalink
Add git_name and git_email options
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
samuelmeuli committed May 2, 2020
1 parent c6935ca commit ad6ad48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ jobs:
<img src="./.github/screenshots/auto-fix.png" alt="Screenshot of auto-fix commit" width="80%" />
</p>

- **`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
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand All @@ -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:
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit ad6ad48

Please sign in to comment.