Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
feat: detailed debugging now configured with NODE_DEBUG=repo (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Jan 17, 2022
1 parent 2e522e4 commit 5306b21
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,13 @@ There are settings you can configure to make this less likely:
When running against a large number of repos, try the following as a starting point:
```bash
repo [command] --delay=2500 --concurrency=4 --retry --title='.*some title.*'
repo [command] --delay=1000 --concurrency=2 --retry --title='.*some title.*'
```
If you are continuing to run into problems, run with:
```
NODE_DEBUG=repo repo [command] --delay=1000 --concurrency=2 --retry --title='.*some title.*'
```
And share the debug output in an issue, along with the command you are running.
12 changes: 7 additions & 5 deletions src/lib/asyncItemIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import * as meow from 'meow';
import {meowFlags} from '../cli';
import Q from 'p-queue';
import ora = require('ora');
import {debuglog} from 'util';
const debug = debuglog('repo');

import * as configLib from './config';
import {GitHub, GitHubRepository, PullRequest, Issue} from './github';
Expand All @@ -37,9 +39,9 @@ async function retryException<T>(
return result;
} catch (err) {
if (i < retryStrategy.length) {
console.error(`\noperation failed: ${err.toString()}`);
debug(`operation failed: ${err.toString()}`);
const delay = nextDelay(retryStrategy[i]);
console.info(`\nretrying in ${delay}ms`);
debug(`retrying in ${delay}ms`);
await delayMs(delay);
continue;
}
Expand All @@ -63,7 +65,7 @@ async function retryBoolean(
const result = await eventual();
if (!result && i < retryStrategy.length) {
const delay = nextDelay(retryStrategy[i]);
console.info(`\nretrying in ${delay}ms`);
debug(`retrying in ${delay}ms`);
await delayMs(delay);
continue;
} else {
Expand Down Expand Up @@ -187,12 +189,12 @@ async function process(
let localItems;
if (processIssues) {
localItems = await retryException<Issue[]>(async () => {
if (delay) delayMs(nextDelay(delay));
if (delay) await delayMs(nextDelay(delay));
return await repo.listIssues();
}, retryStrategy);
} else {
localItems = await retryException<PullRequest[]>(async () => {
if (delay) delayMs(nextDelay(delay));
if (delay) await delayMs(nextDelay(delay));
return await repo.listPullRequests();
}, retryStrategy);
}
Expand Down
26 changes: 24 additions & 2 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,36 @@
* @fileoverview Wraps some octokit GitHub API calls.
*/

import {Gaxios} from 'gaxios';
import {Gaxios, GaxiosPromise, GaxiosOptions} from 'gaxios';
import {Config} from './config';
import {debuglog} from 'util';
const debug = debuglog('repo');

export function getClient(config: Config) {
return new Gaxios({
const client = new Gaxios({
baseURL: 'https://api.github.com',
headers: {Authorization: `token ${config.githubToken}`},
});
// Report rate limit information if NODE_DEBUG=repo set.
let counter = 0;
const request = client.request.bind(client);
client.request = async (opts: GaxiosOptions): GaxiosPromise => {
const resp = await request(opts);
const rateLimit = resp.headers['x-ratelimit-limit']
? Number(resp.headers['x-ratelimit-limit'])
: 0;
const rateLimitRemaining = resp.headers['x-ratelimit-remaining']
? Number(resp.headers['x-ratelimit-remaining'])
: 0;
const reset = resp.headers['x-ratelimit-reset'];
if (counter++ % 10 === 0) {
debug(
`GitHub rate limit: limit = ${rateLimit} remaining = ${rateLimitRemaining} reset epoch = ${reset}`
);
}
return resp;
};
return client;
}

interface SearchReposResponse {
Expand Down

0 comments on commit 5306b21

Please sign in to comment.