Skip to content
Snippets Groups Projects
Verified Commit 664b1330 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Fix build without repository in content

Fixes CI builds
parent 4a4febca
No related branches found
No related tags found
No related merge requests found
Pipeline #
'use strict';
/* /*
* Add date: {creation, modification, modified} and author: {name, email} * Add date: {creation, modification, modified} and author: {name, email}
* to metadata if not already present * to metadata if not already present
...@@ -7,8 +8,6 @@ var nodegit = require('nodegit'); ...@@ -7,8 +8,6 @@ var nodegit = require('nodegit');
var path = require('path'); var path = require('path');
var moment = require('moment'); var moment = require('moment');
var pathToRepo;
// Returns promise for patch of single commit // Returns promise for patch of single commit
var gitShow = function(repo, commitData) { var gitShow = function(repo, commitData) {
var commit, tree, parentTree; var commit, tree, parentTree;
...@@ -83,11 +82,9 @@ var gitlog = function(repo) { ...@@ -83,11 +82,9 @@ var gitlog = function(repo) {
}); });
}; };
var getFilesHistory = function() { var getFilesHistory = function(repo) {
var repo; return Promise.resolve()
return nodegit.Repository.open(pathToRepo) .then(function() {
.then(function(_repo) {
repo = _repo;
return gitlog(repo) return gitlog(repo)
}) })
.then(function(log){ .then(function(log){
...@@ -117,38 +114,50 @@ var getFilesHistory = function() { ...@@ -117,38 +114,50 @@ var getFilesHistory = function() {
module.exports = function(obj) { module.exports = function(obj) {
console.log('Build step: GitInfo'); console.log('Build step: GitInfo');
pathToRepo = path.resolve(obj.config.sourceDir); let pathToRepo = path.resolve(obj.config.sourceDir);
return getFilesHistory() return new Promise(function(resolve,reject) {
.then((filesHistory) => { return nodegit.Repository.open(pathToRepo)
obj.pages.forEach(function(article) { .catch(function() {
var file = path.relative(pathToRepo, article.filename); resolve(obj);
var commits = filesHistory[file]; })
if(commits !== undefined) { .then(getFilesHistory)
commits.sort(function(a,b){ .then((filesHistory) => {
return b.date - a.date; obj.pages.forEach(function(article) {
}); var file = path.relative(pathToRepo, article.filename);
var newestCommit = commits[0]; var commits = filesHistory[file];
var oldestCommit = commits[commits.length-1]; if(commits !== undefined) {
commits.sort(function(a,b){
return b.date - a.date;
});
var newestCommit = commits[0];
var oldestCommit = commits[commits.length-1];
if(article.metadata.date === undefined) if(article.metadata.date === undefined)
article.metadata.date = {}; article.metadata.date = {};
if(article.metadata.date.creation === undefined) if(article.metadata.date.creation === undefined)
article.metadata.date.creation = oldestCommit.date; article.metadata.date.creation = oldestCommit.date;
article.metadata.date.modification = newestCommit.date; article.metadata.date.modification = newestCommit.date;
article.metadata.date.modified = (newestCommit !== oldestCommit); article.metadata.date.modified = (newestCommit !== oldestCommit);
if(article.metadata.author === undefined) if(article.metadata.author === undefined)
article.metadata.author = {} article.metadata.author = {}
if(article.metadata.author.name === undefined) if(article.metadata.author.name === undefined)
article.metadata.author.name = oldestCommit.author.name article.metadata.author.name = oldestCommit.author.name
if(article.metadata.author.email === undefined) if(article.metadata.author.email === undefined)
article.metadata.author.email = oldestCommit.author.email article.metadata.author.email = oldestCommit.author.email
article.commits = commits; article.commits = commits;
} }
});
return obj;
})
.then(function(o) {
resolve(o);
})
.catch(function(e){
reject(e);
}); });
return obj;
}) })
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment