Allow Empty Git Email Configs (#926)

* Allow empty email

* Update README.md

* Update constants.ts

* Allow email

* unsets email

* do not set

* Adjusted
This commit is contained in:
James Ives 2021-11-17 12:36:49 -05:00 committed by GitHub
parent 1d77ee006d
commit bd6d73ed7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 6 deletions

View File

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

View File

@ -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', () => {

View File

@ -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

View File

@ -22,7 +22,7 @@ export async function init(action: ActionInterface): Promise<void | Error> {
action.silent
)
await execute(
`git config user.email "${action.email}"`,
`git config user.email "${action.email ? action.email : '<>'}"`,
action.workspace,
action.silent
)

View File

@ -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 =>