From 6b1e96b302a2f283e448a7d44e58a613f535ea6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info> Date: Sat, 16 Apr 2016 15:10:27 +0200 Subject: [PATCH] Creation date from 1st merge request Configuration option (config.toml): [git] mergeMessage = "array or string" --- sitegin/config.js | 1 - sitegin/gitInfo.js | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sitegin/config.js b/sitegin/config.js index aea78ef..a6417e9 100644 --- a/sitegin/config.js +++ b/sitegin/config.js @@ -51,7 +51,6 @@ module.exports = function() { return resolve({config: config}); } data = toml.parse(data); - console.log('data: '+data); for(let attr in config) { data[attr] = config[attr]; } resolve({config: data}); }) diff --git a/sitegin/gitInfo.js b/sitegin/gitInfo.js index b3f085b..05f47d3 100644 --- a/sitegin/gitInfo.js +++ b/sitegin/gitInfo.js @@ -58,7 +58,7 @@ var gitlog = function(repo) { 'email': author.email() }, 'date': commit.date(), - 'message': commit.message().trim() + 'message': commit.message() }; }; }); @@ -82,7 +82,10 @@ var gitlog = function(repo) { }); }; -var getFilesHistory = function(repo) { +var getFilesHistory = function(repo, startCommitMessage) { + if(!Array.isArray(startCommitMessage) && startCommitMessage !== undefined) { + startCommitMessage = [startCommitMessage]; + } return Promise.resolve() .then(function() { return gitlog(repo) @@ -109,6 +112,31 @@ var getFilesHistory = function(repo) { }); }); return filehistory; + }) + .then(function(log) { + if(startCommitMessage === undefined) return log; + var newLog = {}; + function filterCommits(commits) { + var r = []; + commits.reverse(); + var matched = false; + commits.forEach(function(commit) { + if(!matched) + startCommitMessage.forEach(function(matcher) { + if(commit.message.indexOf(matcher) > -1) matched = true; + }) + if(matched) { + r.push(commit); + } + }) + r.reverse(); + if(r.length < 1) return undefined; + return r; + } + for(var file in log) { + newLog[file] = filterCommits(log[file]); + } + return newLog; }); } @@ -120,7 +148,9 @@ module.exports = function(obj) { .catch(function() { resolve(obj); }) - .then(getFilesHistory) + .then(function(repo) { + return getFilesHistory(repo, obj.config.git.mergeMessage); + }) .then((filesHistory) => { obj.pages.forEach(function(article) { var file = path.relative(pathToRepo, article.filename); @@ -149,6 +179,8 @@ module.exports = function(obj) { article.metadata.author.email = oldestCommit.author.email article.commits = commits; + } else { + console.log('[Warning] Article '+ file +' is not in git repository or doesn\'t have merge commit'); } }); return obj; -- GitLab