Skip to content

Commit

Permalink
updated usage of octokit plugins with complete octokit package
Browse files Browse the repository at this point in the history
  • Loading branch information
TDDR committed Apr 19, 2022
1 parent 686770e commit a73209e
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 21 deletions.
184 changes: 175 additions & 9 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/api/dependency-discovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"homepage": "https://github.com/Seneca-CDOT/telescope#readme",
"dependencies": {
"@octokit/request": "5.6.3",
"@senecacdot/satellite": "^1.27.0",
"octokit": "1.7.1",
"query-registry": "2.2.0",
"supertest": "6.1.6"
},
Expand Down
29 changes: 26 additions & 3 deletions src/api/dependency-discovery/src/github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { request } = require('@octokit/request');

const { Octokit } = require('octokit');
// Check whether a specific time has reached the GitHub time limit.
// @param {Date} datetime - a Date object representing a moment in the past
// @returns {Boolean}
Expand All @@ -11,9 +10,33 @@ const labels = ['hacktoberfest', 'good first issue', 'help wanted'];

async function constructGitHubRequest(gitHubUrl) {
const [owner, repo] = new URL(gitHubUrl).pathname.substring(1).split('/');
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
// options for throttling plugin https://github.com/octokit/plugin-throttling.js
throttle: {
onRateLimit: (retryAfter, options, octokitClient) => {
octokitClient.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);

if (options.request.retryCount === 0) {
// only retries once
octokitClient.log.info(`Retrying after ${retryAfter} seconds!`);
// Return true to automatically retry the request after retryAfter seconds.
return true;
}

return false;
},
onAbuseLimit: (retryAfter, options, octokitClient) => {
// does not retry, only logs a warning
octokitClient.log.warn(`Abuse detected for request ${options.method} ${options.url}`);
},
},
});

const requestPromises = labels.map((label) => {
return request('GET /repos/{owner}/{repo}/issues{?assignee,state,labels}', {
return octokit.request('GET /repos/{owner}/{repo}/issues{?assignee,state,labels}', {
owner,
repo,
assignee: 'none',
Expand Down
4 changes: 1 addition & 3 deletions src/api/status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
},
"homepage": "https://github.com/Seneca-CDOT/telescope#readme",
"dependencies": {
"@octokit/core": "3.5.1",
"@octokit/plugin-retry": "3.0.9",
"@octokit/plugin-throttling": "3.5.2",
"@popperjs/core": "2.11.5",
"@senecacdot/satellite": "^1.27.0",
"bootstrap": "5.1.3",
"express": "4.17.3",
"express-handlebars": "6.0.4",
"npm-run-all": "4.1.5",
"octokit": "1.7.1",
"perfect-scrollbar": "1.5.5",
"sass": "1.49.9",
"vite": "2.8.6",
Expand Down
7 changes: 2 additions & 5 deletions src/api/status/src/js/octokit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const { Octokit } = require('@octokit/core');
const { retry } = require('@octokit/plugin-retry');
const { throttling } = require('@octokit/plugin-throttling');
const { Octokit } = require('octokit');

const MyOctokit = Octokit.plugin(retry, throttling);
const octokit = new MyOctokit({
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
// options for throttling plugin https://github.com/octokit/plugin-throttling.js
throttle: {
Expand Down

0 comments on commit a73209e

Please sign in to comment.