Skip to content

Commit 2e20485

Browse files
authored
Merge pull request mozilla#349 from kumar303/changelog-cli
chore: switch to conventional-changelog
2 parents 74e9bba + 99e5919 commit 2e20485

File tree

3 files changed

+30
-115
lines changed

3 files changed

+30
-115
lines changed

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ it is okay to include each as a separate commit.
103103
To release a new version of `web-ext`, follow these steps:
104104

105105
* Pull from master to make sure you're up to date.
106+
* Create a changelog by running `grunt changelog`.
107+
This will output a Markdown list of all unreleased changes.
108+
You can copy/paste this into the tag notes on github after the tag is created.
109+
It may require some manual editing. For example, commit messages might be
110+
truncated.
106111
* Bump the version in `package.json`.
107112
* Commit and push the version change.
108113
* Tag master with the new release you're about to create
109114
(example: `git tag 1.0.1`) and run `git push --tags upstream`.
110-
* Create a changelog by running `grunt changelog:1.0.0` where
111-
`1.0.0` is the *last published* release tag. This will output a Markdown list
112-
of changes that you can paste into the tag notes on github. It may
113-
require some editing. For example, the *Uncategorized* section may need
114-
rearranging.
115115
* Go to the github
116116
[releases page](https://github.com/mozilla/web-ext/releases),
117117
edit the tag you just created, and enter in the changelog notes.

Gruntfile.js

+24-110
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,8 @@ module.exports = function(grunt) {
6262
'lint-commit-msg', 'checks for commit message lint', function() {
6363
var done = this.async();
6464
if (semver.satisfies(process.version, '>= 4.0.0')) {
65-
66-
var proc = spawn('conventional-changelog-lint', ['--from', 'master']);
67-
proc.stderr.on('data', function(data) {
68-
grunt.log.write(data);
69-
});
70-
proc.stdout.on('data', function(data) {
71-
grunt.log.write(data);
72-
});
73-
proc.on('close', function(code) {
74-
var succeeded = code === 0;
75-
done(succeeded);
76-
});
77-
65+
gruntExec(grunt, 'conventional-changelog-lint', ['--from', 'master'],
66+
done);
7867
} else {
7968
grunt.log.writeln(
8069
'task skipped because this version of Node is too old');
@@ -103,107 +92,32 @@ module.exports = function(grunt) {
10392
});
10493

10594
grunt.registerTask(
106-
'changelog', 'Create a changelog from commits', function(tag) {
95+
'changelog', 'Create a changelog from commits', function() {
10796
// See https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md#writing-commit-messages
108-
var done = this.async();
109-
var results = {};
110-
111-
if (tag === undefined) {
112-
grunt.log.writeln(
113-
'Missing first agument: the current git release tag ' +
114-
'(before the next release)');
115-
return done(false);
116-
}
117-
118-
function processLine(line) {
119-
// First, get the commit hash.
120-
var metaMatch = /commit:\{([^\}]+)\} (.*)/.exec(line);
121-
if (!metaMatch) {
122-
throw new Error('Could not find commit hash in ' + line);
123-
}
124-
var commitHash = metaMatch[1];
125-
line = metaMatch[2]; // strip off the commit hash part.
126-
127-
// Parse the semantic commit message.
128-
// e.g. fix(): Fixed some stuff
129-
var match = /^([a-zA-Z0-9]+)\(?.*\)?: (.*)$/g.exec(line);
130-
var bucket;
131-
var message = line;
132-
if (!match) {
133-
bucket = results.uncategorized = results.uncategorized || [];
134-
} else {
135-
var type = match[1].toLowerCase();
136-
bucket = results[type] = results[type] || [];
137-
message = match[2];
138-
}
139-
140-
bucket.push({msg: message, commit: commitHash});
141-
}
142-
143-
function commitLink(commit) {
144-
// Create a Markdown link to the commit.
145-
return '[' + commit + ']' +
146-
'(https://github.com/mozilla/web-ext/commit/' + commit + ')';
147-
}
148-
149-
function bullet(text) {
150-
// Create a Markdown bullet point.
151-
return ' * ' + text;
152-
}
153-
154-
function writeChangelog() {
155-
[
156-
['New features:', 'feat'],
157-
['Fixes:', 'fix'],
158-
['Performance enhancements:', 'perf'],
159-
['Uncategorized:', 'uncategorized'],
160-
].forEach(function(conf) {
161-
var header = conf[0];
162-
var key = conf[1];
163-
164-
if ((results[key] || []).length) {
165-
grunt.log.writeln(header);
166-
results[key].forEach(function(data) {
167-
grunt.log.writeln(
168-
bullet(data.msg + ' (' + commitLink(data.commit) + ')'));
169-
});
170-
grunt.log.writeln('');
171-
}
172-
});
173-
grunt.log.writeln('General maintenance:');
174-
grunt.log.writeln(bullet(
175-
results.chore.length + ' dependency updates (or other chores)'));
176-
grunt.log.writeln(bullet(
177-
results.docs.length + ' documentation updates'));
178-
}
97+
gruntExec(grunt, 'conventional-changelog', ['-p', 'angular', '-u'],
98+
this.async());
99+
});
179100

180-
var git = spawn(
181-
'git',
182-
['log', '--no-merges', '--format=commit:{%h} %s', tag + '...master']);
101+
};
183102

184-
git.stderr.on('data', function(data) {
185-
grunt.log.writeln(data);
186-
done(false);
187-
});
188103

189-
git.stdout.on('data', function(data) {
190-
data.toString().split('\n').forEach(function(line) {
191-
if (line !== '') {
192-
processLine(line);
193-
}
194-
});
195-
});
104+
function gruntExec(grunt, cmd, args, onCompletion) {
105+
var PATH = process.env.PATH || '';
106+
// Make sure the script dir for local node modules is on the path.
107+
process.env.PATH =
108+
PATH + ':' + path.resolve(__dirname) + '/node_modules/.bin';
109+
var proc = spawn(cmd, args);
196110

197-
git.on('close', function(code) {
198-
if (code !== 0) {
199-
grunt.log.writeln('git exited: ' + code);
200-
done(false);
201-
} else {
202-
writeChangelog();
203-
done(true);
204-
}
205-
});
111+
proc.stderr.on('data', function(data) {
112+
grunt.log.write(data);
113+
});
206114

207-
});
115+
proc.stdout.on('data', function(data) {
116+
grunt.log.write(data);
117+
});
208118

209-
};
119+
proc.on('close', function(code) {
120+
var succeeded = code === 0;
121+
onCompletion(succeeded);
122+
});
123+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"babel-preset-es2015": "6.9.0",
7272
"babel-preset-stage-2": "6.11.0",
7373
"chai": "3.5.0",
74+
"conventional-changelog-cli": "1.2.0",
7475
"conventional-changelog-lint": "1.0.0",
7576
"copy-dir": "0.3.0",
7677
"coveralls": "2.11.9",

0 commit comments

Comments
 (0)