Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions packages/decap-cms-backend-github/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}'`,
);
}
Expand All @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions packages/decap-cms-core/src/actions/editorialWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -385,7 +385,7 @@ export function persistUnpublishedEntry(
assetProxies,
usedSlugs,
context,
status,
status: customEntryStatus,
});
dispatch(
addNotification({
Expand Down Expand Up @@ -572,6 +572,7 @@ export function publishUnpublishedEntry(
export function unpublishPublishedEntry(
collection: Collection,
slug: string,
context: HookContext,
customEntry?: EntryMap,
) {
return (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
Expand All @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not directly related with the PR just a fix on deleteEntry workflow which currently is not working properly

.then(() => {
if (!backend.implementation.deleteCollectionFiles) {
backend.persistEntry({
Expand Down
10 changes: 5 additions & 5 deletions packages/decap-cms-core/src/actions/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -950,7 +950,7 @@ export function persistEntry(
assetProxies,
usedSlugs,
context,
status,
status: customEntryStatus,
})
.then(async (newSlug: string) => {
dispatch(
Expand Down Expand Up @@ -1004,16 +1004,16 @@ export function deleteEntry(
collection: Collection,
slug: string,
context: HookContext,
entry?: EntryMap,
customEntry?: EntryMap,
) {
return (dispatch: ThunkDispatch<State, {}, AnyAction>, 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(
Expand Down
Loading