fix(core): update

This commit is contained in:
2021-05-16 23:50:56 +00:00
parent 0ba352e90a
commit 7765ff77f9
11 changed files with 413 additions and 140 deletions

View File

@@ -11,23 +11,29 @@ export class GitlabAccount {
return GitlabGroup.getByName(nameArg, this);
}
/**
* handles the basic request/response patterns with the gitlab.com API
*/
public async request (methodArg: 'GET' | 'POST', routeArg: string, searchParamsArg: {[key: string]: string}) {
if(!routeArg.startsWith('/')) {
public async request(
methodArg: 'GET' | 'POST',
routeArg: string,
searchParamsArg: { [key: string]: string }
) {
if (!routeArg.startsWith('/')) {
throw new Error(`"${routeArg}" -> routeArg must start with a slash`);
}
const smarturlInstance = plugins.smarturl.Smarturl.createFromUrl(`https://gitlab.com/api/v4${routeArg}`, {
searchParams: searchParamsArg
});
const smarturlInstance = plugins.smarturl.Smarturl.createFromUrl(
`https://gitlab.com/api/v4${routeArg}`,
{
searchParams: searchParamsArg,
}
);
const response = await plugins.smartrequest.request(smarturlInstance.toString(), {
method: methodArg
method: methodArg,
});
// lets deal with pagination headers
const fintLinkName = (markup) => {
const findLinkName = (markup) => {
const pattern = /<([^\s>]+)(\s|>)+/;
return markup.match(pattern)[1];
};
@@ -37,6 +43,17 @@ export class GitlabAccount {
original: string;
link: string;
}[] = [];
for (const link of links) {
linkObjects.push({
original: link,
link: findLinkName(link)
});
}
const next = linkObjects.find(linkObject => linkObject.original.includes('rel="next"'));
if (next && response.body instanceof Array) {
const nextResponse = await this.request(methodArg, next.link.replace('https://gitlab.com/api/v4', ''), {});
response.body = response.body.concat(nextResponse);
}
}
return response.body;
}