Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry api requests #26

Merged
merged 5 commits into from
Oct 20, 2019
Merged
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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ inputs:
required: false
env:
'GITHUB_TOKEN': 'As provided by Github Actions'
outputs:
url:
description: 'URL to the Release HTML Page'
runs:
using: 'node12'
main: 'lib/main.js'
Expand Down
3 changes: 2 additions & 1 deletion lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class GitHubReleaser {
return this.github.repos.createRelease(params);
}
allReleases(params) {
return this.github.paginate.iterator(this.github.repos.listReleases.endpoint.merge(params));
const updatedParams = Object.assign({ per_page: 100 }, params);
return this.github.paginate.iterator(this.github.repos.listReleases.endpoint.merge(updatedParams));
}
}
exports.GitHubReleaser = GitHubReleaser;
Expand Down
17 changes: 16 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,29 @@ function run() {
if (!util_1.isTag(config.github_ref)) {
throw new Error(`⚠️ GitHub Releases requires a tag`);
}
const gh = new github_2.GitHub(config.github_token);
github_2.GitHub.plugin(require("@octokit/plugin-throttling"));
const gh = new github_2.GitHub(config.github_token, {
onRateLimit: (retryAfter, options) => {
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
if (options.request.retryCount === 0) {
// only retries once
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
}
});
let rel = yield github_1.release(config, new github_1.GitHubReleaser(gh));
if (config.input_files) {
util_1.paths(config.input_files).forEach((path) => __awaiter(this, void 0, void 0, function* () {
yield github_1.upload(gh, rel.upload_url, path);
}));
}
console.log(`🎉 Release ready at ${rel.html_url}`);
core_1.setOutput("url", rel.html_url);
}
catch (error) {
core_1.setFailed(error.message);
Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@actions/core": "^1.1.0",
"@actions/github": "^1.1.0",
"@octokit/plugin-throttling": "^2.6.0",
"glob": "^7.1.4",
"mime": "^2.4.4"
},
Expand Down
3 changes: 2 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export class GitHubReleaser implements Releaser {
owner: string;
repo: string;
}): AsyncIterableIterator<{ data: Release[] }> {
const updatedParams = { per_page: 100, ...params };
return this.github.paginate.iterator(
this.github.repos.listReleases.endpoint.merge(params)
this.github.repos.listReleases.endpoint.merge(updatedParams)
);
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { paths, parseConfig, isTag } from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { setFailed } from "@actions/core";
import { setFailed, setOutput } from "@actions/core";
import { GitHub } from "@actions/github";
import { env } from "process";

Expand All @@ -10,14 +10,33 @@ async function run() {
if (!isTag(config.github_ref)) {
throw new Error(`⚠️ GitHub Releases requires a tag`);
}
const gh = new GitHub(config.github_token);
GitHub.plugin(require("@octokit/plugin-throttling"));
const gh = new GitHub(config.github_token, {
onRateLimit: (retryAfter, options) => {
console.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);
if (options.request.retryCount === 0) {
// only retries once
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
}
});
let rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) {
paths(config.input_files).forEach(async path => {
await upload(gh, rel.upload_url, path);
});
}
console.log(`🎉 Release ready at ${rel.html_url}`);
setOutput("url", rel.html_url);
} catch (error) {
setFailed(error.message);
}
Expand Down