From fcf4bb67cefcc59551783e9b4ae7dbf6e1d2ca1c Mon Sep 17 00:00:00 2001 From: Hutson Betts Date: Mon, 29 May 2017 12:52:32 -0500 Subject: [PATCH] refactor(package): make similar to conventional-gitlab-changelog --- .gitattributes | 2 +- .travis.yml | 43 +++++--- CHANGELOG.md | 186 --------------------------------- CONTRIBUTING.md | 45 ++++++++ README.md | 35 ++----- package.json | 48 ++++----- cli.js => src/cli.js | 2 +- index.js => src/index.js | 2 +- {lib => src}/transform.js | 0 {lib => src}/transform.spec.js | 0 test/cli.js | 165 ----------------------------- test/fixtures/_package.json | 5 - test/fixtures/config.js | 5 - test/prepare.js | 9 -- test/test.js | 180 ------------------------------- 15 files changed, 109 insertions(+), 618 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md rename cli.js => src/cli.js (98%) mode change 100755 => 100644 rename index.js => src/index.js (98%) rename {lib => src}/transform.js (100%) rename {lib => src}/transform.spec.js (100%) delete mode 100644 test/cli.js delete mode 100644 test/fixtures/_package.json delete mode 100644 test/fixtures/config.js delete mode 100644 test/prepare.js delete mode 100644 test/test.js diff --git a/.gitattributes b/.gitattributes index 176a458f..6313b56c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -* text=auto +* text=auto eol=lf diff --git a/.travis.yml b/.travis.yml index 953acb3f..8bb61a38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,32 @@ -sudo: false language: node_js -node_js: - - '5' - - '4' - - '3' - - '2' - - '1' - - '0.12' - - '0.10' -before_script: - - git config --global user.name 'Travis-CI' - - git config --global user.email 'dummy@example.org' -after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --timeout 50000 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 +cache: + directories: + - "node_modules" + yarn: true env: global: - - secure: QCYfoj5UTTSFuKP1FqxG72ROGm97pPiFbSS2uYofu1dh3DtXn8sbSxAH9IdZWiHONbu+sNT0DWVyVx2tsBbHZewE61tu774Jmo6IeqC3z/B2Fn4NtbZmz9AmB02QRlOjk+CxFJqq1vJTcQtTZ0taBbm9V5C+MrxcSAl0FuotYNc/Hi+29BJMLU+/OPnB1se9ezaCvz9NLb9v/V3owIONkOo79zTTtm7fGbGisi7FJ5VmV/iBhgRI+PNC49Xrnr2j0A44RKVdtJ69G2GSi0Zam7QywwVUZLkt3pnJPta2Li6ycS8aPYsYOR6xFJwY2cqCmEmZGX3Z2J8PjUkJruSi7tkiqgFUKKBW2LTtKNVkoOAMdxt8JQchy6S3JFsVc1rW7Qvs3N1gBNW/DzZWBbL8/E/z0paEF1Gjwk3T5tXuq5CV+SsyJ1jPdShPWjlewOMZicr/pATflKtg5aQOSsclZ2wPIyZGHoeBs0v/gm9yVId6zQTJBk+ZPdNrjW7hH4GVOmyCL7WUBlazSgP0tWKdo9B5behh+9HCT82MLrD6xedHorBbKbcewDSzyLan8nWPquLFWPclqjLRU3jKM6m/eNDt0SEFv+jiwgUF8J5fPnuTpt6GWdwAv5cOxVSKlA6ANCsk064XiQTEW6WGdczj+J3w2Y4HZxGbmhFZKs+YZZs= + - CXX=g++-4.8 + matrix: + - NPM_VERSION=2 + - NPM_VERSION=3 + - NPM_VERSION=4 + - NPM_VERSION=next +matrix: + fast_finish: true + allow_failures: + - env: NPM_VERSION=next + - node_js: "node" +node_js: + - "4" + - "6" + - "node" +before_install: + - npm install --global npm@${NPM_VERSION} +after_script: + - cat ./coverage/lcov.info | node $(npm bin)/coveralls.js diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 66ddc1d2..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,186 +0,0 @@ - -## [1.1.3](https://github.com/conventional-changelog/conventional-github-releaser/compare/v1.1.2...v1.1.3) (2016-06-12) - - -### Bug Fixes - -* **cli:** config option issue (#19) ([a958ea9](https://github.com/conventional-changelog/conventional-github-releaser/commit/a958ea9)) -* **cli:** fix unit test error ([6a80929](https://github.com/conventional-changelog/conventional-github-releaser/commit/6a80929)) -* **test:** use github user from env validable ([c787ea4](https://github.com/conventional-changelog/conventional-github-releaser/commit/c787ea4)) - - - - -## [1.1.2](https://github.com/conventional-changelog/conventional-github-releaser/compare/v1.1.1...v1.1.2) (2016-04-17) - - - - - -## [1.1.1](https://github.com/stevemao/conventional-github-releaser/compare/v1.1.0...v1.1.1) (2016-02-29) - - -### Bug Fixes - -* **partial:** always ignore the default header partial ([73c27d9](https://github.com/stevemao/conventional-github-releaser/commit/73c27d9)) - - - - -# [1.1.0](https://github.com/stevemao/conventional-github-releaser/compare/v1.0.0...v1.1.0) (2016-02-13) - - -### Features - -* use conventional-changelog v1.1.0 ([8617e57](https://github.com/stevemao/conventional-github-releaser/commit/8617e57)) - - -### BREAKING CHANGES - -* cli options are different. -`--config` is added. -`--git-raw-commits-opts`, `--parser-opts` and `--writer-opts` are removed. - - - - -# [1.0.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.5.3...v1.0.0) (2016-02-05) - - -### Chores - -* **deps:** bump ([00c939a](https://github.com/stevemao/conventional-github-releaser/commit/00c939a)) - - -### BREAKING CHANGES - -* deps: Use conventional-changelog 1.0.0. - - - - -## [0.5.3](https://github.com/stevemao/conventional-github-releaser/compare/v0.5.2...v0.5.3) (2016-01-30) - - -### Bug Fixes - -* **cli:** should error if all results fail ([12f1990](https://github.com/stevemao/conventional-github-releaser/commit/12f1990)) -* **cli:** should error if only one result when verbose ([9c574ee](https://github.com/stevemao/conventional-github-releaser/commit/9c574ee)) - - - - -## [0.5.2](https://github.com/stevemao/conventional-github-releaser/compare/v0.5.1...v0.5.2) (2016-01-30) - - -### Bug Fixes - -* **cli:** fail if theres one failing result ([2814a62](https://github.com/stevemao/conventional-github-releaser/commit/2814a62)), closes [#6](https://github.com/stevemao/conventional-github-releaser/issues/6) -* **err:** better message ([8c07bde](https://github.com/stevemao/conventional-github-releaser/commit/8c07bde)), closes [#8](https://github.com/stevemao/conventional-github-releaser/issues/8) - - - - -## [0.5.1](https://github.com/stevemao/conventional-github-releaser/compare/v0.5.0...v0.5.1) (2015-12-25) - - -### Bug Fixes - -* **err:** catch error in gitSemverTags ([f3101c7](https://github.com/stevemao/conventional-github-releaser/commit/f3101c7)) - - - - -# [0.5.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.4.0...v0.5.0) (2015-09-30) - - -### Features - -* **deps:** bump ([f40b898](https://github.com/stevemao/conventional-github-releaser/commit/f40b898)) - - -### BREAKING CHANGES - -* deps: Use conventional-changelog^0.5.0 - - - - -# [0.4.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.3.0...v0.4.0) (2015-08-15) - - - - - -# [0.3.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.2.0...v0.3.0) (2015-08-09) - - -### Bug Fixes - -* **transform:** use new syntax of conventional-changelog@0.3.0 ([a14397d](https://github.com/stevemao/conventional-github-releaser/commit/a14397d)) - -### Features - -* **deps:** use conventional-changelog@0.3.0 ([d707ef6](https://github.com/stevemao/conventional-github-releaser/commit/d707ef6)) - - -### BREAKING CHANGES - -* deps: . - - - - -# [0.2.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.1.0...v0.2.0) (2015-07-24) - - -### Bug Fixes - -* the latest version should be last semver tag ([e7922fa](https://github.com/stevemao/conventional-github-releaser/commit/e7922fa)) -* **writeOpts:** do not overwrite transform ([4f0787f](https://github.com/stevemao/conventional-github-releaser/commit/4f0787f)) - - - - -# [0.1.0](https://github.com/stevemao/conventional-github-releaser/compare/v0.0.4...v0.1.0) (2015-07-22) - - - - - -## [0.0.4](https://github.com/stevemao/conventional-github-releaser/compare/v0.0.3...v0.0.4) (2015-07-20) - - -### Features - -* **prerelease:** auto detect based on semver ([981c704](https://github.com/stevemao/conventional-github-releaser/commit/981c704)) - - - - -## [0.0.3](https://github.com/stevemao/conventional-github-releaser/compare/v0.0.2...v0.0.3) (2015-07-17) - - -### Features - -* **partial:** no header if using preset by default ([861730f](https://github.com/stevemao/conventional-github-releaser/commit/861730f)) - - - - -## [0.0.2](https://github.com/stevemao/conventional-github-releaser/compare/v0.0.1...v0.0.2) (2015-07-17) - - -### Bug Fixes - -* **cli:** alias ([1a1c20f](https://github.com/stevemao/conventional-github-releaser/commit/1a1c20f)) -* **opts:** merge options to deep assign ([88ae81c](https://github.com/stevemao/conventional-github-releaser/commit/88ae81c)) - - - - -## 0.0.1 (2015-07-15) - - - - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..f1ff3f55 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,45 @@ +# Contributing + +## Getting Started + +Fork the repository to your own account and then clone the repository to a suitable location on your local machine. + +```bash +git clone [YOUR FORK OF THE PROJECT] +``` + +To update the project from within the project's folder you can run the following command: + +```bash +git pull --rebase +``` + +### Building + +Install the project's dependencies. + +```bash +npm install +``` + +### Testing + +To run the project's tests run the following command: + +```bash +npm test +``` + +## Feature Requests + +I'm always looking for suggestions to improve this project. If you have a suggestion for improving an existing feature, or would like to suggest a completely new feature, please file an issue with my [GitHub repository](https://github.com/conventional-changelog/conventional-github-releaser/issues). + +## Bug Reports + +My project isn't always perfect, but I strive to always improve on that work. You may file bug reports on the [GitHub repository](https://github.com/conventional-changelog/conventional-github-releaser/issues) site. + +## Pull Requests + +Along with my desire to hear your feedback and suggestions, I'm also interested in accepting direct assistance in the form of new code or documentation. + +Please feel free to file merge requests against my [GitHub repository](https://github.com/conventional-changelog/conventional-github-releaser/merge_requests). diff --git a/README.md b/README.md index 0be18264..a5a6319d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url] +# conventional-github-releaser +[![Build Status](https://travis-ci.org/conventional-changelog/conventional-github-releaser.svg?branch=master)](https://travis-ci.org/conventional-changelog/conventional-github-releaser) +[![Coverage Status](https://coveralls.io/repos/github/conventional-changelog/conventional-github-releaser/badge.svg?branch=master)](https://coveralls.io/github/conventional-changelog/conventional-github-releaser?branch=master) +[![dependencies Status](https://david-dm.org/conventional-changelog/conventional-github-releaser/status.svg)](https://david-dm.org/conventional-changelog/conventional-github-releaser) [![Join the chat at https://gitter.im/conventional-changelog/conventional-github-releaser](https://badges.gitter.im/conventional-changelog/conventional-github-releaser.svg)](https://gitter.im/conventional-changelog/conventional-github-releaser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -> Make a new GitHub release from git metadata +> Make a new GitHub release from git metadata. **Note** You don't have to use the angular commit convention. For the best result of the tool to tokenize you commit and produce flexible output, it's recommended to use a commit convention. - ## Quick start [Set up a token first](#setup-token-for-cli). @@ -33,18 +35,16 @@ All available command line parameters can be listed using [CLI](#cli) : `convent Or use one of the plugins if you are already using the tool: [grunt](https://github.com/conventional-changelog/grunt-conventional-github-releaser)/[atom](https://github.com/conventional-changelog/atom-conventional-changelog) - ## Example output - https://github.com/conventional-changelog/conventional-github-releaser/releases - https://github.com/conventional-changelog/conventional-changelog/releases - ### Recommended workflow 1. Make changes 2. Commit those changes -3. Make sure Travis turns green +3. Make sure Travis CI turns green 4. Bump version in `package.json` 5. Commit `package.json` files 6. Tag @@ -55,7 +55,6 @@ You have to have a tag on GitHub to make a release. hence `gitRawCommitsOpts.to` Please use this [gist](https://gist.github.com/stevemao/280ef22ee861323993a0) to make a release or change it to your needs. - ## Why - Based on [conventional-changelog](https://github.com/ajoslin/conventional-changelog) but GitHub releases are more elegant. @@ -65,7 +64,6 @@ Please use this [gist](https://gist.github.com/stevemao/280ef22ee861323993a0) to - Everything internally or externally is pluggable. - A lot of tests and actively maintained. - ## Programmatic Usage ```sh @@ -76,8 +74,8 @@ $ npm install --save conventional-github-releaser var conventionalGithubReleaser = require('conventional-github-releaser'); var AUTH = { - type: "oauth", - token: '0126af95c0e2d9b0a7c78738c4c00a860b04acc8'// change this to your own GitHub token or use an environment variable + type: 'oauth', + token: '0126af95c0e2d9b0a7c78738c4c00a860b04acc8' // change this to your own GitHub token or use an environment variable }; conventionalGithubReleaser(AUTH, { @@ -85,7 +83,6 @@ conventionalGithubReleaser(AUTH, { }, callback); ``` - ## API ### conventionalGithubReleaser(auth, [changelogOpts, [context, [gitRawCommitsOpts, [parserOpts, [writerOpts]]]]], callback) @@ -154,7 +151,6 @@ Default: `''` Default header contains the version and date which are already in the release. - ## CLI ```sh @@ -168,36 +164,23 @@ You can also submit your release as a draft version via the '--draft' flag. This Note: If all results error, it will print the error messages to stderr and exit with code `1`. - ## Regenerate all the releases Use [github-remove-all-releases](https://github.com/stevemao/github-remove-all-releases) to remove all releases and set `changelogOpts.releaseCount` to `0` to regenerate. - ## Setup token for cli [Create a new token](https://github.com/settings/tokens/new) and set your environment variable `CONVENTIONAL_GITHUB_RELEASER_TOKEN` to the token you just created. You can google [How to set environment variable](https://www.google.com.au/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20set%20environment%20variable). The scopes for the token you need is `public_repo` or `repo` (if you need to access private repos). [More details](https://developer.github.com/v3/oauth/#scopes). - ## Related - [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog-cli) - Generate a changelog from git metadata - [conventional-recommended-bump](https://github.com/conventional-changelog/conventional-recommended-bump) - Get a recommended version bump based on conventional commits -- [github-remove-all-releases](https://github.com/stevemao/github-remove-all-releases) - Remove all releases of your GitHub repo - [conventional-commits-detector](https://github.com/conventional-changelog/conventional-commits-detector) - Detect what commit message convention your repository is using +- [github-remove-all-releases](https://github.com/stevemao/github-remove-all-releases) - Remove all releases of your GitHub repo - [conventional-gitlab-releaser](https://gitlab.com/hutson/conventional-gitlab-releaser) - Similar to `conventional-github-releaser`, but makes a GitLab release. - ## License MIT © [Steve Mao](https://github.com/stevemao) - -[npm-image]: https://badge.fury.io/js/conventional-github-releaser.svg -[npm-url]: https://npmjs.org/package/conventional-github-releaser -[travis-image]: https://travis-ci.org/conventional-changelog/conventional-github-releaser.svg?branch=master -[travis-url]: https://travis-ci.org/conventional-changelog/conventional-github-releaser -[daviddm-image]: https://david-dm.org/conventional-changelog/conventional-github-releaser.svg?theme=shields.io -[daviddm-url]: https://david-dm.org/conventional-changelog/conventional-github-releaser -[coveralls-image]: https://coveralls.io/repos/conventional-changelog/conventional-github-releaser/badge.svg -[coveralls-url]: https://coveralls.io/r/conventional-changelog/conventional-github-releaser diff --git a/package.json b/package.json index ee633f3f..0a0cca7d 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,23 @@ { - "name": "conventional-github-releaser", - "version": "1.1.7", - "description": "Make a new GitHub release from git metadata", - "homepage": "https://github.com/conventional-changelog/conventional-github-releaser", "author": { "name": "Steve Mao", "email": "maochenyan@gmail.com", "url": "https://github.com/stevemao" }, - "repository": "conventional-changelog/conventional-github-releaser", - "license": "MIT", + "bin": "./src/cli.js", + "bugs": "https://github.com/conventional-changelog/conventional-github-releaser/issues", + "description": "Make a new GitHub release from git metadata.", + "engines": { + "node": "^6.9.0 || ^4.2.0", + "npm": "^4.0.0 || ^3.0.0 || ^2.1.9" + }, "files": [ - "index.js", - "cli.js", - "lib/" + "src/" ], + "homepage": "https://github.com/conventional-changelog/conventional-github-releaser", "keywords": [ "conventional-github-releaser", "github", - "gh", "release", "releases", "conventional-changelog", @@ -26,6 +25,17 @@ "changelog", "log" ], + "license": "MIT", + "main": "src/index.js", + "name": "conventional-github-releaser", + "repository": { + "type": "git", + "url": "https://github.com/conventional-changelog/conventional-github-releaser.git" + }, + "scripts": { + "test": "jshint src/ && jscs src/ && nyc --all --cache --include=src/ --exclude=src/**/*.spec.js --reporter=lcov --reporter=text mocha --check-leaks --full-trace --globals __core-js_shared__,__coverage__,YamlEscaper --inline-diffs --no-exit --recursive --reporter=progress --retries 1 src/**/*.spec.js" + }, + "version": "1.1.7", "dependencies": { "conventional-changelog": "^1.1.0", "dateformat": "^1.0.11", @@ -43,21 +53,9 @@ "chai": "^3.0.0", "concat-stream": "^1.5.1", "coveralls": "^2.11.2", - "github-remove-all-releases": "^1.0.0", - "istanbul": "^0.4.1", - "jscs": "^2.0.0", + "jscs": "^3.0.7", "jshint": "^2.9.1", - "mocha": "*", - "nyc": "^10.3.2", - "shelljs": "^0.6.0" - }, - "scripts": { - "coverage": "istanbul cover _mocha -- -R spec --timeout 50000 && rm -rf ./coverage", - "lint": "jshint *.js test --exclude node_modules && jscs *.js test", - "formertest": "npm run-script lint && mocha --timeout 50000", - "test": "jshint lib/ && jscs lib/ && nyc --all --cache --include=lib/ --exclude=lib/**/*.spec.js --reporter=lcov --reporter=text mocha --check-leaks --full-trace --globals __core-js_shared__,__coverage__,YamlEscaper --inline-diffs --no-exit --recursive --reporter=progress --retries 1 lib/**/*.spec.js" - }, - "bin": { - "conventional-github-releaser": "cli.js" + "mocha": "^3.2.0", + "nyc": "^10.3.2" } } diff --git a/cli.js b/src/cli.js old mode 100755 new mode 100644 similarity index 98% rename from cli.js rename to src/cli.js index b42194a2..aae09e30 --- a/cli.js +++ b/src/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node 'use strict'; var meow = require('meow'); -var conventionalGithubReleaser = require('./'); +var conventionalGithubReleaser = require('./index'); var resolve = require('path').resolve; var cli = meow({ diff --git a/index.js b/src/index.js similarity index 98% rename from index.js rename to src/index.js index f231d94d..8589a671 100644 --- a/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ var merge = require('lodash.merge'); var Q = require('q'); var semver = require('semver'); var through = require('through2'); -var transform = require('./lib/transform'); +var transform = require('./transform'); var github = new Github({ version: '3.0.0' diff --git a/lib/transform.js b/src/transform.js similarity index 100% rename from lib/transform.js rename to src/transform.js diff --git a/lib/transform.spec.js b/src/transform.spec.js similarity index 100% rename from lib/transform.spec.js rename to src/transform.spec.js diff --git a/test/cli.js b/test/cli.js deleted file mode 100644 index 6aba261d..00000000 --- a/test/cli.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; -var expect = require('chai').expect; -var fs = require('fs'); -var Q = require('q'); -var githubRemoveAllReleases = require('github-remove-all-releases'); -var shell = require('shelljs'); -var spawn = require('child_process').spawn; -var concat = require('concat-stream'); - -var cliPath = __dirname + '/../cli.js'; - -var AUTH = { - type: 'oauth', - token: process.env.TEST_CONVENTIONAL_GITHUB_RELEASER_TOKEN -}; -var GITHUB_USER = process.env.TEST_CONVENTIONAL_GITHUB_USER || 'stevemaotest'; - -describe('cli', function() { - before(function(done) { - shell.cd('cli'); - shell.exec('git init'); - fs.writeFileSync('test1', ''); - shell.exec('git add --all && git commit -m"First commit"'); - shell.exec('git tag v0.0.1'); - - githubRemoveAllReleases(AUTH, GITHUB_USER, 'conventional-github-releaser-test', function() { - done(); - }); - }); - - after(function() { - shell.cd('../'); - }); - - it('should work with one release', function(done) { - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], { - stdio: [process.stdin, null, null] - }); - - cp.stdout.pipe(concat(function(data) { - expect(data.toString()).to.include('Your git-log command is:'); - expect(data.toString()).to.include('state: \'fulfilled\''); - })); - - cp.on('close', function(code) { - expect(code).to.equal(0); - - done(); - }); - }); - - it('--config should work', function(done) { - fs.writeFileSync('test2', ''); - shell.exec('git add --all && git commit -m"fix: fix config!"'); - shell.exec('git tag v0.0.2'); - - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '--config', __dirname + '/fixtures/config.js', '-t', AUTH.token], { - stdio: [process.stdin, null, null] - }); - - cp.on('close', function(code) { - expect(code).to.equal(0); - - done(); - }); - }); - - it('should work with no releases', function(done) { - Q.Promise(function(resolve, reject) { - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], { - stdio: [process.stdin, null, null] - }); - - cp.on('error', function(code) { - reject('Process exits with code ' + code); - }); - - cp.on('close', function(code) { - expect(code).to.equal(0); - - resolve(); - }); - }).then(function() { - // we call it a second time, because there no tags are left to create a release from - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], { - stdio: [process.stdin, null, null] - }); - - cp.on('error', function(code) { - done('Process exits with code ' + code); - }); - - cp.on('close', function(code) { - // this time we also expect the cli to exit with code 0 due to #17 - expect(code).to.equal(0); - - done(); - }); - }); - }); - - it('should print out error message and exit with `1` if all results error', function(done) { - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token], { - stdio: [process.stdin, null, null] - }); - - cp.stderr.pipe(concat(function(data) { - expect(data.toString()).to.include('already_exists'); - })); - - cp.on('close', function(code) { - expect(code).to.equal(1); - - done(); - }); - }); - - it('should print out error message and exit with `1` if all results error when verbose', function(done) { - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], { - stdio: [process.stdin, null, null] - }); - - cp.stderr.pipe(concat(function(data) { - expect(data.toString()).to.include('already_exists'); - })); - - cp.on('close', function(code) { - expect(code).to.equal(1); - - done(); - }); - }); - - it('should exit with `0` if not all results error', function(done) { - fs.writeFileSync('test3', ''); - shell.exec('git add --all && git commit -m"Second commit"'); - shell.exec('git tag v0.0.3'); - - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-r', '0'], { - stdio: [process.stdin, null, null] - }); - - cp.on('close', function(code) { - expect(code).to.equal(0); - - done(); - }); - }); - - it('should exit with `1` if all results error', function(done) { - var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-r', '0'], { - stdio: [process.stdin, null, null] - }); - - cp.stderr.pipe(concat(function(data) { - expect(data.toString()).to.include('already_exists'); - })); - - cp.on('close', function(code) { - expect(code).to.equal(1); - - done(); - }); - }); -}); diff --git a/test/fixtures/_package.json b/test/fixtures/_package.json deleted file mode 100644 index 831ce9de..00000000 --- a/test/fixtures/_package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "conventional-github-releaser-test", - "version": "0.0.0", - "repository": "stevemaotest/conventional-github-releaser-test" -} diff --git a/test/fixtures/config.js b/test/fixtures/config.js deleted file mode 100644 index 567b998e..00000000 --- a/test/fixtures/config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - writerOpts: { - mainTemplate: '{{commitGroups.[0].commits.[0].type}}{{testContext}}template' - } -}; diff --git a/test/prepare.js b/test/prepare.js deleted file mode 100644 index 22da439a..00000000 --- a/test/prepare.js +++ /dev/null @@ -1,9 +0,0 @@ -var shell = require('shelljs'); - -shell.config.silent = true; -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); -shell.cd('tmp'); - -shell.mkdir('test'); -shell.mkdir('cli'); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a5e7e136..00000000 --- a/test/test.js +++ /dev/null @@ -1,180 +0,0 @@ -'use strict'; -var conventionalGithubReleaser = require('../'); -var expect = require('chai').expect; -var fs = require('fs'); -var Github = require('github'); -var githubRemoveAllReleases = require('github-remove-all-releases'); -var shell = require('shelljs'); - -var AUTH = { - type: 'oauth', - token: process.env.TEST_CONVENTIONAL_GITHUB_RELEASER_TOKEN -}; -var GITHUB_USER = process.env.TEST_CONVENTIONAL_GITHUB_USER || 'stevemaotest'; - -var github = new Github({ - version: '3.0.0' -}); - -github.authenticate(AUTH); - -describe('conventional-github-releaser', function() { - before(function(done) { - shell.cd('test'); - shell.exec('git init'); - fs.writeFileSync('test1', ''); - shell.exec('git add --all && git commit -m"First commit"'); - - githubRemoveAllReleases(AUTH, GITHUB_USER, 'conventional-github-releaser-test', function() { - done(); - }); - }); - - after(function() { - shell.cd('../'); - }); - - it('should throw if no auth is passed', function() { - expect(conventionalGithubReleaser).to.throw('Expected an auth object'); - }); - - it('should throw if no cb is passed', function() { - expect(function() { - conventionalGithubReleaser({}); - }).to.throw('Expected an callback'); - }); - - it('should error if git-raw-commits opts is wrong', function(done) { - conventionalGithubReleaser(AUTH, {}, {}, { - version: '0.0.1' - }, function(err) { - expect(err).to.be.ok; // jshint ignore:line - - done(); - }); - }); - - it('should error if no version can be found', function(done) { - conventionalGithubReleaser(AUTH, function(err) { - expect(err).to.be.ok; // jshint ignore:line - - done(); - }); - }); - - it('should create a release', function(done) { - shell.exec('git tag v1.0.0'); - - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - }, function(err, responses) { - expect(responses.length).to.equal(1); - expect(responses[0].state).to.equal('fulfilled'); - github.releases.getRelease({ - // jscs:disable - owner: GITHUB_USER, - repo: 'conventional-github-releaser-test', - id: responses[0].value.id - // jscs:enable - }, function(err, data) { - expect(data.body).to.match(/First commit/); - done(); - }); - }); - }); - - it('should fail if a release exists', function(done) { - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - }, function(err, responses) { - expect(responses[0].state).to.equal('rejected'); - - done(err); - }); - }); - - it('should create a prerelease', function(done) { - fs.writeFileSync('test2', ''); - shell.exec('git add --all && git commit -m"feat(awesome): second commit"'); - shell.exec('git tag v2.0.0-beta'); - - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - }, function(err, responses) { - expect(responses.length).to.equal(1); - expect(responses[0].state).to.equal('fulfilled'); - github.releases.getRelease({ - // jscs:disable - owner: GITHUB_USER, - repo: 'conventional-github-releaser-test', - id: responses[0].value.id - // jscs:enable - }, function(err, data) { - expect(data.prerelease).to.equal(true); - done(); - }); - }); - }); - - it('should ignore the header template if using a preset', function(done) { - fs.writeFileSync('test3', ''); - shell.exec('git add --all && git commit -m"feat(awesome): third commit"'); - shell.exec('git tag v2.0.0'); - - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - preset: 'angular' - }, function(err, responses) { - expect(responses.length).to.equal(1); - github.releases.getRelease({ - // jscs:disable - owner: GITHUB_USER, - repo: 'conventional-github-releaser-test', - id: responses[0].value.id - // jscs:enable - }, function(err, data) { - expect(data.body).to.not.match(/<\/a>/); - done(); - }); - }); - }); - - it('should generate multiple releases', function(done) { - fs.writeFileSync('test4', ''); - shell.exec('git add --all && git commit -m"feat(awesome): forth commit"'); - shell.exec('git tag v3.0.0'); - fs.writeFileSync('test5', ''); - shell.exec('git add --all && git commit -m"feat(awesome): fifth commit"'); - shell.exec('git tag v4.0.0'); - - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - releaseCount: 2 - }, function(err, responses) { - expect(responses.length).to.equal(2); - done(err); - }); - }); - - it('should attempt to generate all releases', function(done) { - conventionalGithubReleaser(AUTH, { - pkg: { - path: __dirname + '/fixtures/_package.json' - }, - releaseCount: 0 - }, function(err, responses) { - expect(responses.length).to.equal(5); - done(err); - }); - }); -});