Skip to content

Commit

Permalink
First steps for commit logs on the release page :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanaye committed Feb 3, 2017
1 parent 878093b commit a89cd5d
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions build/tasks/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = function (grunt) {
var gitUser = process.env.GIT_USER;
var gitPassword = process.env.GIT_PASSWORD;
var gitEmail = process.env.GIT_EMAIL;
var releaseNotes;

function getMasterCommit (repo) {
return repo.getMasterCommit();
Expand Down Expand Up @@ -65,7 +66,9 @@ module.exports = function (grunt) {
newContent = JSON.parse(blobs[0].toString('utf-8'));
oldContent = JSON.parse(blobs[1].toString('utf-8'));
if (newContent.version != oldContent.version) {
return true;
return buildReleaseNotes(repo, oldContent.version).then(function () {
return true;
});
}
return false;
}).then(function (versionChanged) {
Expand Down Expand Up @@ -157,11 +160,11 @@ module.exports = function (grunt) {
}).then(function (parent) {
return repository.createCommit('HEAD', author, author, '[ci skip] Build Version ' + version, oid, [parent]);
}).then(function (id) {
grunt.log.writeln('Created commit ' + id + 'for ' + version);
grunt.log.writeln('Created commit ' + id + ' for ' + version);
return Git.Object.lookup(repository, id, Git.Object.TYPE.COMMIT);
})
.then(function (object) {
return Git.Tag.create(repository, version, object, author, 'Release v'+version, 0); // 0 = don't force tag creation
return Git.Tag.annotationCreate(repository, version, object, author, 'Release v'+version); // 0 = don't force tag creation
}).then(function () {
grunt.log.writeln('Created tag ' + version);
return repository.getRemote('origin');
Expand All @@ -186,6 +189,33 @@ module.exports = function (grunt) {
});
}

function buildReleaseNotes (repository, version) {
releaseNotes = '### Release ' + grunt.config.data.version + '\n Commits: \n';
return repository.getReferenceCommit(version).then(function (targetCommit) {
return getMasterCommit(repository).then(function (masterCommit) {
return new Promise(function (resolve) {
var history = masterCommit.history(Git.Revwalk.SORT.TIME);
history.on('end', function (commits) {
for (var i = 0; i < commits.length; i++) {
var commit = commits[i];
if (commit.id().toString() == targetCommit.id().toString()) {
break;
}

if (process.env.TRAVIS_REPO_SLUG) {
releaseNotes += '* [[`' + commit.sha() + '`](https://github.com/' + process.env.TRAVIS_REPO_SLUG + 'commit/' + commit.sha() +')] - ' + commit.summary() + '\n';
} else {
releaseNotes += '* [`' + commit.sha() + '`] - ' + commit.summary() + '\n';
}
}
resolve();
});
history.start();
});
});
});
}

function publishNpm () {
var cwd = process.cwd();
process.chdir(require('path').join(cwd, 'dist/npm'));
Expand Down

0 comments on commit a89cd5d

Please sign in to comment.