Skip to content
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

Contributors value showing wrong #927

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions frontend/src/pages/ContributorsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,46 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faGithub } from '@fortawesome/free-brands-svg-icons'
import CountUp from 'react-countup'
import axios from 'axios'

const ContributorsPage = () => {
const [contributors, setContributors] = useState([])
const [repoStats, setRepoStats] = useState({})
const [loading, setLoading] = useState(true)
const fetchData = async () => {
try {
const contributorsResponse = await fetch(
'https://api.github.com/repos/manikumarreddyu/AgroTech-AI/contributors'
)
const contributorsData = await contributorsResponse.json()

const repoResponse = await fetch(
'https://api.github.com/repos/manikumarreddyu/AgroTech-AI'
)
const repoData = await repoResponse.json()

setContributors(contributorsData)
setRepoStats(repoData)
const contributorsData = [];
const repoUrl = 'https://api.github.com/repos/manikumarreddyu/AgroTech-AI';
let page = 1;
let isFetching = true;

// Fetch repository stats
const repoResponse = await fetch(repoUrl);
const repoData = await repoResponse.json();
setRepoStats(repoData);

// Fetch all contributors with pagination
while (isFetching) {
const contributorsResponse = await fetch(`${repoUrl}/contributors?per_page=100&page=${page}`);
const pageData = await contributorsResponse.json();

if (!contributorsResponse.ok || pageData.length === 0) {
isFetching = false;
} else {
contributorsData.push(...pageData);
page++;
}
}

setContributors(contributorsData);
} catch (error) {
console.error('Error fetching data:', error)
setContributors([])
setRepoStats({})
console.error('Error fetching data:', error);
setContributors([]);
setRepoStats({});
} finally {
setLoading(false)
setLoading(false);
}
}
};


useEffect(() => {
fetchData()
Expand Down
Loading