From e852991954f477d6d1a55db29dbdd7c84d2f5f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20Zen?= Date: Mon, 5 Sep 2016 12:12:38 -0300 Subject: [PATCH] Storing more complete commit information on branch metadata --- src/actions/config.js | 5 +++++ src/backends/backend.js | 13 ++++++++++--- src/backends/github/API.js | 25 ++++++++++++++++++------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/actions/config.js b/src/actions/config.js index 00082c97..57a51510 100644 --- a/src/actions/config.js +++ b/src/actions/config.js @@ -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; diff --git a/src/backends/backend.js b/src/backends/backend.js index 43e00126..cafcf668 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -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) { diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 13025037..7c4de494 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -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);