Skip to content
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
23 changes: 18 additions & 5 deletions src/gitlab-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ import {requestUrl, RequestUrlParam, RequestUrlResponse} from 'obsidian';

export default class GitlabApi {

static load<T>(url: string, gitlabToken: string): Promise<T> {
static load<T>(url: string, gitlabToken: string, page?: string): Promise<T> {

const headers = { 'PRIVATE-TOKEN': gitlabToken };
let req_url: string;

const params: RequestUrlParam = { url: url, headers: headers };

if (!!page) {
req_url = `${url}&page=${page}`;
} else {
req_url = url;
}

const params: RequestUrlParam = { url: req_url, headers: headers };

return requestUrl(params)
.then((response: RequestUrlResponse) => {
if (response.status !== 200) {
throw new Error(response.text);
}

return response.json as Promise<T>;
});
if ("x-next-page" in response.headers && response.headers["x-next-page"] != "") {
return GitlabApi.load(url, gitlabToken, response.headers["x-next-page"]).then((j) => {
return response.json.concat(j) as Promise<T>;
}) as Promise<T>;
} else {
return response.json as Promise<T>;
}
});
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just going to keep retrieving page after page of results? What happens if there are thousands of results?

Is is not better to specify the max number of results in the main filter query?

}
}
7 changes: 6 additions & 1 deletion src/settings.ts
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use-case for changing this URL please?

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export const DEFAULT_SETTINGS: GitlabIssuesSettings = {
filter: 'due_date=month',
showIcon: false,
gitlabApiUrl(): string {
return `${this.gitlabUrl}/api/v4`;
if (this.gitlabUrl.indexOf('/api/') != -1) {
// Full path to API (might be a project specific URL
return this.gitlabUrl;
} else {
return `${this.gitlabUrl}/api/v4`;
}
}
};

Expand Down