fix(backend-github-graphql): handle trailing paths in collection folder (#3099)

This commit is contained in:
Erez Rokah 2020-01-16 16:43:15 +02:00 committed by GitHub
parent 6a13a85e26
commit bc80804066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ import {
localForage,
DEFAULT_PR_BODY,
} from 'netlify-cms-lib-util';
import { trim } from 'lodash';
import introspectionQueryResultData from './fragmentTypes';
import API, { Config, BlobArgs, PR, API_NAME } from './API';
import * as queries from './queries';
@ -250,13 +251,14 @@ export default class GraphQLAPI extends API {
async listFiles(path: string, { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {}) {
const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
const folder = trim(path, '/');
const { data } = await this.query({
query: queries.files(depth),
variables: { owner, name, expression: `${branch}:${path}` },
variables: { owner, name, expression: `${branch}:${folder}` },
});
if (data.repository.object) {
const allFiles = this.getAllFiles(data.repository.object.entries, path);
const allFiles = this.getAllFiles(data.repository.object.entries, folder);
return allFiles;
} else {
return [];