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)) { if (!('public_folder' in config)) {
// Make sure there is a public folder // Make sure there is a public folder
config.public_folder = config.media_folder; config.public_folder = config.media_folder;

View File

@ -21,7 +21,7 @@ class Backend {
constructor(implementation, authStore = null) { constructor(implementation, authStore = null) {
this.implementation = implementation; this.implementation = implementation;
this.authStore = authStore; this.authStore = authStore;
if (this.implementation == null) { if (this.implementation === null) {
throw 'Cannot instantiate a Backend with no implementation'; throw 'Cannot instantiate a Backend with no implementation';
} }
} }
@ -103,8 +103,13 @@ class Backend {
} }
persistEntry(config, collection, entryDraft, MediaFiles) { persistEntry(config, collection, entryDraft, MediaFiles) {
const newEntry = entryDraft.getIn(['entry', 'newRecord']) || false; 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(); const entryData = entryDraft.getIn(['entry', 'data']).toJS();
let entryObj; let entryObj;
if (newEntry) { if (newEntry) {
@ -130,7 +135,9 @@ class Backend {
const collectionName = collection.get('name'); 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) { entryToRaw(collection, entry) {

View File

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