From ce0ca760ed84a1967af96eec0eb1246336610ede Mon Sep 17 00:00:00 2001 From: James Womack Date: Tue, 7 Nov 2017 07:25:53 -0800 Subject: [PATCH] refactor: stash is now bb enterprise BREAKING CHANGE: stash repo type is now bitbucket --- README.md | 8 ++++---- index.js | 2 +- lib/changelog.js | 41 ++++++++++++++++++++++------------------ tests/specs/changelog.js | 20 ++++++++++++++++++++ 4 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 tests/specs/changelog.js diff --git a/README.md b/README.md index 634fe5e..b709562 100644 --- a/README.md +++ b/README.md @@ -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`) @@ -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 diff --git a/index.js b/index.js index 9f4f6e3..bfe6c81 100755 --- a/index.js +++ b/index.js @@ -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' }) diff --git a/lib/changelog.js b/lib/changelog.js index 1179826..5c4831d 100644 --- a/lib/changelog.js +++ b/lib/changelog.js @@ -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 * @@ -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) { @@ -60,3 +64,4 @@ function writeChangelog (options, done) { } module.exports = writeChangelog +module.exports.createBitbucketEnterpriseCommitLink = createBitbucketEnterpriseCommitLink diff --git a/tests/specs/changelog.js b/tests/specs/changelog.js new file mode 100644 index 0000000..d1d26fe --- /dev/null +++ b/tests/specs/changelog.js @@ -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() +})