Skip to content

Commit

Permalink
General fixes (#190)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexcanessa committed Oct 14, 2018
1 parent 977b97f commit 9970606
Show file tree
Hide file tree
Showing 9 changed files with 7,961 additions and 6,561 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ node_js:
- "6"
- "7.9"
- "8"

cache:
directories:
- node_modules
- "10"

before_install:
- npm install -g gulp-cli
Expand Down
20 changes: 10 additions & 10 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ The accepted file extensions are the following:
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:

{% raw %}
```json
{
```js
module.exports = {
"template": {
"commit": "- [{{message}}]({{url}}) - @{{author}}",
"issue": "- {{labels}} {{name}} [{{text}}]({{url}})",
"label": "[**{{label}}**]",
"noLabel": "closed",
"group": "\n#### {{heading}}\n",
"changelogTitle": "# Changelog\n\n",
"release": "## {{release}} ({{date}})\n{{body}}",
"releaseSeparator": "\n---\n\n"
commit: ({ message, url, author, name }) => `- [${message}](${url}) - ${author ? `@${author}` : name}`,
issue: "- {{labels}} {{name}} [{{text}}]({{url}})",
label: "[**{{label}}**]",
noLabel: "closed",
group: "\n#### {{heading}}\n",
changelogTitle: "# Changelog\n\n",
release: "## {{release}} ({{date}})\n{{body}}",
releaseSeparator: "\n---\n\n"
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const eslint = require('gulp-eslint');
const gulp = require('gulp');
const gulpIf = require('gulp-if');

gulp.task('scripts', () => {
gulp.task('scripts', done => {
gulp.src('./lib/src/**/*.js')
.pipe(babel({
presets: ['es2015']
Expand All @@ -18,6 +18,8 @@ gulp.task('scripts', () => {
.pipe(babel())
.pipe(chmod(0o755))
.pipe(gulp.dest('bin'));

done();
});

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

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

gulp.task('build', ['lint', 'scripts']);
gulp.task('default', ['build', 'watch']);
gulp.task('build', gulp.series(['lint', 'scripts']));
gulp.task('default', gulp.series(['build', 'watch']));
27 changes: 18 additions & 9 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Github from 'github-api';
import utils from './_utils.js';
import { generate } from './_template.js';
import connectivity from 'connectivity';
import templateConfig from './templates.json';
import templateConfig from './templates.js';
import ObjectAssign from 'object-assign-deep';
import fs from 'fs';

Expand Down Expand Up @@ -147,7 +147,7 @@ class Gren {

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

loaded(chalk.green(`\nChangelog created in ${filePath}`));
loaded(chalk.green(`Changelog created in ${filePath}`));
}

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

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

return release;
}
Expand Down Expand Up @@ -465,12 +465,13 @@ class Gren {
* @return {string}
*/
// eslint-disable-next-line camelcase
_templateCommits({ sha, html_url, author: { login }, commit: { message } }) {
_templateCommits({ sha, html_url, author, commit: { author: { name }, message } }) {
return generate({
sha,
message: message.split('\n')[0],
url: html_url,
author: login
author: author && author.login,
authorName: name
}, this.options.template.commit);
}

Expand Down Expand Up @@ -659,10 +660,10 @@ class Gren {
const ranges = await Promise.all(
releaseRanges
.map(async range => {
const [{ date: since }, { date: until }] = range;
const [{ date: until }, { date: since }] = range;

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

return {
id: range[0].id,
Expand Down Expand Up @@ -977,7 +978,7 @@ class Gren {
*/
_createReleaseRanges(releaseDates) {
const ranges = [];
const range = 2;
const RANGE = 2;
const sortedReleaseDates = this._sortReleasesByDate(releaseDates);

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

for (let i = 0; i < sortedReleaseDates.length - 1; i++) {
ranges.push(sortedReleaseDates.slice(i, i + range));
// NOTE: Get one second later
const until = (new Date(new Date(sortedReleaseDates[i + 1].date).getTime() + 1000).toISOString()).replace(/\.000Z$/, 'Z');
ranges.push([
sortedReleaseDates[i],
{
...sortedReleaseDates[i + RANGE - 1],
date: until
}
]);
}

return ranges;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
// NOTE: check if author is present as might be returned as null.
commit: ({ message, url, author, name }) => `- [${message}](${url}) - ${author ? `@${author}` : name}`,
issue: '- {{labels}} {{name}} [{{text}}]({{url}})',
label: '[**{{label}}**]',
noLabel: 'closed',
group: '\n#### {{heading}}\n',
changelogTitle: '# Changelog\n\n',
release: '## {{release}} ({{date}})\n{{body}}',
releaseSeparator: '\n---\n\n'
};
10 changes: 0 additions & 10 deletions lib/src/templates.json

This file was deleted.

Loading

0 comments on commit 9970606

Please sign in to comment.