diff --git a/github-repo-fetcher.js b/github-repo-fetcher.js deleted file mode 100644 index 8e348dc..0000000 --- a/github-repo-fetcher.js +++ /dev/null @@ -1,248 +0,0 @@ -// GitHub API endpoint -const API_URL = 'https://api.github.com'; - -// Selectors -const usernameInput = document.getElementById('usernameInput'); -const fetchButton = document.getElementById('fetchButton'); -const userImage = document.getElementById('userImage'); -const userName = document.getElementById('userName'); -const userLocation = document.getElementById('userLocation'); -const userBio = document.getElementById('userBio'); -const userProfileLink = document.getElementById('userProfileLink'); -const userLinks = document.getElementById('userLinks'); -const userSocialLinks = document.getElementById('userSocialLinks'); -const userFollowers = document.getElementById('userFollowers'); -const userRepos = document.getElementById('userRepos'); -const userStars = document.getElementById('userStars'); -const userPullRequests = document.getElementById('userPullRequests'); -const userIssues = document.getElementById('userIssues'); -const repositoriesDiv = document.getElementById('repositories'); -const loaderContainer = document.getElementById('loaderContainer'); -const loader = document.getElementById('loader'); -const paginationDiv = document.getElementById('pagination'); -const userInfoCard = document.getElementById('userInfo'); - -let repositoriesData = []; -let currentPage = 1; - -fetchButton.addEventListener('click', fetchUserData); - -async function fetchUserData() { - const username = usernameInput.value.trim(); - - if (username === '') { - alert('Please enter a GitHub username.'); - return; - } - - clearUserData(); - repositoriesDiv.innerHTML = ''; - paginationDiv.innerHTML = ''; - loaderContainer.style.display = 'flex'; - loader.style.display = 'block'; - - try { - const userData = await fetchUser(username); - displayUserInfo(userData); - - userInfoCard.style.display = 'flex'; - - repositoriesData = await fetchRepositories(username); - displayRepositories(currentPage); - - } catch (error) { - displayError('Failed to fetch data. Please check the username and try again.'); - } finally { - loader.style.display = 'none'; - loaderContainer.style.display = 'none'; - } -} - -async function fetchUser(username) { - const response = await fetch(`${API_URL}/users/${username}`); - if (!response.ok) { - throw new Error('Failed to fetch user data'); - } - return response.json(); -} - -async function fetchRepositories(username) { - const response = await fetch(`${API_URL}/users/${username}/repos`); - if (!response.ok) { - throw new Error('Failed to fetch repositories'); - } - return response.json(); -} - -async function fetchPullRequests(repoUrl) { - const response = await fetch(repoUrl.replace('{/number}', '')); - if (!response.ok) { - return 0; - } - const pullRequests = await response.json(); - return pullRequests.length; -} - -function displayUserInfo(userData) { - const { login, name, avatar_url, html_url, location, bio, followers, public_repos, blog, twitter_username, email, company } = userData; - - userImage.src = avatar_url; - userImage.style.display = 'block'; - userName.textContent = name || login; - userLocation.textContent = location ? `Location: ${location}` : ''; - userBio.textContent = bio || ''; - userProfileLink.innerHTML = `View on GitHub`; - userFollowers.textContent = `👥 Followers: ${followers}`; - userRepos.textContent = `📦 Public Repos: ${public_repos}`; - - const socialLinks = []; - if (blog) { - socialLinks.push(`🔗 ${blog}`); - } - if (twitter_username) { - socialLinks.push(`🐦 @${twitter_username}`); - } - if (email) { - socialLinks.push(`📧 ${email}`); - } - if (company) { - socialLinks.push(`🏢 ${company}`); - } - fetchSocialLinks(userData.html_url).then(links => { - if (links.instagram) { - socialLinks.push(`📸 Instagram`); - } - if (links.linkedin) { - socialLinks.push(`🔗 LinkedIn`); - } - }); - - userSocialLinks.innerHTML = socialLinks.join(' | '); - fetchAdditionalUserData(login); -} - -async function fetchSocialLinks(profileUrl) { - // You would need a service to fetch Instagram, LinkedIn links, which is not available via GitHub API. - // This is a placeholder function assuming you can fetch such data. - // In real scenarios, scraping or another API might be needed. - return { - instagram: null, // Replace with actual URL if available - linkedin: null // Replace with actual URL if available - }; -} - -async function fetchAdditionalUserData(username) { - try { - const [starredResponse, pullsResponse, issuesResponse] = await Promise.all([ - fetch(`${API_URL}/users/${username}/starred`), - fetch(`${API_URL}/search/issues?q=author:${username}+type:pr`), - fetch(`${API_URL}/search/issues?q=author:${username}+type:issue`) - ]); - - const starredRepos = await starredResponse.json(); - const pullsData = await pullsResponse.json(); - const issuesData = await issuesResponse.json(); - - userStars.textContent = `⭐ Stars: ${starredRepos.length}`; - userPullRequests.textContent = `🔃 Pull Requests: ${pullsData.total_count || 0}`; - userIssues.textContent = `❗ Issues: ${issuesData.total_count || 0}`; - } catch (error) { - console.error('Failed to fetch additional user data:', error); - userStars.textContent = `⭐ Stars: 0`; - userPullRequests.textContent = `🔃 Pull Requests: 0`; - userIssues.textContent = `❗ Issues: 0`; - } -} - -function displayRepositories(page) { - currentPage = page; - const startIndex = (page - 1) * 9; - const endIndex = startIndex + 9; - const displayedRepos = repositoriesData.slice(startIndex, endIndex); - - repositoriesDiv.innerHTML = displayedRepos.map(repo => { - const { name, description, html_url, topics, license, stargazers_count, open_issues_count, pulls_url } = repo; - return ` -
-
-
-
${name}
-

${description || 'No description provided'}

-
- ${topics.map(topic => ``).join(' ')} -
-
-

License: ${license ? license.spdx_id : 'None'}

-

⭐ Stars: ${stargazers_count}

-

❗ Issues: ${open_issues_count}

-

🔃 Pull Requests: Fetching...

-
- -
-
-
- `; - }).join(''); - - displayedRepos.forEach(repo => { - const { name, pulls_url } = repo; - fetchPullRequests(pulls_url).then(count => { - document.getElementById(`pull-requests-${name}`).textContent = `🔃 Pull Requests: ${count}`; - }); - }); - - displayPagination(); -} - -function displayPagination() { - const totalPages = Math.ceil(repositoriesData.length / 9); - let paginationHTML = ` - - `; - - paginationDiv.innerHTML = paginationHTML; -} - -function navigatePage(page) { - if (page >= 1 && page <= Math.ceil(repositoriesData.length / 9)) { - displayRepositories(page); - } -} - -function clearUserData() { - userImage.style.display = 'none'; - userName.textContent = ''; - userLocation.textContent = ''; - userBio.textContent = ''; - userProfileLink.innerHTML = ''; - userSocialLinks.innerHTML = ''; - userFollowers.textContent = ''; - userRepos.textContent = ''; - userStars.textContent = ''; - userPullRequests.textContent = ''; - userIssues.textContent = ''; -} - -function displayError(message) { - alert(message); -}