From 4dde0e6bd981a979db55b1273273ba8b7628d060 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 09:16:20 -0500 Subject: [PATCH 1/7] Allow empty email --- __tests__/util.test.ts | 20 ++++++++++++++++++++ src/constants.ts | 4 ++-- src/util.ts | 12 +++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index fa5e1c6ab..4d669187e 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 a2f682af6..28d84df70 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 @@ -106,7 +106,7 @@ export const action: ActionInterface = { ? stripProtocolFromUrl(process.env.GITHUB_SERVER_URL) : 'github.com' }`, - name: !isNullOrUndefined(getInput('git-config-name')) + name: !isNullOrUndefined(getInput('git-config-name'), true) ? getInput('git-config-name') : pusher && pusher.name ? pusher.name diff --git a/src/util.ts b/src/util.ts index dba4a4193..f93087613 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 => From dc15f3fa05ae96b7e9d16f6ed7949f97c1049961 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 09:17:03 -0500 Subject: [PATCH 2/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ee1e642e9..571a79e93 100644 --- a/README.md +++ b/README.md @@ -136,8 +136,8 @@ 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-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. You can include an empty string value if you wish to omit this field altogether. | `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** | From 25bb5a5b481877092f3d98e270ab3625ba3e6ef1 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 09:23:55 -0500 Subject: [PATCH 3/7] Update constants.ts --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 28d84df70..a55db1013 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -106,7 +106,7 @@ export const action: ActionInterface = { ? stripProtocolFromUrl(process.env.GITHUB_SERVER_URL) : 'github.com' }`, - name: !isNullOrUndefined(getInput('git-config-name'), true) + name: !isNullOrUndefined(getInput('git-config-name')) ? getInput('git-config-name') : pusher && pusher.name ? pusher.name From aa4947a958833971db40726c0104aa175cc1925f Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 09:30:16 -0500 Subject: [PATCH 4/7] Allow email --- README.md | 2 +- src/git.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 571a79e93..572adff5b 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,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. You can include an empty string value if you wish to omit this field altogether. | `with` | **No** | +| `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. 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** | diff --git a/src/git.ts b/src/git.ts index c91d3c296..cdf697610 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 ) From 9f732a41a03895dffc6208b27f9fa9e74ab8875c Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 09:58:06 -0500 Subject: [PATCH 5/7] unsets email --- __tests__/git.test.ts | 20 ++++++++++++++++++++ src/git.ts | 20 +++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 69e9bfac5..5824a29ed 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -58,6 +58,26 @@ describe('git', () => { expect(execute).toBeCalledTimes(5) }) + it('should unset email if it does not exist', async () => { + Object.assign(action, { + hostname: 'github.com', + silent: false, + email: '', + repositoryPath: 'JamesIves/github-pages-deploy-action', + token: '123', + branch: 'branch', + folder: '.', + pusher: { + name: 'asd', + email: 'as@cat' + }, + isTest: TestFlag.HAS_CHANGED_FILES + }) + + await init(action) + expect(execute).toBeCalledTimes(5) + }) + it('should catch when a function throws an error', async () => { ;(execute as jest.Mock).mockImplementationOnce(() => { throw new Error('Mocked throw') diff --git a/src/git.ts b/src/git.ts index cdf697610..e144c3223 100644 --- a/src/git.ts +++ b/src/git.ts @@ -21,11 +21,21 @@ export async function init(action: ActionInterface): Promise { action.workspace, action.silent ) - await execute( - `git config user.email "${action.email ? action.email : '<>'}"`, - action.workspace, - action.silent - ) + + if (action.email) { + await execute( + `git config user.email "${action.email}"`, + action.workspace, + action.silent + ) + } else { + /* If a user specifies that they don't want their email displayed, unset it from the config. */ + await execute( + `git config --unset user.email`, + action.workspace, + action.silent + ) + } try { if ((process.env.CI && !action.sshKey) || action.isTest) { From 0519bc5ed59609ca38c9c9558896fcf17bb97c8a Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 10:01:27 -0500 Subject: [PATCH 6/7] do not set --- __tests__/git.test.ts | 2 +- src/git.ts | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 5824a29ed..b08f5838a 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -75,7 +75,7 @@ describe('git', () => { }) await init(action) - expect(execute).toBeCalledTimes(5) + expect(execute).toBeCalledTimes(4) }) it('should catch when a function throws an error', async () => { diff --git a/src/git.ts b/src/git.ts index e144c3223..0483f3c14 100644 --- a/src/git.ts +++ b/src/git.ts @@ -28,13 +28,6 @@ export async function init(action: ActionInterface): Promise { action.workspace, action.silent ) - } else { - /* If a user specifies that they don't want their email displayed, unset it from the config. */ - await execute( - `git config --unset user.email`, - action.workspace, - action.silent - ) } try { From b3928a901682998531cb6673f16cc354ff8d69db Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 17 Nov 2021 10:09:46 -0500 Subject: [PATCH 7/7] Adjusted --- __tests__/git.test.ts | 20 -------------------- src/git.ts | 13 +++++-------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index b08f5838a..69e9bfac5 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -58,26 +58,6 @@ describe('git', () => { expect(execute).toBeCalledTimes(5) }) - it('should unset email if it does not exist', async () => { - Object.assign(action, { - hostname: 'github.com', - silent: false, - email: '', - repositoryPath: 'JamesIves/github-pages-deploy-action', - token: '123', - branch: 'branch', - folder: '.', - pusher: { - name: 'asd', - email: 'as@cat' - }, - isTest: TestFlag.HAS_CHANGED_FILES - }) - - await init(action) - expect(execute).toBeCalledTimes(4) - }) - it('should catch when a function throws an error', async () => { ;(execute as jest.Mock).mockImplementationOnce(() => { throw new Error('Mocked throw') diff --git a/src/git.ts b/src/git.ts index 0483f3c14..cdf697610 100644 --- a/src/git.ts +++ b/src/git.ts @@ -21,14 +21,11 @@ export async function init(action: ActionInterface): Promise { action.workspace, action.silent ) - - if (action.email) { - await execute( - `git config user.email "${action.email}"`, - action.workspace, - action.silent - ) - } + await execute( + `git config user.email "${action.email ? action.email : '<>'}"`, + action.workspace, + action.silent + ) try { if ((process.env.CI && !action.sshKey) || action.isTest) {