Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GitLab workspace integration #1523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Fixed GitLab workspace integration
Changed getTree to a recursive function so it iterates through all pages of the GitLab API's response when fetching the tree.
  • Loading branch information
ProbablyFaiz committed Jul 27, 2019
commit e0e60c12743951eb101f067d073197e069c4aeec
2 changes: 2 additions & 0 deletions src/services/providers/gitlabWorkspaceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default new Provider({
return gitlabHelper.getTree({
...store.getters['workspace/currentWorkspace'],
token: this.getToken(),
existingBody: [],
page: 1,
});
},
prepareChanges(tree) {
Expand Down
30 changes: 25 additions & 5 deletions src/services/providers/helpers/gitlabHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import store from '../../../store';
import userSvc from '../../userSvc';
import badgeSvc from '../../badgeSvc';

const request = ({ accessToken, serverUrl }, options) => networkSvc.request({
const fullRequest = ({ accessToken, serverUrl }, options) => networkSvc.request({
...options,
url: `${serverUrl}/api/v4/${options.url}`,
headers: {
...options.headers || {},
Authorization: `Bearer ${accessToken}`,
},
})
.then(res => res.body);
});

const request = ({ accessToken, serverUrl }, options) => fullRequest({
accessToken,
serverUrl,
}, options).then(res => res.body);

const getCommitMessage = (name, path) => {
const message = store.getters['data/computedSettings'].git[name];
Expand Down Expand Up @@ -114,18 +118,34 @@ export default {
* https://docs.gitlab.com/ee/api/repositories.html#list-repository-tree
*/
async getTree({
existingBody, // Used for recursive requests, intially empty
token,
projectId,
branch,
page,
}) {
return request(token, {
const pageResponse = await fullRequest(token, {
url: `projects/${encodeURIComponent(projectId)}/repository/tree`,
params: {
ref: branch,
recursive: true,
per_page: 9999,
per_page: 100,
page,
},
});
const combinedBody = pageResponse.body.concat(existingBody);
const nextPage = new Headers(pageResponse.headers).get('X-Next-Page');
// eslint-disable-next-line eqeqeq
if (nextPage == '') {
return combinedBody;
}
return this.getTree({
existingBody: combinedBody,
token,
projectId,
branch,
page: nextPage,
});
},

/**
Expand Down