Merge pull request #110 from github/hashtagchris-pagination

Simplify variable pagination, retrieve every page of secrets and runner labels
This commit is contained in:
Chris Sidi
2023-01-26 10:26:24 -05:00
committed by GitHub
5 changed files with 127 additions and 76 deletions
+1 -1
View File
@@ -40,7 +40,7 @@
"dependencies": {
"@github/actions-languageservice": "^0.1.101",
"@github/actions-workflow-parser": "^0.1.101",
"@octokit/rest": "^19.0.5",
"@octokit/rest": "^19.0.7",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.7",
"yaml": "^2.1.3"
@@ -92,12 +92,13 @@ async function getRemoteSecrets(
async function fetchSecrets(octokit: Octokit, owner: string, name: string): Promise<StringData[]> {
try {
const response = await octokit.actions.listRepoSecrets({
owner,
repo: name
});
return response.data.secrets.map(secret => new StringData(secret.name));
return await octokit.paginate(octokit.actions.listRepoSecrets,
{
owner,
repo: name,
per_page: 100
},
response => response.data.map(secret => new StringData(secret.name)));
} catch (e) {
console.log("Failure to retrieve secrets: ", e);
}
@@ -111,12 +112,13 @@ async function fetchEnvironmentSecrets(
environmentName: string
): Promise<StringData[]> {
try {
const response = await octokit.actions.listEnvironmentSecrets({
repository_id: repositoryId,
environment_name: environmentName
});
return response.data.secrets.map(secret => new StringData(secret.name));
return await octokit.paginate(octokit.actions.listEnvironmentSecrets,
{
repository_id: repositoryId,
environment_name: environmentName,
per_page: 100
},
response => response.data.map(secret => new StringData(secret.name)));
} catch (e) {
console.log("Failure to retrieve environment secrets: ", e);
}
@@ -94,19 +94,15 @@ export async function getRemoteVariables(
async function fetchVariables(octokit: Octokit, owner: string, name: string): Promise<Pair[]> {
try {
const response = (await octokit.paginate("GET /repos/{owner}/{repo}/actions/variables{?per_page}", {
owner: owner,
repo: name
})) as {
name: string;
value: string;
created_at: string;
updated_at: string;
}[];
return response.map(variable => {
return {key: variable.name, value: new StringData(variable.value)};
});
return await octokit.paginate(octokit.actions.listRepoVariables,
{
owner: owner,
repo: name,
per_page: 100
},
response => response.data.map(variable => {
return {key: variable.name, value: new StringData(variable.value)};
}));
} catch (e) {
console.log("Failure to retrieve variables: ", e);
}
@@ -120,22 +116,15 @@ async function fetchEnvironmentVariables(
environmentName: string
): Promise<Pair[]> {
try {
const response = (await octokit.paginate(
"GET /repositories/{repository_id}/environments/{environment_name}/variables{?per_page}",
return await octokit.paginate(octokit.actions.listEnvironmentVariables,
{
repository_id: repositoryId,
environment_name: environmentName
}
)) as {
name: string;
value: string;
created_at: string;
updated_at: string;
}[];
return response.map(variable => {
return {key: variable.name, value: new StringData(variable.value)};
});
environment_name: environmentName,
per_page: 100
},
response => response.data.map(variable => {
return {key: variable.name, value: new StringData(variable.value)};
}));
} catch (e) {
console.log("Failure to retrieve environment variables: ", e);
}
@@ -33,16 +33,20 @@ export async function getRunnerLabels(client: Octokit, cache: TTLCache, owner: s
async function fetchRunnerLabels(client: Octokit, owner: string, name: string): Promise<Set<string>> {
const labels = new Set<string>();
try {
const response = await client.actions.listSelfHostedRunnersForRepo({
owner,
repo: name
});
const itor = client.paginate.iterator(client.actions.listSelfHostedRunnersForRepo,
{
owner,
repo: name,
per_page: 100
});
for (const runner of response.data.runners) {
for (const label of runner.labels) {
labels.add(label.name);
for await (const response of itor) {
for (const runner of response.data) {
for (const label of runner.labels) {
labels.add(label.name);
}
}
}
}
} catch (e) {
console.log("Failure to retrieve runner labels: ", e);
}
+84 -28
View File
@@ -39,7 +39,7 @@
"dependencies": {
"@github/actions-languageservice": "^0.1.101",
"@github/actions-workflow-parser": "^0.1.101",
"@octokit/rest": "^19.0.5",
"@octokit/rest": "^19.0.7",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.7",
"yaml": "^2.1.3"
@@ -2904,11 +2904,11 @@
"dev": true
},
"node_modules/@octokit/plugin-paginate-rest": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-5.0.1.tgz",
"integrity": "sha512-7A+rEkS70pH36Z6JivSlR7Zqepz3KVucEFVDnSrgHXzG7WLAzYwcHZbKdfTXHwuTHbkT1vKvz7dHl1+HNf6Qyw==",
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-6.0.0.tgz",
"integrity": "sha512-Sq5VU1PfT6/JyuXPyt04KZNVsFOSBaYOAq2QRZUwzVlI10KFvcbUo8lR258AAQL1Et60b0WuVik+zOWKLuDZxw==",
"dependencies": {
"@octokit/types": "^8.0.0"
"@octokit/types": "^9.0.0"
},
"engines": {
"node": ">= 14"
@@ -2917,6 +2917,19 @@
"@octokit/core": ">=4"
}
},
"node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-16.0.0.tgz",
"integrity": "sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA=="
},
"node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.0.0.tgz",
"integrity": "sha512-LUewfj94xCMH2rbD5YJ+6AQ4AVjFYTgpp6rboWM5T7N3IsIF65SBEOVcYMGAEzO/kKNiNaW4LoWtoThOhH06gw==",
"dependencies": {
"@octokit/openapi-types": "^16.0.0"
}
},
"node_modules/@octokit/plugin-request-log": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz",
@@ -2926,11 +2939,11 @@
}
},
"node_modules/@octokit/plugin-rest-endpoint-methods": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-6.7.0.tgz",
"integrity": "sha512-orxQ0fAHA7IpYhG2flD2AygztPlGYNAdlzYz8yrD8NDgelPfOYoRPROfEyIe035PlxvbYrgkfUZIhSBKju/Cvw==",
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-7.0.1.tgz",
"integrity": "sha512-pnCaLwZBudK5xCdrR823xHGNgqOzRnJ/mpC/76YPpNP7DybdsJtP7mdOwh+wYZxK5jqeQuhu59ogMI4NRlBUvA==",
"dependencies": {
"@octokit/types": "^8.0.0",
"@octokit/types": "^9.0.0",
"deprecation": "^2.3.1"
},
"engines": {
@@ -2940,6 +2953,19 @@
"@octokit/core": ">=3"
}
},
"node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-16.0.0.tgz",
"integrity": "sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA=="
},
"node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.0.0.tgz",
"integrity": "sha512-LUewfj94xCMH2rbD5YJ+6AQ4AVjFYTgpp6rboWM5T7N3IsIF65SBEOVcYMGAEzO/kKNiNaW4LoWtoThOhH06gw==",
"dependencies": {
"@octokit/openapi-types": "^16.0.0"
}
},
"node_modules/@octokit/request": {
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.2.tgz",
@@ -2970,14 +2996,14 @@
}
},
"node_modules/@octokit/rest": {
"version": "19.0.5",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-19.0.5.tgz",
"integrity": "sha512-+4qdrUFq2lk7Va+Qff3ofREQWGBeoTKNqlJO+FGjFP35ZahP+nBenhZiGdu8USSgmq4Ky3IJ/i4u0xbLqHaeow==",
"version": "19.0.7",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-19.0.7.tgz",
"integrity": "sha512-HRtSfjrWmWVNp2uAkEpQnuGMJsu/+dBr47dRc5QVgsCbnIc1+GFEaoKBWkYG+zjrsHpSqcAElMio+n10c0b5JA==",
"dependencies": {
"@octokit/core": "^4.1.0",
"@octokit/plugin-paginate-rest": "^5.0.0",
"@octokit/plugin-paginate-rest": "^6.0.0",
"@octokit/plugin-request-log": "^1.0.4",
"@octokit/plugin-rest-endpoint-methods": "^6.7.0"
"@octokit/plugin-rest-endpoint-methods": "^7.0.0"
},
"engines": {
"node": ">= 14"
@@ -14546,7 +14572,7 @@
"requires": {
"@github/actions-languageservice": "^0.1.101",
"@github/actions-workflow-parser": "^0.1.101",
"@octokit/rest": "^19.0.5",
"@octokit/rest": "^19.0.7",
"@types/jest": "^29.0.3",
"fetch-mock": "^9.11.0",
"jest": "^29.0.3",
@@ -16280,11 +16306,26 @@
"dev": true
},
"@octokit/plugin-paginate-rest": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-5.0.1.tgz",
"integrity": "sha512-7A+rEkS70pH36Z6JivSlR7Zqepz3KVucEFVDnSrgHXzG7WLAzYwcHZbKdfTXHwuTHbkT1vKvz7dHl1+HNf6Qyw==",
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-6.0.0.tgz",
"integrity": "sha512-Sq5VU1PfT6/JyuXPyt04KZNVsFOSBaYOAq2QRZUwzVlI10KFvcbUo8lR258AAQL1Et60b0WuVik+zOWKLuDZxw==",
"requires": {
"@octokit/types": "^8.0.0"
"@octokit/types": "^9.0.0"
},
"dependencies": {
"@octokit/openapi-types": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-16.0.0.tgz",
"integrity": "sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA=="
},
"@octokit/types": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.0.0.tgz",
"integrity": "sha512-LUewfj94xCMH2rbD5YJ+6AQ4AVjFYTgpp6rboWM5T7N3IsIF65SBEOVcYMGAEzO/kKNiNaW4LoWtoThOhH06gw==",
"requires": {
"@octokit/openapi-types": "^16.0.0"
}
}
}
},
"@octokit/plugin-request-log": {
@@ -16294,12 +16335,27 @@
"requires": {}
},
"@octokit/plugin-rest-endpoint-methods": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-6.7.0.tgz",
"integrity": "sha512-orxQ0fAHA7IpYhG2flD2AygztPlGYNAdlzYz8yrD8NDgelPfOYoRPROfEyIe035PlxvbYrgkfUZIhSBKju/Cvw==",
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-7.0.1.tgz",
"integrity": "sha512-pnCaLwZBudK5xCdrR823xHGNgqOzRnJ/mpC/76YPpNP7DybdsJtP7mdOwh+wYZxK5jqeQuhu59ogMI4NRlBUvA==",
"requires": {
"@octokit/types": "^8.0.0",
"@octokit/types": "^9.0.0",
"deprecation": "^2.3.1"
},
"dependencies": {
"@octokit/openapi-types": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-16.0.0.tgz",
"integrity": "sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA=="
},
"@octokit/types": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.0.0.tgz",
"integrity": "sha512-LUewfj94xCMH2rbD5YJ+6AQ4AVjFYTgpp6rboWM5T7N3IsIF65SBEOVcYMGAEzO/kKNiNaW4LoWtoThOhH06gw==",
"requires": {
"@octokit/openapi-types": "^16.0.0"
}
}
}
},
"@octokit/request": {
@@ -16326,14 +16382,14 @@
}
},
"@octokit/rest": {
"version": "19.0.5",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-19.0.5.tgz",
"integrity": "sha512-+4qdrUFq2lk7Va+Qff3ofREQWGBeoTKNqlJO+FGjFP35ZahP+nBenhZiGdu8USSgmq4Ky3IJ/i4u0xbLqHaeow==",
"version": "19.0.7",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-19.0.7.tgz",
"integrity": "sha512-HRtSfjrWmWVNp2uAkEpQnuGMJsu/+dBr47dRc5QVgsCbnIc1+GFEaoKBWkYG+zjrsHpSqcAElMio+n10c0b5JA==",
"requires": {
"@octokit/core": "^4.1.0",
"@octokit/plugin-paginate-rest": "^5.0.0",
"@octokit/plugin-paginate-rest": "^6.0.0",
"@octokit/plugin-request-log": "^1.0.4",
"@octokit/plugin-rest-endpoint-methods": "^6.7.0"
"@octokit/plugin-rest-endpoint-methods": "^7.0.0"
}
},
"@octokit/types": {