2021-11-26 20:57:51 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
|
2022-04-04 21:27:01 +08:00
|
|
|
const VERSION = "2.17.0";
|
|
|
|
|
|
|
|
function ownKeys(object, enumerableOnly) {
|
|
|
|
var keys = Object.keys(object);
|
|
|
|
|
|
|
|
if (Object.getOwnPropertySymbols) {
|
|
|
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
|
|
|
|
|
|
if (enumerableOnly) {
|
|
|
|
symbols = symbols.filter(function (sym) {
|
|
|
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
keys.push.apply(keys, symbols);
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _objectSpread2(target) {
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
|
|
|
|
|
|
if (i % 2) {
|
|
|
|
ownKeys(Object(source), true).forEach(function (key) {
|
|
|
|
_defineProperty(target, key, source[key]);
|
|
|
|
});
|
|
|
|
} else if (Object.getOwnPropertyDescriptors) {
|
|
|
|
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
|
|
} else {
|
|
|
|
ownKeys(Object(source)).forEach(function (key) {
|
|
|
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _defineProperty(obj, key, value) {
|
|
|
|
if (key in obj) {
|
|
|
|
Object.defineProperty(obj, key, {
|
|
|
|
value: value,
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true,
|
|
|
|
writable: true
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
obj[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
2021-11-26 20:57:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Some “list” response that can be paginated have a different response structure
|
|
|
|
*
|
|
|
|
* They have a `total_count` key in the response (search also has `incomplete_results`,
|
|
|
|
* /installation/repositories also has `repository_selection`), as well as a key with
|
|
|
|
* the list of the items which name varies from endpoint to endpoint.
|
|
|
|
*
|
|
|
|
* Octokit normalizes these responses so that paginated results are always returned following
|
|
|
|
* the same structure. One challenge is that if the list response has only one page, no Link
|
|
|
|
* header is provided, so this header alone is not sufficient to check wether a response is
|
|
|
|
* paginated or not.
|
|
|
|
*
|
|
|
|
* We check if a "total_count" key is present in the response data, but also make sure that
|
|
|
|
* a "url" property is not, as the "Get the combined status for a specific ref" endpoint would
|
|
|
|
* otherwise match: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
|
|
|
|
*/
|
|
|
|
function normalizePaginatedListResponse(response) {
|
2022-04-04 21:27:01 +08:00
|
|
|
// endpoints can respond with 204 if repository is empty
|
|
|
|
if (!response.data) {
|
|
|
|
return _objectSpread2(_objectSpread2({}, response), {}, {
|
|
|
|
data: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-26 20:57:51 +08:00
|
|
|
const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data);
|
|
|
|
if (!responseNeedsNormalization) return response; // keep the additional properties intact as there is currently no other way
|
|
|
|
// to retrieve the same information.
|
|
|
|
|
|
|
|
const incompleteResults = response.data.incomplete_results;
|
|
|
|
const repositorySelection = response.data.repository_selection;
|
|
|
|
const totalCount = response.data.total_count;
|
|
|
|
delete response.data.incomplete_results;
|
|
|
|
delete response.data.repository_selection;
|
|
|
|
delete response.data.total_count;
|
|
|
|
const namespaceKey = Object.keys(response.data)[0];
|
|
|
|
const data = response.data[namespaceKey];
|
|
|
|
response.data = data;
|
|
|
|
|
|
|
|
if (typeof incompleteResults !== "undefined") {
|
|
|
|
response.data.incomplete_results = incompleteResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof repositorySelection !== "undefined") {
|
|
|
|
response.data.repository_selection = repositorySelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
response.data.total_count = totalCount;
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
function iterator(octokit, route, parameters) {
|
|
|
|
const options = typeof route === "function" ? route.endpoint(parameters) : octokit.request.endpoint(route, parameters);
|
|
|
|
const requestMethod = typeof route === "function" ? route : octokit.request;
|
|
|
|
const method = options.method;
|
|
|
|
const headers = options.headers;
|
|
|
|
let url = options.url;
|
|
|
|
return {
|
|
|
|
[Symbol.asyncIterator]: () => ({
|
|
|
|
async next() {
|
|
|
|
if (!url) return {
|
|
|
|
done: true
|
|
|
|
};
|
2022-04-04 21:27:01 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await requestMethod({
|
|
|
|
method,
|
|
|
|
url,
|
|
|
|
headers
|
|
|
|
});
|
|
|
|
const normalizedResponse = normalizePaginatedListResponse(response); // `response.headers.link` format:
|
|
|
|
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"'
|
|
|
|
// sets `url` to undefined if "next" URL is not present or `link` header is not set
|
|
|
|
|
|
|
|
url = ((normalizedResponse.headers.link || "").match(/<([^>]+)>;\s*rel="next"/) || [])[1];
|
|
|
|
return {
|
|
|
|
value: normalizedResponse
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
if (error.status !== 409) throw error;
|
|
|
|
url = "";
|
|
|
|
return {
|
|
|
|
value: {
|
|
|
|
status: 200,
|
|
|
|
headers: {},
|
|
|
|
data: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-11-26 20:57:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function paginate(octokit, route, parameters, mapFn) {
|
|
|
|
if (typeof parameters === "function") {
|
|
|
|
mapFn = parameters;
|
|
|
|
parameters = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gather(octokit, [], iterator(octokit, route, parameters)[Symbol.asyncIterator](), mapFn);
|
|
|
|
}
|
|
|
|
|
|
|
|
function gather(octokit, results, iterator, mapFn) {
|
|
|
|
return iterator.next().then(result => {
|
|
|
|
if (result.done) {
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
let earlyExit = false;
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
earlyExit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
results = results.concat(mapFn ? mapFn(result.value, done) : result.value.data);
|
|
|
|
|
|
|
|
if (earlyExit) {
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gather(octokit, results, iterator, mapFn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const composePaginateRest = Object.assign(paginate, {
|
|
|
|
iterator
|
|
|
|
});
|
|
|
|
|
2022-04-04 21:27:01 +08:00
|
|
|
const paginatingEndpoints = ["GET /app/hook/deliveries", "GET /app/installations", "GET /applications/grants", "GET /authorizations", "GET /enterprises/{enterprise}/actions/permissions/organizations", "GET /enterprises/{enterprise}/actions/runner-groups", "GET /enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/organizations", "GET /enterprises/{enterprise}/actions/runner-groups/{runner_group_id}/runners", "GET /enterprises/{enterprise}/actions/runners", "GET /enterprises/{enterprise}/actions/runners/downloads", "GET /events", "GET /gists", "GET /gists/public", "GET /gists/starred", "GET /gists/{gist_id}/comments", "GET /gists/{gist_id}/commits", "GET /gists/{gist_id}/forks", "GET /installation/repositories", "GET /issues", "GET /marketplace_listing/plans", "GET /marketplace_listing/plans/{plan_id}/accounts", "GET /marketplace_listing/stubbed/plans", "GET /marketplace_listing/stubbed/plans/{plan_id}/accounts", "GET /networks/{owner}/{repo}/events", "GET /notifications", "GET /organizations", "GET /orgs/{org}/actions/permissions/repositories", "GET /orgs/{org}/actions/runner-groups", "GET /orgs/{org}/actions/runner-groups/{runner_group_id}/repositories", "GET /orgs/{org}/actions/runner-groups/{runner_group_id}/runners", "GET /orgs/{org}/actions/runners", "GET /orgs/{org}/actions/runners/downloads", "GET /orgs/{org}/actions/secrets", "GET /orgs/{org}/actions/secrets/{secret_name}/repositories", "GET /orgs/{org}/blocks", "GET /orgs/{org}/credential-authorizations", "GET /orgs/{org}/events", "GET /orgs/{org}/failed_invitations", "GET /orgs/{org}/hooks", "GET /orgs/{org}/hooks/{hook_id}/deliveries", "GET /orgs/{org}/installations", "GET /orgs/{org}/invitations", "GET /orgs/{org}/invitations/{invitation_id}/teams", "GET /orgs/{org}/issues", "GET /orgs/{org}/members", "GET /orgs/{org}/migrations", "GET /orgs/{org}/migrations/{migration_id}/repositories", "GET /orgs/{org}/outside_collaborators", "GET /orgs/{org}/packages", "GET /orgs/{org}/projects", "GET /orgs/{org}/public_members", "GET /orgs/{org}/repos", "GET /orgs/{org}/secret-scanning/alerts", "GET /orgs/{org}/team-sync/groups", "GET /orgs/{org}/teams", "GET /orgs/{org}/teams/{team_slug}/discussions", "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments", "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number}/reactions", "GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/reactions", "GET /orgs/{org}/teams/{team_slug}/invitations", "GET /orgs/{org}/teams/{team_slug}/members", "GET /orgs/{org}/teams/{team_slug}/projects", "GET /orgs/{org}/teams/{team_slug}/repos", "GET /orgs/{org}/teams/{team_slug}/team-sync/group-mappings", "GET /orgs/{org}/teams/{team_slug}/teams", "GET /projects/columns/{column_id}/cards", "GET /projects/{project_id}/collaborators", "GET /projects/{project_id}/columns", "GET /repos/{owner}/{repo}/actions/artifacts", "GET /repos/{owner}/{repo}/actions/runners", "GET /repos/{owner}/{repo}/actions/runners/downloads", "GET /repos/{owner}/{repo}/actions/runs", "GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts", "GET /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/jobs", "GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs", "GET /repos/{owner}/{repo}/actions/secrets", "GET /repos/{owner}/{repo}/actions/workflows", "GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs", "GET /repos/{owner}/{repo}/assignees", "GET /repos/{owner}/{repo}/autolinks", "GET /repos/{owner}/{repo}/branches", "GET /repos/{owner}/{repo}/check-runs/{check_run_id}/annotations", "GET /repos/{owner}/{repo}/check-suites/{check_suite_id}/check-runs", "GET /repos/{owner}/{repo}/code-scanning/alerts", "GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/instances", "GET /repos/{owner}/{repo}/code-scanning/analyses", "GET /repos/{owner}/{repo}/collaborators", "GET /repos/{owner}/{repo}/comments", "GET /repos/{owner}/{repo}/comments/{comment_id}/reactions", "GET /repos/{owner}/{repo}/commits", "GET /repos/{owner}/{repo}/commits/{commit_sha}/branches-where-
|
2021-11-26 20:57:51 +08:00
|
|
|
|
|
|
|
function isPaginatingEndpoint(arg) {
|
|
|
|
if (typeof arg === "string") {
|
|
|
|
return paginatingEndpoints.includes(arg);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param octokit Octokit instance
|
|
|
|
* @param options Options passed to Octokit constructor
|
|
|
|
*/
|
|
|
|
|
|
|
|
function paginateRest(octokit) {
|
|
|
|
return {
|
|
|
|
paginate: Object.assign(paginate.bind(null, octokit), {
|
|
|
|
iterator: iterator.bind(null, octokit)
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
paginateRest.VERSION = VERSION;
|
|
|
|
|
|
|
|
exports.composePaginateRest = composePaginateRest;
|
|
|
|
exports.isPaginatingEndpoint = isPaginatingEndpoint;
|
|
|
|
exports.paginateRest = paginateRest;
|
|
|
|
exports.paginatingEndpoints = paginatingEndpoints;
|
|
|
|
//# sourceMappingURL=index.js.map
|