Commit 664b1330 authored by Isabella Skořepová's avatar Isabella Skořepová

Fix build without repository in content

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