|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +/* |
| 5 | + * This script generates the template a changelog by comparing a current version |
| 6 | + * with master. Run this, copy what's logged into the `CHANGELOG.md` and update |
| 7 | + * the top section based on the changes listed in "Community Contributions" |
| 8 | + * |
| 9 | + * Usage: |
| 10 | + * |
| 11 | + * bin/changelog |
| 12 | + */ |
| 13 | + |
| 14 | +var EOL = require('os').EOL; |
| 15 | +var multiline = require('multiline'); |
| 16 | +var Promise = require('ember-cli/lib/ext/promise'); |
| 17 | +var GitHubApi = require('github'); |
| 18 | + |
| 19 | +var github = new GitHubApi({version: '3.0.0'}); |
| 20 | +var compareCommits = Promise.denodeify(github.repos.compareCommits); |
| 21 | +var currentVersion = 'v' + require('../package').version; |
| 22 | + |
| 23 | +compareCommits({ |
| 24 | + user: 'zapnito', |
| 25 | + repo: 'ember-cli-deploy-build', |
| 26 | + base: currentVersion, |
| 27 | + head: 'master' |
| 28 | +}).then(function(res) { |
| 29 | + return res.commits.map(function(commitInfo) { |
| 30 | + return commitInfo.commit.message |
| 31 | + |
| 32 | + }).filter(function(message) { |
| 33 | + return message.indexOf('Merge pull request #') > -1; |
| 34 | + |
| 35 | + }).map(function(message) { |
| 36 | + var numAndAuthor = message.match(/#(\d+) from (.*)\//).slice(1,3); |
| 37 | + var title = message.split('\n\n')[1]; |
| 38 | + |
| 39 | + return { |
| 40 | + number: +numAndAuthor[0], |
| 41 | + author: numAndAuthor[1], |
| 42 | + title: title |
| 43 | + }; |
| 44 | + |
| 45 | + }).sort(function(a, b) { |
| 46 | + return a.number > b.number; |
| 47 | + }).map(function(pr) { |
| 48 | + var link = '[#' + pr.number + ']' + |
| 49 | + '(https://github.com/zapnito/ember-cli-deploy-build/pull/' + pr.number + ')'; |
| 50 | + var title = pr.title; |
| 51 | + var author = '[@' + pr.author + ']' + |
| 52 | + '(https://github.com/' + pr.author +')'; |
| 53 | + |
| 54 | + return '- ' + link + ' ' + title + ' ' + author; |
| 55 | + |
| 56 | + }).join('\n'); |
| 57 | + |
| 58 | +}).then(function(contributions) { |
| 59 | + var changelog = generateChangelog(contributions); |
| 60 | + |
| 61 | + console.log(changelog); |
| 62 | +}).catch(function(err) { |
| 63 | + console.error(err); |
| 64 | +}) |
| 65 | + |
| 66 | +function generateChangelog(contributions) { |
| 67 | + var header = multiline(function() {/* |
| 68 | +The following changes are required if you are upgrading from the previous |
| 69 | +version: |
| 70 | +- Users |
| 71 | + + Upgrade your project's ember-cli version - [docs](http://www.ember-cli.com/#project-update) |
| 72 | +- Addon Developers |
| 73 | + + No changes required |
| 74 | +- Core Contributors |
| 75 | + + No changes required |
| 76 | +#### Community Contributions |
| 77 | + */}); |
| 78 | + |
| 79 | + var footer = 'Thank you to all who took the time to contribute!'; |
| 80 | + |
| 81 | + return header + EOL + EOL + contributions + EOL + EOL + footer; |
| 82 | +} |
0 commit comments