Skip to content

Commit 9970606

Browse files
authored
General fixes (#190)
* Remove extra line from release log * Change the range logic * Add tests for extra second * Migrate to gulp v4 correctly related to #177 * Fix npm audit, fixes #189 * Fix author missing issue * Update travis configuration
1 parent 977b97f commit 9970606

File tree

9 files changed

+7961
-6561
lines changed

9 files changed

+7961
-6561
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ node_js:
55
- "6"
66
- "7.9"
77
- "8"
8-
9-
cache:
10-
directories:
11-
- node_modules
8+
- "10"
129

1310
before_install:
1411
- npm install -g gulp-cli

docs/options.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ The accepted file extensions are the following:
7777
You can configure the output of **gren** using templates. Set your own configuration inside the config file, which will be merged with the defaults, shown below:
7878

7979
{% raw %}
80-
```json
81-
{
80+
```js
81+
module.exports = {
8282
"template": {
83-
"commit": "- [{{message}}]({{url}}) - @{{author}}",
84-
"issue": "- {{labels}} {{name}} [{{text}}]({{url}})",
85-
"label": "[**{{label}}**]",
86-
"noLabel": "closed",
87-
"group": "\n#### {{heading}}\n",
88-
"changelogTitle": "# Changelog\n\n",
89-
"release": "## {{release}} ({{date}})\n{{body}}",
90-
"releaseSeparator": "\n---\n\n"
83+
commit: ({ message, url, author, name }) => `- [${message}](${url}) - ${author ? `@${author}` : name}`,
84+
issue: "- {{labels}} {{name}} [{{text}}]({{url}})",
85+
label: "[**{{label}}**]",
86+
noLabel: "closed",
87+
group: "\n#### {{heading}}\n",
88+
changelogTitle: "# Changelog\n\n",
89+
release: "## {{release}} ({{date}})\n{{body}}",
90+
releaseSeparator: "\n---\n\n"
9191
}
9292
}
9393
```

gulpfile.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const eslint = require('gulp-eslint');
44
const gulp = require('gulp');
55
const gulpIf = require('gulp-if');
66

7-
gulp.task('scripts', () => {
7+
gulp.task('scripts', done => {
88
gulp.src('./lib/src/**/*.js')
99
.pipe(babel({
1010
presets: ['es2015']
@@ -18,6 +18,8 @@ gulp.task('scripts', () => {
1818
.pipe(babel())
1919
.pipe(chmod(0o755))
2020
.pipe(gulp.dest('bin'));
21+
22+
done();
2123
});
2224

2325
gulp.task('lint', () => {
@@ -36,7 +38,7 @@ gulp.task('lint', () => {
3638
.pipe(gulpIf(isFixed, gulp.dest('./lib/')));
3739
});
3840

39-
gulp.task('watch', () => gulp.watch('./lib/**/*.js', ['lint', 'scripts']));
41+
gulp.task('watch', () => gulp.watch('./lib/**/*.js', gulp.series(['lint', 'scripts'])));
4042

41-
gulp.task('build', ['lint', 'scripts']);
42-
gulp.task('default', ['build', 'watch']);
43+
gulp.task('build', gulp.series(['lint', 'scripts']));
44+
gulp.task('default', gulp.series(['build', 'watch']));

lib/src/Gren.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Github from 'github-api';
33
import utils from './_utils.js';
44
import { generate } from './_template.js';
55
import connectivity from 'connectivity';
6-
import templateConfig from './templates.json';
6+
import templateConfig from './templates.js';
77
import ObjectAssign from 'object-assign-deep';
88
import fs from 'fs';
99

@@ -147,7 +147,7 @@ class Gren {
147147

148148
fs.writeFileSync(filePath, this.options.template.changelogTitle + body);
149149

150-
loaded(chalk.green(`\nChangelog created in ${filePath}`));
150+
loaded(chalk.green(`Changelog created in ${filePath}`));
151151
}
152152

153153
/**
@@ -201,7 +201,7 @@ class Gren {
201201
const loaded = utils.task(this, 'Preparing the release');
202202
const { data: release } = await this.repo.createRelease(releaseOptions);
203203

204-
loaded(chalk.green(`\n${release.name} has been successfully created!`) + chalk.blue(`\nSee the results here: ${release.html_url}`));
204+
loaded(chalk.green(`${release.name} has been successfully created!`) + chalk.blue(`\nSee the results here: ${release.html_url}`));
205205

206206
return release;
207207
}
@@ -465,12 +465,13 @@ class Gren {
465465
* @return {string}
466466
*/
467467
// eslint-disable-next-line camelcase
468-
_templateCommits({ sha, html_url, author: { login }, commit: { message } }) {
468+
_templateCommits({ sha, html_url, author, commit: { author: { name }, message } }) {
469469
return generate({
470470
sha,
471471
message: message.split('\n')[0],
472472
url: html_url,
473-
author: login
473+
author: author && author.login,
474+
authorName: name
474475
}, this.options.template.commit);
475476
}
476477

@@ -659,10 +660,10 @@ class Gren {
659660
const ranges = await Promise.all(
660661
releaseRanges
661662
.map(async range => {
662-
const [{ date: since }, { date: until }] = range;
663+
const [{ date: until }, { date: since }] = range;
663664

664665
this.tasks[taskName].text = `Get commits between ${utils.formatDate(new Date(since))} and ${utils.formatDate(new Date(until))}`;
665-
const commits = await this._getCommitsBetweenTwo(range[1].date, range[0].date);
666+
const commits = await this._getCommitsBetweenTwo(since, until);
666667

667668
return {
668669
id: range[0].id,
@@ -977,7 +978,7 @@ class Gren {
977978
*/
978979
_createReleaseRanges(releaseDates) {
979980
const ranges = [];
980-
const range = 2;
981+
const RANGE = 2;
981982
const sortedReleaseDates = this._sortReleasesByDate(releaseDates);
982983

983984
if (sortedReleaseDates.length === 1 || this.options.tags.indexOf('all') >= 0) {
@@ -988,7 +989,15 @@ class Gren {
988989
}
989990

990991
for (let i = 0; i < sortedReleaseDates.length - 1; i++) {
991-
ranges.push(sortedReleaseDates.slice(i, i + range));
992+
// NOTE: Get one second later
993+
const until = (new Date(new Date(sortedReleaseDates[i + 1].date).getTime() + 1000).toISOString()).replace(/\.000Z$/, 'Z');
994+
ranges.push([
995+
sortedReleaseDates[i],
996+
{
997+
...sortedReleaseDates[i + RANGE - 1],
998+
date: until
999+
}
1000+
]);
9921001
}
9931002

9941003
return ranges;

lib/src/templates.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
// NOTE: check if author is present as might be returned as null.
3+
commit: ({ message, url, author, name }) => `- [${message}](${url}) - ${author ? `@${author}` : name}`,
4+
issue: '- {{labels}} {{name}} [{{text}}]({{url}})',
5+
label: '[**{{label}}**]',
6+
noLabel: 'closed',
7+
group: '\n#### {{heading}}\n',
8+
changelogTitle: '# Changelog\n\n',
9+
release: '## {{release}} ({{date}})\n{{body}}',
10+
releaseSeparator: '\n---\n\n'
11+
};

lib/src/templates.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)