8000 Allow Empty Git Email Configs (#926) · Wulf/github-pages-deploy-action@bd6d73e · GitHub
[go: up one dir, main page]

Skip to content

Commit bd6d73e

Browse files
authored
Allow Empty Git Email Configs (JamesIves#926)
* Allow empty email * Update README.md * Update constants.ts * Allow email * unsets email * do not set * Adjusted
1 parent 1d77ee0 commit bd6d73e

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ By default the action does not need any token configuration and uses the provide
137137
| Key | Value Information | Type | Required |
138138
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
139139
| `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** |
140-
| `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** |
140+
| `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** |
141141
| `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** |
142142
| `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** |
143143
| `commit-message` | If you need to customize the commit message for an integration you can do so. | `with` | **No** |

__tests__/util.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ describe('util', () => {
3131
const value = ''
3232
expect(isNullOrUndefined(value)).toBeTruthy()
3333
})
34+
35+
it('should return true if the value is null (with allowEmptyString)', async () => {
36+
const value = null
37+
expect(isNullOrUndefined(value, true)).toBeTruthy()
38+
})
39+
40+
it('should return true if the value is undefined (with allowEmptyString)', async () => {
41+
const value = undefined
42+
expect(isNullOrUndefined(value, true)).toBeTruthy()
43+
})
44+
45+
it('should return false if the value is defined (with allowEmptyString)', async () => {
46+
const value = 'montezuma'
47+
expect(isNullOrUndefined(value, true)).toBeFalsy()
48+
})
49+
50+
it('should return false if the value is empty string (with allowEmptyString)', async () => {
51+
const value = ''
52+
expect(isNullOrUndefined(value, true)).toBeFalsy()
53+
})
3454
})
3555

3656
describe('generateTokenType', () => {

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const action: ActionInterface = {
9595
? stripProtocolFromUrl(process.env.GITHUB_SERVER_URL)
9696
: 'github.com',
9797
isTest: TestFlag.NONE,
98-
email: !isNullOrUndefined(getInput('git-config-email'))
98+
email: !isNullOrUndefined(getInput('git-config-email'), true)
9999
? getInput('git-config-email')
100100
: pusher && pusher.email
101101
? pusher.email

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2222
action.silent
2323
)
2424
await execute(
25-
`git config user.email "${action.email}"`,
25+
`git config user.email "${action.email ? action.email : '<>'}"`,
2626
action.workspace,
2727
action.silent
2828
)

src/util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ import {ActionInterface, RequiredActionParameters} from './constants'
77
const replaceAll = (input: string, find: string, replace: string): string =>
88
input.split(find).join(replace)
99

10-
/* Utility function that checks to see if a value is undefined or not. */
11-
export const isNullOrUndefined = (value: unknown): boolean =>
12-
typeof value === 'undefined' || value === null || value === ''
10+
/* Utility function that checks to see if a value is undefined or not.
11+
If allowEmptyString is passed the parameter is allowed to contain an empty string as a valid parameter. */
12+
export const isNullOrUndefined = (
13+
value: unknown,
14+
allowEmptyString = false
15+
): boolean =>
16+
allowEmptyString
17+
? typeof value === 'undefined' || value === null
18+
: typeof value === 'undefined' || value === null || value === ''
1319

1420
/* Generates a token type used for the action. */
1521
export const generateTokenType = (action: ActionInterface): string =>

0 commit comments

Comments
 (0)
0