diff --git a/packages/decap-cms-backend-github/src/API.ts b/packages/decap-cms-backend-github/src/API.ts index 95c4a15542d1..d62387ccc8c1 100644 --- a/packages/decap-cms-backend-github/src/API.ts +++ b/packages/decap-cms-backend-github/src/API.ts @@ -845,8 +845,7 @@ export default class API { } console.log( - `Done migrating Pull Request '${ - number === newNumber ? newNumber : `${number} => ${newNumber}` + `Done migrating Pull Request '${number === newNumber ? newNumber : `${number} => ${newNumber}` }'`, ); } @@ -858,6 +857,26 @@ export default class API { return cmsBranches; } + async getCmsRefs() { + const cmsPullRequestsNoLabel: GitHubPull[] = []; + const cmsPullRequests = await this.getPullRequests(undefined, PullRequestState.Open, pr => { + const hasRefSuffix = withCmsRefSuffix(pr); + if (!hasRefSuffix) return false; + + const prLabeled = withCmsLabel(pr, this.cmsLabelPrefix) + if (!prLabeled) { + cmsPullRequestsNoLabel.push(pr); + } + return true; + }); + + for (const pr of cmsPullRequestsNoLabel) { + await this.setPullRequestStatus(pr, this.initialWorkflowStatus); + } + + return cmsPullRequests.map(pr => pr.head.ref); + } + async listUnpublishedBranches() { console.log( '%c Checking for Unpublished entries', @@ -895,10 +914,8 @@ export default class API { // prCount = prCount + 1; // await this.migratePullRequest(pr, `${prCount} of ${pullRequests.length}`); // } - const cmsPullRequests = await this.getPullRequests(undefined, PullRequestState.Open, pr => - withCmsLabel(pr, this.cmsLabelPrefix), - ); - branches = cmsPullRequests.map(pr => pr.head.ref); + + branches = await this.getCmsRefs(); } return branches; @@ -1175,6 +1192,8 @@ export default class API { } async setPullRequestStatus(pullRequest: GitHubPull, newStatus: string) { + if (!newStatus) return; + const labels = [ ...pullRequest.labels .filter(label => !isCMSLabel(label.name, this.cmsLabelPrefix)) @@ -1655,6 +1674,14 @@ export default class API { this.useStack = false; } + async getStackLabel(pullRequest: GitHubPull): Promise<{ name: string }> { + const label = pullRequest.labels.find(l => isCMSLabel(l.name, this.cmsLabelPrefix)); + if (label) return label; + const initialStatus = this.initialWorkflowStatus; + await this.updateStackStatus(initialStatus); + return { name: statusToLabel(initialStatus, this.cmsLabelPrefix) }; + } + async fetchStack() { if (!this.stack) return; @@ -1665,9 +1692,7 @@ export default class API { const pullRequest = await this.getStackPullRequest(); if (!pullRequest) return; - const label = pullRequest.labels.find(l => isCMSLabel(l.name, this.cmsLabelPrefix)) as { - name: string; - }; + const label = await this.getStackLabel(pullRequest); const status = labelToStatus(label.name, this.cmsLabelPrefix); const updatedAt = pullRequest.updated_at; return { diff --git a/packages/decap-cms-core/src/actions/editorialWorkflow.ts b/packages/decap-cms-core/src/actions/editorialWorkflow.ts index 51b9ed2b7893..52c94d409add 100644 --- a/packages/decap-cms-core/src/actions/editorialWorkflow.ts +++ b/packages/decap-cms-core/src/actions/editorialWorkflow.ts @@ -335,7 +335,7 @@ export function persistUnpublishedEntry( const state = getState(); const entryDraft = customEntryDraft || state.entryDraft; const isCustomEntry = customEntryDraft && entryDraft.getIn(['entry', 'isCustomEntry'], true); - const status = customEntryDraft && customEntryDraft.getIn(['entry', 'status']); + const customEntryStatus = customEntryDraft && customEntryDraft.getIn(['entry', 'status']); const fieldsErrors = entryDraft.get('fieldsErrors'); const unpublishedSlugs = selectUnpublishedSlugs(state, collection.get('name')); const publishedSlugs = selectPublishedSlugs(state, collection.get('name')); @@ -385,7 +385,7 @@ export function persistUnpublishedEntry( assetProxies, usedSlugs, context, - status, + status: customEntryStatus, }); dispatch( addNotification({ @@ -572,6 +572,7 @@ export function publishUnpublishedEntry( export function unpublishPublishedEntry( collection: Collection, slug: string, + context: HookContext, customEntry?: EntryMap, ) { return (dispatch: ThunkDispatch, getState: () => State) => { @@ -582,7 +583,7 @@ export function unpublishPublishedEntry( const entryDraft = Map().set('entry', entry) as unknown as EntryDraft; dispatch(unpublishedEntryPersisting(collection, slug)); return backend - .deleteEntry(state, collection, slug) + .deleteEntry(state, collection, slug, context, customEntry) .then(() => { if (!backend.implementation.deleteCollectionFiles) { backend.persistEntry({ diff --git a/packages/decap-cms-core/src/actions/entries.ts b/packages/decap-cms-core/src/actions/entries.ts index 1346f9735613..18b699550b21 100644 --- a/packages/decap-cms-core/src/actions/entries.ts +++ b/packages/decap-cms-core/src/actions/entries.ts @@ -932,7 +932,7 @@ export function persistEntry( const backend = currentBackend(state.config); const entry = entryDraft.get('entry'); const isCustomEntry = customEntryDraft && entry.get('isCustomEntry', true); - const status = customEntryDraft && entry.get('status'); + const customEntryStatus = customEntryDraft && entry.get('status'); const assetProxies = getMediaAssets({ entry, }); @@ -950,7 +950,7 @@ export function persistEntry( assetProxies, usedSlugs, context, - status, + status: customEntryStatus, }) .then(async (newSlug: string) => { dispatch( @@ -1004,16 +1004,16 @@ export function deleteEntry( collection: Collection, slug: string, context: HookContext, - entry?: EntryMap, + customEntry?: EntryMap, ) { return (dispatch: ThunkDispatch, getState: () => State) => { const state = getState(); const backend = currentBackend(state.config); - const isCustomEntry = entry && entry.get('isCustomEntry', true); + const isCustomEntry = customEntry && customEntry.get('isCustomEntry', true); dispatch(entryDeleting(collection, slug)); return backend - .deleteEntry(state, collection, slug, context, entry) + .deleteEntry(state, collection, slug, context, customEntry) .then(async () => { dispatch(entryDeleted(collection, slug)); dispatch(