Storing more complete commit information on branch metadata

This commit is contained in:
Cássio Zen 2016-09-05 12:12:38 -03:00
parent 4a55bb0296
commit e852991954
3 changed files with 33 additions and 10 deletions

View File

@ -70,6 +70,11 @@ function parseConfig(data) {
}
}
if (!('publish_mode' in config.backend)) {
// Make sure there is a publish mode
config.backend['publish_mode'] = 'simple';
}
if (!('public_folder' in config)) {
// Make sure there is a public folder
config.public_folder = config.media_folder;

View File

@ -21,7 +21,7 @@ class Backend {
constructor(implementation, authStore = null) {
this.implementation = implementation;
this.authStore = authStore;
if (this.implementation == null) {
if (this.implementation === null) {
throw 'Cannot instantiate a Backend with no implementation';
}
}
@ -103,8 +103,13 @@ class Backend {
}
persistEntry(config, collection, entryDraft, MediaFiles) {
const newEntry = entryDraft.getIn(['entry', 'newRecord']) || false;
const parsedData = {
title: entryDraft.getIn(['entry', 'data', 'title'], 'No Title'),
description: entryDraft.getIn(['entry', 'data', 'description'], 'No Description'),
};
const entryData = entryDraft.getIn(['entry', 'data']).toJS();
let entryObj;
if (newEntry) {
@ -130,7 +135,9 @@ class Backend {
const collectionName = collection.get('name');
return this.implementation.persistEntry(entryObj, MediaFiles, { newEntry, commitMessage, collectionName, mode });
return this.implementation.persistEntry(entryObj, MediaFiles, {
newEntry, parsedData, commitMessage, collectionName, mode
});
}
entryToRaw(collection, entry) {

View File

@ -101,7 +101,7 @@ export default class API {
});
return result;
});
});
}).catch(error => null);
}
readFile(path, sha) {
@ -132,10 +132,13 @@ export default class API {
persistFiles(entry, mediaFiles, options) {
let filename, part, parts, subtree;
const fileTree = {};
const files = [];
mediaFiles.concat(entry).forEach((file) => {
const uploadPromises = [];
const files = mediaFiles.concat(entry);
files.forEach((file) => {
if (file.uploaded) { return; }
files.push(this.uploadBlob(file));
uploadPromises.push(this.uploadBlob(file));
parts = file.path.split('/').filter((part) => part);
filename = parts.pop();
subtree = fileTree;
@ -146,15 +149,23 @@ export default class API {
subtree[filename] = file;
file.file = true;
});
return Promise.all(files)
return Promise.all(uploadPromises)
.then(() => this.getBranch())
.then(branchData => this.updateTree(branchData.commit.sha, '/', fileTree))
.then(changeTree => this.commit(options.commitMessage, changeTree))
.then((response) => {
if (options.mode && options.mode === BRANCH) {
const contentKey = options.collectionName ? `${options.collectionName}-${entry.slug}` : entry.slug;
return this.createBranch(`cms/${contentKey}`, response.sha)
.then(this.storeMetadata(contentKey, { status: 'draft' }))
const branchName = `cms/${contentKey}`;
return this.createBranch(branchName, response.sha)
.then(this.storeMetadata(contentKey, {
type: 'PR',
status: 'draft',
branch: branchName,
title: options.parsedData.title,
description: options.parsedData.description,
objects: files.map(file => file.path)
}))
.then(this.createPR(options.commitMessage, `cms/${contentKey}`));
} else {
return this.patchBranch(this.branch, response.sha);