gitlab-fetcher
Advanced tools
Comparing version 0.1.0 to 0.1.1
11
index.js
@@ -5,5 +5,5 @@ import qs from "query-string"; | ||
function fetchOnce(url, payload = undefined, method = "get") { | ||
function fetchOnce(token, url, payload = undefined, method = "get") { | ||
const headers = new Headers(); | ||
headers.append("Private-Token", config.token); | ||
headers.append("Private-Token", token); | ||
@@ -23,2 +23,3 @@ return fetch( | ||
/** | ||
* @param {String} token | ||
* @param {String} url | ||
@@ -31,6 +32,6 @@ * @param {Object} payload | ||
*/ | ||
export default function fetchGitlab(url, payload = undefined, page = 1, recursiveData = []) { | ||
export default function fetchGitlab(token, url, payload = undefined, page = 1, recursiveData = []) { | ||
let totalPages; | ||
return fetchOnce(url, { ...payload, "per_page": pageSize, page }) | ||
return fetchOnce(token, url, { ...payload, "per_page": pageSize, page }) | ||
.then(response => { | ||
@@ -48,4 +49,4 @@ totalPages = parseInt(response.headers.get("x-total-pages")); | ||
return fetchGitlab(url, payload, page + 1, recursiveData); | ||
return fetchGitlab(token, url, payload, page + 1, recursiveData); | ||
}); | ||
} |
{ | ||
"name": "gitlab-fetcher", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Simple helper to aggregate Gitlab API results across multiple pages", | ||
@@ -5,0 +5,0 @@ "author": "neemzy <tom.panier@free.fr>", |
@@ -10,5 +10,5 @@ # gitlab-fetcher | ||
const issues = fetchGitlab("/issues", { scope: "all", state: "opened" }); | ||
const issues = fetchGitlab("YourToken", "https://gitlab.url/issues", { scope: "all", state: "opened" }); | ||
``` | ||
`issues` will contain a `Promise` resolving to aggregated results from all result pages. An `Error` will be thrown in case of HTTP error (with `message` containing `response.statusText`). |
1990
39