Skip to content

Commit

Permalink
Implement separate listAllEntries method for GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaiah committed May 7, 2018
1 parent 54a0355 commit be2aeed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backends/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ class Backend {
// returns all the collected entries. Used to retrieve all entries
// for local searches and queries.
async listAllEntries(collection) {
if (collection.get("folder") && this.implementation.allEntriesByFolder) {
const extension = selectFolderEntryExtension(collection);
return this.implementation.allEntriesByFolder(collection, extension)
.then(entries => this.processEntries(entries, collection));
}

const response = await this.listEntries(collection);
const { entries } = response;
let { cursor } = response;
Expand Down
18 changes: 18 additions & 0 deletions src/backends/gitlab/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ export default class API {
return { entries, cursor: this.reverseCursor(newCursor) };
};

listAllEntries = async path => {
const entries = [];
let { cursor, entries: initialEntries } = await this.fetchCursorAndEntries({
url: `${ this.repoURL }/repository/tree`,
// Get the maximum number of entries per page
params: { path, ref: this.branch, per_page: 100 },
});
entries.push(...initialEntries);
while (cursor && cursor.actions.includes("next")) {
const link = cursor.data.links["next"];
const { cursor: newCursor, entries: newEntries } = await this.fetchCursorAndEntries(link);
entries.push(...newEntries);
cursor = newCursor;
console.log({ cursor, entries });
}
return entries;
};

toBase64 = str => Promise.resolve(Base64.encode(str));
fromBase64 = str => Base64.decode(str);
uploadAndCommit = async (item, { commitMessage, updateFile = false, branch = this.branch }) => {
Expand Down
5 changes: 5 additions & 0 deletions src/backends/gitlab/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default class GitLab {
);
}

allEntriesByFolder(collection, extension) {
return this.api.listAllEntries(collection.get("folder"), extension)
.then(files => this.fetchFiles(files.filter(file => fileExtension(file.name) === extension)));
}

entriesByFiles(collection) {
const files = collection.get("files").map(collectionFile => ({
path: collectionFile.get("file"),
Expand Down

0 comments on commit be2aeed

Please sign in to comment.