Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
Client-side fetch logic for repository
Browse files Browse the repository at this point in the history
  • Loading branch information
LineIndent committed Sep 4, 2023
1 parent 80702c2 commit 72dda38
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app/utilities/rx_repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// GitHub repository owner and name
const owner = '<owner>';
const repoName = '<repo>';

// GitHub REST API URL to get the repository information
const apiUrl = `https://api.github.com/repos/${owner}/${repoName}`;

// Function to format a number in shorthand like 'k'
function formatNumberShorthand(number) {
if (number >= 1000) {
return (number / 1000).toFixed(1) + 'k';
}
return number.toString();
}


// Function to fetch and display repository information, including the latest release
async function getRepoInfo() {
try {

// Dynamically import the 'node-fetch' module as an ES module
const fetch = (await import('node-fetch')).default;

// Send an HTTP GET request to the GitHub API
const response = await fetch(apiUrl);
const repoInfo = await response.json();

// Check if the response contains the desired information
if (response.status === 200) {
const starsCount = repoInfo.stargazers_count;
const forksCount = repoInfo.forks_count;

// Fetch the latest release information
const releaseUrl = `${apiUrl}/releases/latest`;
const releaseResponse = await fetch(releaseUrl);
const releaseInfo = await releaseResponse.json();
const latestRelease = releaseInfo.tag_name;

console.log(`Stars: ${formatNumberShorthand(starsCount)}`);
console.log(`Forks: ${formatNumberShorthand(forksCount)}`);
console.log(`Latest Release: ${latestRelease}`);
} else {
console.log('Error fetching repository information.');
}
} catch (error) {
console.error("Error fetching data:", error);
}
}

0 comments on commit 72dda38

Please sign in to comment.