-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: separate request responsibility #12
Conversation
WalkthroughThe codebase has undergone a refactoring to enhance modularity and error handling. A new function for repository retrieval was added, and existing functions were updated to use a centralized request handler, improving maintainability. Tests were adjusted to reflect these updates, including skipping some and updating expected values. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (4)
- contributors.js (3 hunks)
- network.js (1 hunks)
- test/contributors.test.js (2 hunks)
- test/fixtures/contributors.fixture.js (1 hunks)
Files skipped from review due to trivial changes (2)
- test/contributors.test.js
- test/fixtures/contributors.fixture.js
Additional comments: 6
contributors.js (5)
6-6: Semicolon added for consistency in export statements.
7-7: Addition of
getAllRepos
to the exports supports the centralization of network requests.13-13: Import of
makeRequest
fromnetwork.js
replaces directhttps
usage, aligning with the centralization goal.45-61: Refactored
getAllRepos
to usemakeRequest
for network calls, which is a core part of the centralization effort.72-88: Refactored
getRepoContributors
to usemakeRequest
for network calls, which is consistent with the centralization goal.network.js (1)
- 1-51: The
makeRequest
function is well-implemented with proper error handling and usage of Promises for asynchronous operations. The documentation and example usage provided are clear and helpful. Ensure that the rest of the codebase is updated to use this new function for all network requests.
console.log("Repo list request finished"); | ||
console.log('HTTP status: ', res.statusCode); | ||
// console.log(data) | ||
let dataJsonArray = JSON.parse(data); | ||
if (dataJsonArray.length == 100) { | ||
//It might have more data on the next page | ||
pageNo++; | ||
try { | ||
let dataFromNextPage = await getAllRepos(owner, { pageNo: pageNo } ); | ||
dataJsonArray.push(...dataFromNextPage); | ||
} catch (err) { | ||
console.log("No more pagination needed") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider improving error handling beyond console logs to ensure robustness in production environments.
Also applies to: 75-86
if (dataJsonArray.length == 100) { | ||
//It might have more data on the next page | ||
pageNo++; | ||
try { | ||
let dataFromNextPage = await getAllRepos(owner, { pageNo: pageNo } ); | ||
dataJsonArray.push(...dataFromNextPage); | ||
} catch (err) { | ||
console.log("No more pagination needed") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pagination logic assumes that a full page of results indicates more data. It may be helpful to add a comment explaining this assumption for future maintainability.
Also applies to: 78-87
if(options && options.GITHUB_PERSONAL_TOKEN){ | ||
GITHUB_REQUEST_OPTIONS.headers["Authorization"] = "token "+options.GITHUB_PERSONAL_TOKEN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct modification of GITHUB_REQUEST_OPTIONS
could lead to side effects. Consider creating a new options object for each request.
let dataFromNextPage = await getAllRepos(owner, { pageNo: pageNo } ); | ||
dataJsonArray.push(...dataFromNextPage); | ||
} catch (err) { | ||
console.log("No more pagination needed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recursion for pagination could lead to stack overflow with many pages. An iterative approach may be more robust.
Also applies to: 82-85
A step before developing rate limit abilities - get all requests to be handled by single file
network.js
Summary by CodeRabbit