Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Empty Git Email Configs #926

Merged
merged 7 commits into from Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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** |
Expand Down
20 changes: 20 additions & 0 deletions __tests__/util.test.ts
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts
Expand Up @@ -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
)
Expand Down
12 changes: 9 additions & 3 deletions src/util.ts
Expand Up @@ -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 =>
Expand Down