feat(backend-github): Open Authoring (#2430)

* Make filterPromises resolve entries before filtering

* Add filterPromisesWith & onlySuccessfulPromises to utility library

* Memoize user method in GitHub API

* Make storeMetadata safe to call concurrently in GitHub API

* Fork workflow: startup and authentication

* Fork workflow: backend support

* Fork workflow: disable unused UI elements

* Fork workflow: docs

* Fork workflow: fix deploy previews

* Suggested edits for fork workflow doc

* Change future tense to present

* Fork workflow: add beta status to docs

* remove debug statement

* rename fork workflow to Open Authoring
This commit is contained in:
Benaiah Mischenko
2019-07-24 15:20:41 -07:00
committed by Shawn Erquhart
parent 41559256d0
commit edf0a3afdc
16 changed files with 729 additions and 219 deletions

View File

@ -3,7 +3,13 @@ import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from './Cursor';
import EditorialWorkflowError, { EDITORIAL_WORKFLOW_ERROR } from './EditorialWorkflowError';
import localForage from './localForage';
import { resolvePath, basename, fileExtensionWithSeparator, fileExtension } from './path';
import { filterPromises, resolvePromiseProperties, then } from './promise';
import {
filterPromises,
filterPromisesWith,
onlySuccessfulPromises,
resolvePromiseProperties,
then,
} from './promise';
import unsentRequest from './unsentRequest';
import { filterByPropExtension, parseResponse, responseParser } from './backendUtil';
import loadScript from './loadScript';
@ -21,6 +27,8 @@ export const NetlifyCmsLibUtil = {
fileExtensionWithSeparator,
fileExtension,
filterPromises,
filterPromisesWith,
onlySuccessfulPromises,
resolvePromiseProperties,
then,
unsentRequest,
@ -42,6 +50,8 @@ export {
fileExtensionWithSeparator,
fileExtension,
filterPromises,
filterPromisesWith,
onlySuccessfulPromises,
resolvePromiseProperties,
then,
unsentRequest,

View File

@ -1,7 +1,15 @@
import constant from 'lodash/constant';
import filter from 'lodash/fp/filter';
import map from 'lodash/fp/map';
import flow from 'lodash/flow';
import zipObject from 'lodash/zipObject';
export const filterPromises = (arr, filter) =>
Promise.all(arr.map(entry => filter(entry))).then(bits => arr.filter(() => bits.shift()));
Promise.all(arr.map(entry => Promise.resolve(entry).then(filter))).then(bits =>
arr.filter(() => bits.shift()),
);
export const filterPromisesWith = filter => arr => filterPromises(arr, filter);
export const resolvePromiseProperties = obj => {
// Get the keys which represent promises
@ -18,3 +26,10 @@ export const resolvePromiseProperties = obj => {
};
export const then = fn => p => Promise.resolve(p).then(fn);
const filterPromiseSymbol = Symbol('filterPromiseSymbol');
export const onlySuccessfulPromises = flow([
then(map(p => p.catch(constant(filterPromiseSymbol)))),
then(Promise.all.bind(Promise)),
then(filter(maybeValue => maybeValue !== filterPromiseSymbol)),
]);