Skip to content

Commit

Permalink
Merge pull request #26 from softprops/retry-api
Browse files Browse the repository at this point in the history
retry api requests
  • Loading branch information
softprops committed Oct 20, 2019
2 parents 742de99 + e234343 commit 7363c39
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/github.js
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
16 changes: 15 additions & 1 deletion lib/main.js
Expand Up @@ -21,7 +21,21 @@ 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* () {
Expand Down
13 changes: 13 additions & 0 deletions 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
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
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
20 changes: 19 additions & 1 deletion src/main.ts
Expand Up @@ -10,7 +10,25 @@ 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 => {
Expand Down

0 comments on commit 7363c39

Please sign in to comment.