Skip to content

Commit

Permalink
refactor: stash is now bb enterprise
Browse files Browse the repository at this point in the history
BREAKING CHANGE: stash repo type is now bitbucket
  • Loading branch information
James Womack committed Nov 7, 2017
1 parent 727287e commit ce0ca76
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Updates your changelog according to the conventional changelog spec
* Publishes your module to NPM (optionally turned off via `--no-publish`)
* Pushes your code and tags to git (optionally turned off via `--no-push`)
* Supports both Github & Stash (creates links to these in your changelog)
* Supports changelog links for both Github & Bitbucket Enterprise (formerly Stash)
* Automatically recovers from errors by safely resetting to the git state prior to running unleash
* Features a "dry run" mode for most commands that will allow you to preview what change unleash will make before it makes them
* Allows you to preview what files will and won't be published to NPM (`--list-publishables`)
Expand Down Expand Up @@ -67,13 +67,13 @@ unleash -M --no-publish
unleash -M --no-push
```

#### Execute a Minor Release to a Stash Repository
#### Execute a Minor Release to a Bitbucket Enterprise Repository
```
unleash -m -r stash
unleash -m -r bitbucket
```
OR...
```
unleash --minor --repo-type stash
unleash --minor --repo-type bitbucket
```

#### View which files will be published to NPM
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const unleash = shortVersionFlags.reduce(function (y, shortFlag) {
})
.option('repo-type', {
alias: 'r',
describe: 'The remote repository type such as "stash"',
describe: 'The remote repository type, "bitbucket" or "github"',
default: 'github',
type: 'string'
})
Expand Down
41 changes: 23 additions & 18 deletions lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@ const
* @module lib/changelog
*/

function createBitbucketEnterpriseCommitLink () {
const template = require('lodash.template')
const partial = require('lodash.partial')
const pkg = require(process.cwd() + '/package')

const commitTemplate = function (repository, commit) {
const templateFn = repository ?
template('[<%= commit %>](<%= repository %>/commits/<%= commit %>)') :
template('<%= commit %>')
return templateFn({
repository: repository,
commit: commit.substring(0,8) // no need to show super long hash in log
})
}

return partial(commitTemplate, pkg.repository.url)
}

/**
* Output change information from git commits to CHANGELOG.md
*
* @param options - {Object} that contains all the options of the changelog writer
* - repoType: The {String} repo type (github or stash) of the project (default to `"github"`),
* - repoType: The {String} repo type (github or bitbucket) of the project (default to `"github"`),
* - version: The {String} semantic version to add a change log for
* @param done - {Function} that gets called when the changelog write task has completed
*
Expand All @@ -30,23 +48,9 @@ function writeChangelog (options, done) {
version: options.version
}

// Github uses "commit", Stash uses "commits"
if (options.repoType === 'stash') {
const template = require('lodash.template')
const partial = require('lodash.partial')

const commitTemplate = function (repository, commit) {
// TODO - Make this configurable and default to Github, but include a Stash option
const templateFn = repository ?
template('[<%= commit %>](<%= repository %>/commits/<%= commit %>)') :
template('<%= commit %>')
return templateFn({
repository: repository,
commit: commit.substring(0,8) // no need to show super long hash in log
})
}

opts.commitLink = partial(commitTemplate, pkg.repository.url)
// Github uses "commit", Bitbucket Enterprise uses "commits"
if (options.repoType === 'bitbucket') {
opts.commitLink = createBitbucketEnterpriseCommitLink()
}

return require('nf-conventional-changelog')(opts, function (err, clog) {
Expand All @@ -60,3 +64,4 @@ function writeChangelog (options, done) {
}

module.exports = writeChangelog
module.exports.createBitbucketEnterpriseCommitLink = createBitbucketEnterpriseCommitLink
20 changes: 20 additions & 0 deletions tests/specs/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict' // force block-scoping w/ Node < 6

const spec = require('tape')
const createBitbucketEnterpriseCommitLink = require('../../lib/changelog').createBitbucketEnterpriseCommitLink

spec('createBitbucketEnterpriseCommitLink', specOptions => {
const test = specOptions.test
const endSpec = specOptions.end

test('Has a task function (well it inherits from Undertaker)', testOptions => {
const equal = testOptions.equal
const endTest = testOptions.end

equal(typeof createBitbucketEnterpriseCommitLink, 'function')
equal(createBitbucketEnterpriseCommitLink()('acognaoiuc'), '[acognaoi](https://github.com/netflix/unleash/commits/acognaoi)')
endTest()
})

endSpec()
})

0 comments on commit ce0ca76

Please sign in to comment.