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 18, 2018
1 parent d58231c commit 8b07d6d
Show file tree
Hide file tree
Showing 3 changed files with 28 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
17 changes: 17 additions & 0 deletions src/backends/gitlab/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ 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;
}
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 8b07d6d

Please sign in to comment.