-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling the API limit exceed for fetching the contributors
- Loading branch information
1 parent
96745db
commit 05aac4f
Showing
4 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Node.js dependencies | ||
node_modules/ | ||
package-lock.json | ||
|
||
# Logs and temp files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.env | ||
|
||
# Netlify functions build | ||
.netlify/functions/ | ||
|
||
# VSCode settings (if applicable) | ||
.vscode/ | ||
|
||
# MacOS system files | ||
.DS_Store | ||
|
||
# Linux/Mac temporary files | ||
*.swp | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Use dynamic import for node-fetch | ||
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); | ||
|
||
exports.handler = async function(event, context) { | ||
const token = process.env.GITHUB_TOKEN; // Access the token from the environment variables | ||
const page = event.queryStringParameters.page || 1; | ||
const perPage = event.queryStringParameters.per_page || 100; | ||
const owner = 'Rakesh9100'; | ||
const repoName = 'Beautiify'; | ||
|
||
const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${page}&per_page=${perPage}`; | ||
|
||
try { | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `token ${token}` // Use the token in the request header | ||
} | ||
}); | ||
|
||
if (!response.ok) { | ||
return { | ||
statusCode: response.status, | ||
body: `Failed to fetch the contributors data. Status code: ${response.status}` | ||
}; | ||
} | ||
|
||
const contributorsData = await response.json(); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(contributorsData) | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ message: 'Error fetching the contributors' }) | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "beautiify", | ||
"version": "1.0.0", | ||
"description": "Fetch and display GitHub contributors.", | ||
"main": "script.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": ["github", "contributors", "fetch"], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"node-fetch": "^3.3.2" | ||
} | ||
} |