diff --git a/src/actions/editorialWorkflow.js b/src/actions/editorialWorkflow.js
index 5ec74c54..c1cc0ffa 100644
--- a/src/actions/editorialWorkflow.js
+++ b/src/actions/editorialWorkflow.js
@@ -271,6 +271,27 @@ export function updateUnpublishedEntryStatus(collection, slug, oldStatus, newSta
};
}
+export function deleteUnpublishedEntry(collection, slug) {
+ return (dispatch, getState) => {
+ const state = getState();
+ const backend = currentBackend(state.config);
+ const transactionID = uuid.v4();
+ dispatch(unpublishedEntryPublishRequest(collection, slug, transactionID));
+ backend.deleteUnpublishedEntry(collection, slug)
+ .then(() => {
+ dispatch(unpublishedEntryPublished(collection, slug, transactionID));
+ })
+ .catch((error) => {
+ dispatch(notifSend({
+ message: `Failed to close PR: ${ error }`,
+ kind: 'danger',
+ dismissAfter: 8000,
+ }));
+ dispatch(unpublishedEntryPublishError(collection, slug, transactionID));
+ });
+ };
+}
+
export function publishUnpublishedEntry(collection, slug) {
return (dispatch, getState) => {
const state = getState();
diff --git a/src/backends/backend.js b/src/backends/backend.js
index 5d7f81f5..49ed91e9 100644
--- a/src/backends/backend.js
+++ b/src/backends/backend.js
@@ -200,6 +200,9 @@ class Backend {
return this.implementation.publishUnpublishedEntry(collection, slug);
}
+ deleteUnpublishedEntry(collection, slug) {
+ return this.implementation.deleteUnpublishedEntry(collection, slug);
+ }
entryToRaw(collection, entry) {
const format = resolveFormat(collection, entry.toJS());
diff --git a/src/backends/github/API.js b/src/backends/github/API.js
index 8be0b043..aad6cea9 100644
--- a/src/backends/github/API.js
+++ b/src/backends/github/API.js
@@ -314,6 +314,14 @@ export default class API {
.then(updatedMetadata => this.storeMetadata(contentKey, updatedMetadata));
}
+ deleteUnpublishedEntry(collection, slug) {
+ const contentKey = slug;
+ let prNumber;
+ return this.retrieveMetadata(contentKey)
+ .then(metadata => this.closePR(metadata.pr, metadata.objects))
+ .then(() => this.deleteBranch(`cms/${ contentKey }`));
+ }
+
publishUnpublishedEntry(collection, slug) {
const contentKey = slug;
let prNumber;
@@ -367,6 +375,18 @@ export default class API {
});
}
+ closePR(pullrequest, objects) {
+ const headSha = pullrequest.head;
+ const prNumber = pullrequest.number;
+ console.log("%c Deleting PR", "line-height: 30px;text-align: center;font-weight: bold"); // eslint-disable-line
+ return this.request(`${ this.repoURL }/pulls/${ prNumber }`, {
+ method: "PATCH",
+ body: JSON.stringify({
+ state: closed,
+ }),
+ });
+ }
+
mergePR(pullrequest, objects) {
const headSha = pullrequest.head;
const prNumber = pullrequest.number;
diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js
index 74340dc3..87818864 100644
--- a/src/backends/github/implementation.js
+++ b/src/backends/github/implementation.js
@@ -135,6 +135,9 @@ export default class GitHub {
return this.api.updateUnpublishedEntryStatus(collection, slug, newStatus);
}
+ deleteUnpublishedEntry(collection, slug) {
+ return this.api.deleteUnpublishedEntry(collection, slug);
+ }
publishUnpublishedEntry(collection, slug) {
return this.api.publishUnpublishedEntry(collection, slug);
}
diff --git a/src/components/UnpublishedListing/UnpublishedListing.js b/src/components/UnpublishedListing/UnpublishedListing.js
index 9df02dab..66266b8b 100644
--- a/src/components/UnpublishedListing/UnpublishedListing.js
+++ b/src/components/UnpublishedListing/UnpublishedListing.js
@@ -13,6 +13,7 @@ class UnpublishedListing extends React.Component {
entries: ImmutablePropTypes.orderedMap,
handleChangeStatus: PropTypes.func.isRequired,
handlePublish: PropTypes.func.isRequired,
+ handleDelete: PropTypes.func.isRequired,
};
handleChangeStatus = (newStatus, dragProps) => {
@@ -22,6 +23,11 @@ class UnpublishedListing extends React.Component {
this.props.handleChangeStatus(collection, slug, oldStatus, newStatus);
};
+ requestDelete = (collection, slug, ownStatus) => {
+ if (window.confirm('Are you sure you want to delete this entry?')) {
+ this.props.handleDelete(collection, slug, ownStatus);
+ }
+ };
requestPublish = (collection, slug, ownStatus) => {
if (ownStatus !== status.last()) return;
if (window.confirm('Are you sure you want to publish this entry?')) {
@@ -82,6 +88,10 @@ class UnpublishedListing extends React.Component {
+
{
(ownStatus === status.last() && !entry.get('isPersisting', false)) &&