From bd6d73ed7de2b73c9b6b6a4bb54e8f01fbc89c8a Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 12:36:49 -0500 Subject: [PATCH] Allow Empty Git Email Configs (#926) * Allow empty email * Update README.md * Update constants.ts * Allow email * unsets email * do not set * Adjusted --- README.md | 2 +- __tests__/util.test.ts | 20 ++++++++++++++++++++ src/constants.ts | 2 +- src/git.ts | 2 +- src/util.ts | 12 +++++++++--- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ee1e642e..572adff5 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ By default the action does not need any token configuration and uses the provide | Key | Value Information | Type | Required | | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | | `git-config-name` | Allows you to customize the name that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action. | `with` | **No** | -| `git-config-email` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. | `with` | **No** | +| `git-config-email` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. You can include an empty string value if you wish to omit this field altogether. | `with` | **No** | | `repository-name` | Allows you to specify a different repository path so long as you have permissions to push to it. This should be formatted like so: `JamesIves/github-pages-deploy-action`. You'll need to use a PAT in the `token` input for this configuration option to work properly. | `with` | **No** | | `target-folder` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | | `commit-message` | If you need to customize the commit message for an integration you can do so. | `with` | **No** | diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index fa5e1c6a..4d669187 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -31,6 +31,26 @@ describe('util', () => { const value = '' expect(isNullOrUndefined(value)).toBeTruthy() }) + + it('should return true if the value is null (with allowEmptyString)', async () => { + const value = null + expect(isNullOrUndefined(value, true)).toBeTruthy() + }) + + it('should return true if the value is undefined (with allowEmptyString)', async () => { + const value = undefined + expect(isNullOrUndefined(value, true)).toBeTruthy() + }) + + it('should return false if the value is defined (with allowEmptyString)', async () => { + const value = 'montezuma' + expect(isNullOrUndefined(value, true)).toBeFalsy() + }) + + it('should return false if the value is empty string (with allowEmptyString)', async () => { + const value = '' + expect(isNullOrUndefined(value, true)).toBeFalsy() + }) }) describe('generateTokenType', () => { diff --git a/src/constants.ts b/src/constants.ts index a2f682af..a55db101 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -95,7 +95,7 @@ export const action: ActionInterface = { ? stripProtocolFromUrl(process.env.GITHUB_SERVER_URL) : 'github.com', isTest: TestFlag.NONE, - email: !isNullOrUndefined(getInput('git-config-email')) + email: !isNullOrUndefined(getInput('git-config-email'), true) ? getInput('git-config-email') : pusher && pusher.email ? pusher.email diff --git a/src/git.ts b/src/git.ts index c91d3c29..cdf69761 100644 --- a/src/git.ts +++ b/src/git.ts @@ -22,7 +22,7 @@ export async function init(action: ActionInterface): Promise { action.silent ) await execute( - `git config user.email "${action.email}"`, + `git config user.email "${action.email ? action.email : '<>'}"`, action.workspace, action.silent ) diff --git a/src/util.ts b/src/util.ts index dba4a419..f9308761 100644 --- a/src/util.ts +++ b/src/util.ts @@ -7,9 +7,15 @@ import {ActionInterface, RequiredActionParameters} from './constants' const replaceAll = (input: string, find: string, replace: string): string => input.split(find).join(replace) -/* Utility function that checks to see if a value is undefined or not. */ -export const isNullOrUndefined = (value: unknown): boolean => - typeof value === 'undefined' || value === null || value === '' +/* Utility function that checks to see if a value is undefined or not. + If allowEmptyString is passed the parameter is allowed to contain an empty string as a valid parameter. */ +export const isNullOrUndefined = ( + value: unknown, + allowEmptyString = false +): boolean => + allowEmptyString + ? typeof value === 'undefined' || value === null + : typeof value === 'undefined' || value === null || value === '' /* Generates a token type used for the action. */ export const generateTokenType = (action: ActionInterface): string =>