Skip to content

Commit

Permalink
fix: make 403 forbidden check more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jul 17, 2023
1 parent bdf9eb9 commit 881740a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "./lib/constants.js";
import { endorsementToUniqueKey } from "./lib/endorsement-to-unique-key.js";
import { sourceFilesToUniqueKey } from "./lib/source-file-to-unique-key.js";
import { MAX_RETRY_COUNT } from "./lib/octokit.js";

/**
* @param {InstanceType<typeof import('./lib/octokit.js').default>} octokit
Expand Down Expand Up @@ -155,7 +156,10 @@ export default async function run(octokit, logger = pino()) {
}

// https://github.com/all-contributors/import/issues/25
if (error.status === 403 && error.request.request.retryCount === 1) {
if (
error.status === 403 &&
error.request.request.retryCount !== MAX_RETRY_COUNT
) {
sourceFileLogger.warn(
`403 error that is not rate limiting. See https://github.com/all-contributors/import/issues/25. Ignoring.`
);
Expand Down
6 changes: 4 additions & 2 deletions lib/octokit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import pino from "pino";

const octokitLogger = pino().child({ name: "octokit" });

export const MAX_RETRY_COUNT = 5;

export default Octokit.plugin(paginateGraphql).defaults({
userAgent: "all-contributors/import",
log: {
Expand All @@ -17,7 +19,7 @@ export default Octokit.plugin(paginateGraphql).defaults({
onRateLimit: (retryAfter, { method, url }, octokit, retryCount) => {
octokit.log.warn({ method, url }, `Request quota exhausted for request`);

if (retryCount < 5) {
if (retryCount < MAX_RETRY_COUNT) {
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
Expand All @@ -31,7 +33,7 @@ export default Octokit.plugin(paginateGraphql).defaults({
// does not retry, only logs a warning
octokit.log.warn({ method, url }, `SecondaryRateLimit detected`);

if (retryCount < 5) {
if (retryCount < MAX_RETRY_COUNT) {
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
Expand Down

0 comments on commit 881740a

Please sign in to comment.