Skip to content

Commit fd84fac

Browse files
authored
feat: add fallback to environment variables 43 (#57)
* feat: add fallback to environment variables, close #43 * chore: merging git and env fields * chore: bring mocked-env for better testing * use Ramda mergeWith * feat: combine git and env variables, tested * chore: better readme text
1 parent e2a0dd3 commit fd84fac

File tree

9 files changed

+260
-81
lines changed

9 files changed

+260
-81
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ commitInfo(folder)
3636

3737
Notes:
3838

39-
- Code assumes there is `.git` folder and uses Git commands to get each property, like `git show -s --pretty=%B`, see [src/git-api.js](src/git-api.js)
39+
- Code assumes there is `.git` folder and uses Git commands to get each property, like `git show -s --pretty=%B`, see [src/git-api.js](src/git-api.js). Note: there is fallback to environment variables.
4040
- Resolves with [Bluebird](https://github.com/petkaantonov/bluebird) promise.
4141
- Only uses Git commands, see [src/git-api.js](src/git-api.js)
42-
- If a command fails, returns null for each property
42+
- If a command fails, returns `null` for each property
4343
- If you need to debug, run with `DEBUG=commit-info` environment variable.
4444

45+
## Fallback environment variables
46+
47+
If getting the commit information using `git` fails for some reason, you can provide the commit information by setting the environment variables. This module will look at the following environment variables as a fallback
48+
49+
```
50+
branch: COMMIT_INFO_BRANCH
51+
message: COMMIT_INFO_MESSAGE
52+
email: COMMIT_INFO_EMAIL
53+
author: COMMIT_INFO_AUTHOR
54+
sha: COMMIT_INFO_SHA
55+
remote: COMMIT_INFO_REMOTE
56+
```
57+
4558
## Individual methods
4659

4760
In addition to `commitInfo` this module also exposes individual promise-returning

__snapshots__/commit-info-spec.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
exports['commit-info returns information 1'] = {
1+
exports['commit-info combination with environment variables has certain api 1'] = [
2+
"commitInfo",
3+
"getBranch",
4+
"getMessage",
5+
"getEmail",
6+
"getAuthor",
7+
"getSha",
8+
"getRemoteOrigin",
9+
"getSubject",
10+
"getBody"
11+
]
12+
13+
exports['commit-info combination with environment variables returns information 1'] = {
214
"branch": "test-branch",
3-
"message": "important commit",
4-
"email": "me@foo.com",
15+
"message": "some git message",
16+
"email": "user@company.com",
517
"author": "John Doe",
618
"sha": "abc123",
719
"remote": "[email protected]/repo"
820
}
921

10-
exports['commit-info has certain api 1'] = [
22+
exports['commit-info no environment variables has certain api 1'] = [
1123
"commitInfo",
1224
"getBranch",
1325
"getMessage",
@@ -19,7 +31,16 @@ exports['commit-info has certain api 1'] = [
1931
"getBody"
2032
]
2133

22-
exports['commit-info returns empty strings for missing info 1'] = {
34+
exports['commit-info no environment variables returns information 1'] = {
35+
"branch": "test-branch",
36+
"message": "important commit",
37+
"email": "[email protected]",
38+
"author": "John Doe",
39+
"sha": "abc123",
40+
"remote": "[email protected]/repo"
41+
}
42+
43+
exports['commit-info no environment variables returns nulls for missing fields 1'] = {
2344
"branch": "test-branch",
2445
"message": null,
2546
"email": "[email protected]",

package-lock.json

Lines changed: 59 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@
8181
"github-post-release": "1.13.1",
8282
"license-checker": "20.2.0",
8383
"mocha": "5.2.0",
84+
"mocked-env": "1.2.3",
8485
"nsp": "2.8.1",
8586
"pre-git": "3.17.1",
8687
"prettier-standard": "8.0.1",
87-
"ramda": "0.26.0",
8888
"semantic-release": "8.2.3",
8989
"simple-commit-message": "3.3.2",
9090
"snap-shot-it": "6.2.5",
@@ -96,6 +96,7 @@
9696
"check-more-types": "2.24.0",
9797
"debug": "4.1.0",
9898
"execa": "1.0.0",
99-
"lazy-ass": "1.6.0"
99+
"lazy-ass": "1.6.0",
100+
"ramda": "0.26.0"
100101
}
101102
}

0 commit comments

Comments
 (0)