Skip to content

Commit 1c3af0d

Browse files
committed
Export GIT_USER and GIT_EMAIL env and tags vars by default.
Fixes jacob-meacham#56.
1 parent c7658e3 commit 1c3af0d

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.org/jacob-meacham/serverless-plugin-git-variables.svg?branch=develop)](https://travis-ci.org/jacob-meacham/serverless-plugin-git-variables)
44

55
Expose git variables (HEAD description, branch name, short commit hash, message, git tags, and if the local repo has changed files) to your serverless services.
6-
Moreover, it adds GIT related environment variables and tags (GIT_COMMIT_SHORT, GIT_COMMIT_LONG, GIT_BRANCH, GIT_IS_DIRTY, GIT_REPOSITORY, GIT_TAGS) for each defined function in the serverless file. You can disable this by adding the following custom variable in your serverless.yml file:
6+
Moreover, it adds GIT related environment variables and tags (GIT_COMMIT_SHORT, GIT_COMMIT_LONG, GIT_BRANCH, GIT_IS_DIRTY, GIT_REPOSITORY, GIT_TAGS, GIT_USER, GIT_EMAIL) for each defined function in the serverless file. You can disable this by adding the following custom variable in your serverless.yml file:
77

88
```
99
custom:

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ServerlessGitVariables {
152152
return;
153153
}
154154

155-
const exportList = [{ value: 'sha1', variableName: 'GIT_COMMIT_SHORT' }, { value: 'commit', variableName: 'GIT_COMMIT_LONG' }, { value: 'branch', variableName: 'GIT_BRANCH' }, { value: 'isDirty', variableName: 'GIT_IS_DIRTY' }, { value: 'repository', variableName: 'GIT_REPOSITORY' }, { value: 'tags', variableName: 'GIT_TAGS' }];
155+
const exportList = [{ value: 'sha1', variableName: 'GIT_COMMIT_SHORT' }, { value: 'commit', variableName: 'GIT_COMMIT_LONG' }, { value: 'branch', variableName: 'GIT_BRANCH' }, { value: 'isDirty', variableName: 'GIT_IS_DIRTY' }, { value: 'repository', variableName: 'GIT_REPOSITORY' }, { value: 'tags', variableName: 'GIT_TAGS' }, { value: 'user', variableName: 'GIT_USER' }, { value: 'email', variableName: 'GIT_EMAIL' }];
156156

157157
for (const functionName of _this3.serverless.service.getAllFunctions()) {
158158
const func = _this3.serverless.service.getFunction(functionName);

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export default class ServerlessGitVariables {
119119
{ value: 'branch', variableName: 'GIT_BRANCH' },
120120
{ value: 'isDirty', variableName: 'GIT_IS_DIRTY' },
121121
{ value: 'repository', variableName: 'GIT_REPOSITORY' },
122-
{ value: 'tags', variableName: 'GIT_TAGS' }
122+
{ value: 'tags', variableName: 'GIT_TAGS' },
123+
{ value: 'user', variableName: 'GIT_USER' },
124+
{ value: 'email', variableName: 'GIT_EMAIL' }
123125
]
124126

125127
for (const functionName of this.serverless.service.getAllFunctions()) {

test/index.spec.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,16 @@ test.serial('Env variables defined', async t => {
173173
t.is(func.environment.GIT_BRANCH, 'another_branch')
174174
t.is(func.environment.GIT_IS_DIRTY, 'false')
175175
t.is(func.environment.GIT_TAGS, '90440bd')
176+
t.is(func.environment.GIT_USER, 'Full User')
177+
t.is(func.environment.GIT_EMAIL, '[email protected]')
176178

177179
t.is(func.tags.GIT_COMMIT_SHORT, '90440bd')
178180
t.is(func.tags.GIT_COMMIT_LONG, '90440bdc8eb3b2fa20bc578f411cf4b725ae0a25')
179181
t.is(func.tags.GIT_BRANCH, 'another_branch')
180182
t.is(func.tags.GIT_IS_DIRTY, 'false')
181183
t.is(func.tags.GIT_TAGS, '90440bd')
184+
t.is(func.tags.GIT_USER, 'Full User')
185+
t.is(func.tags.GIT_EMAIL, '[email protected]')
182186
})
183187

184188
test.serial('Whitelist', async t => {
@@ -212,15 +216,19 @@ test.serial('Whitelist', async t => {
212216
t.is(func.environment.GIT_BRANCH, undefined)
213217
t.is(func.environment.GIT_IS_DIRTY, 'false')
214218
t.is(func.environment.GIT_TAGS, undefined)
219+
t.is(func.environment.GIT_USER, undefined)
220+
t.is(func.environment.GIT_EMAIL, undefined)
215221

216222
t.is(func.tags.GIT_COMMIT_SHORT, undefined)
217223
t.is(func.tags.GIT_COMMIT_LONG, '90440bdc8eb3b2fa20bc578f411cf4b725ae0a25')
218224
t.is(func.tags.GIT_BRANCH, undefined)
219225
t.is(func.tags.GIT_IS_DIRTY, undefined)
220226
t.is(func.tags.GIT_TAGS, '90440bd')
227+
t.is(func.tags.GIT_USER, undefined)
228+
t.is(func.tags.GIT_EMAIL, undefined)
221229
})
222230

223-
test.serial('User/Email not exported', async t => {
231+
test.serial('User/Email is exported', async t => {
224232
fs.copySync('test/resources/full_repo/git', `${t.context.tmpDir}/.git`)
225233
process.chdir(t.context.tmpDir)
226234

@@ -242,11 +250,11 @@ test.serial('User/Email not exported', async t => {
242250
const plugin = new ServerlessGitVariables(fakeServerless, {})
243251
await plugin.exportGitVariables()
244252

245-
t.is(func.environment.GIT_USER, undefined)
246-
t.is(func.environment.GIT_EMAIL, undefined)
253+
t.is(func.environment.GIT_USER, 'Full User')
254+
t.is(func.environment.GIT_EMAIL, '[email protected]')
247255

248-
t.is(func.tags.GIT_USER, undefined)
249-
t.is(func.tags.GIT_EMAIL, undefined)
256+
t.is(func.tags.GIT_USER, 'Full User')
257+
t.is(func.tags.GIT_EMAIL, '[email protected]')
250258
})
251259

252260
test.serial('Disabling export of env variables', async t => {
@@ -276,6 +284,8 @@ test.serial('Disabling export of env variables', async t => {
276284
t.is(func.environment.GIT_BRANCH, undefined)
277285
t.is(func.environment.GIT_IS_DIRTY, undefined)
278286
t.is(func.environment.GIT_TAGS, undefined)
287+
t.is(func.environment.GIT_USER, undefined)
288+
t.is(func.environment.GIT_EMAIL, undefined)
279289

280290
t.is(func.tags, undefined)
281291
})

0 commit comments

Comments
 (0)