Skip to content

Commit

Permalink
Fix: Pull Requests functionallity working :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Patel07 committed Jul 20, 2024
1 parent 57fb6a7 commit 1f462df
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

19 changes: 17 additions & 2 deletions pages/about/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ import CountUp from "react-countup";

const About = () => {
const [index, setIndex] = useState(0);
const [mergedPullRequests, setMergedPullRequests] = useState(0);

useEffect(() => {
const fetchMergedPullRequests = async () => {
try {
console.log('Fetching merged pull requests...');
const response = await axios.get('/api/gitPullRequests');
setMergedPullRequests(response.data.mergedPullRequestsCount);
} catch (error) {
console.error('Error fetching merged pull requests:', error);
}
};

fetchMergedPullRequests();
}, []);
return (
<div className="h-full bg-primary/30 py-32 text-center xl:text-left">
<Circles />
Expand Down Expand Up @@ -183,10 +198,10 @@ const About = () => {
{/* commits */}
<div className="relative flex-1 after:w-[1px] after:h-full after:bg-white/10 after:absolute after:top-0 after:right-0">
<div className="text-2xl xl:text-4xl font-extrabold text-accent mb-2">
<CountUp start={0} end={commits} duration={5} /> +
<CountUp start={0} end={mergedPullRequests} duration={5} /> +
</div>
<div className="text-xs uppercase tracking-[1px] leading-[1.4] max-w-[100px]">
Total Commits
Total Pull Requests
</div>
</div>
</div>
Expand Down
42 changes: 42 additions & 0 deletions pages/api/gitPullRequests.js
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' });
}
}

0 comments on commit 1f462df

Please sign in to comment.