-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Pull Requests functionallity working :)
- Loading branch information
1 parent
57fb6a7
commit 1f462df
Showing
3 changed files
with
59 additions
and
3 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
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,42 @@ | ||
// pages/api/githubPullRequests.js | ||
|
||
import axios from "axios"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
const GITHUB_USERNAME = 'Shubham-Patel07'; // Replace with your GitHub username | ||
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; | ||
|
||
const getMergedPullRequests = async (username) => { | ||
const headers = { | ||
Authorization: `Bearer ${GITHUB_TOKEN}`, | ||
Accept: 'application/vnd.github.v3+json', | ||
}; | ||
|
||
const url = `https://api.github.com/search/issues?q=author:${username}+is:pr+is:merged`; | ||
|
||
try { | ||
console.log('Making request to GitHub API with URL:', url); | ||
const response = await axios.get(url, { headers }); | ||
return response.data.total_count; | ||
} catch (error) { | ||
if (error.response) { | ||
console.error('Error response data:', error.response.data); | ||
} else { | ||
console.error('Error message:', error.message); | ||
} | ||
return 0; | ||
} | ||
}; | ||
|
||
export default async function handler(req, res) { | ||
if (req.method === 'GET') { | ||
console.log('Received GET request...'); | ||
const mergedPullRequestsCount = await getMergedPullRequests(GITHUB_USERNAME); | ||
console.log('Merged pull requests count:', mergedPullRequestsCount); | ||
res.status(200).json({ mergedPullRequestsCount }); | ||
} else { | ||
res.status(405).json({ message: 'Method not allowed' }); | ||
} | ||
} |