Skip to content

Commit

Permalink
feat: add fallback to environment variables 43 (#57)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bahmutov committed Nov 27, 2018
1 parent e2a0dd3 commit fd84fac
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 81 deletions.
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -36,12 +36,25 @@ commitInfo(folder)

Notes:

- 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)
- 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.
- Resolves with [Bluebird](https://github.com/petkaantonov/bluebird) promise.
- Only uses Git commands, see [src/git-api.js](src/git-api.js)
- If a command fails, returns null for each property
- If a command fails, returns `null` for each property
- If you need to debug, run with `DEBUG=commit-info` environment variable.

## Fallback environment variables

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

```
branch: COMMIT_INFO_BRANCH
message: COMMIT_INFO_MESSAGE
email: COMMIT_INFO_EMAIL
author: COMMIT_INFO_AUTHOR
sha: COMMIT_INFO_SHA
remote: COMMIT_INFO_REMOTE
```

## Individual methods

In addition to `commitInfo` this module also exposes individual promise-returning
Expand Down
31 changes: 26 additions & 5 deletions __snapshots__/commit-info-spec.js
@@ -1,13 +1,25 @@
exports['commit-info returns information 1'] = {
exports['commit-info combination with environment variables has certain api 1'] = [
"commitInfo",
"getBranch",
"getMessage",
"getEmail",
"getAuthor",
"getSha",
"getRemoteOrigin",
"getSubject",
"getBody"
]

exports['commit-info combination with environment variables returns information 1'] = {
"branch": "test-branch",
"message": "important commit",
"email": "me@foo.com",
"message": "some git message",
"email": "user@company.com",
"author": "John Doe",
"sha": "abc123",
"remote": "git@github.com/repo"
}

exports['commit-info has certain api 1'] = [
exports['commit-info no environment variables has certain api 1'] = [
"commitInfo",
"getBranch",
"getMessage",
Expand All @@ -19,7 +31,16 @@ exports['commit-info has certain api 1'] = [
"getBody"
]

exports['commit-info returns empty strings for missing info 1'] = {
exports['commit-info no environment variables returns information 1'] = {
"branch": "test-branch",
"message": "important commit",
"email": "me@foo.com",
"author": "John Doe",
"sha": "abc123",
"remote": "git@github.com/repo"
}

exports['commit-info no environment variables returns nulls for missing fields 1'] = {
"branch": "test-branch",
"message": null,
"email": "me@foo.com",
Expand Down
90 changes: 59 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -81,10 +81,10 @@
"github-post-release": "1.13.1",
"license-checker": "20.2.0",
"mocha": "5.2.0",
"mocked-env": "1.2.3",
"nsp": "2.8.1",
"pre-git": "3.17.1",
"prettier-standard": "8.0.1",
"ramda": "0.26.0",
"semantic-release": "8.2.3",
"simple-commit-message": "3.3.2",
"snap-shot-it": "6.2.5",
Expand All @@ -96,6 +96,7 @@
"check-more-types": "2.24.0",
"debug": "4.1.0",
"execa": "1.0.0",
"lazy-ass": "1.6.0"
"lazy-ass": "1.6.0",
"ramda": "0.26.0"
}
}

0 comments on commit fd84fac

Please sign in to comment.