1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
// Helper function to format the date for GitHub API query
function formatDate(daysAgo: number): string {
const date = new Date();
date.setDate(date.getDate() - daysAgo);
return date.toISOString().split("T")[0];
}
// Function to fetch top GitHub repositories based on stars and creation date
async function topGitHubRepos(stars: number, daysAgo: number, timeframeDescription: string) {
const date = formatDate(daysAgo);
const query = `stars:>${stars} created:>${date}`;
const response = await fetch(
`https://api.github.com/search/repositories?q=${query}&sort=stars&order=desc&per_page=10`,
)
.then((res) => res.json());
return `Top Repositories ${timeframeDescription} (Over ${stars} Stars):\n`
+ response.items.map((repo, index) =>
`${index + 1}: ${repo.full_name} (Stars: ${repo.stargazers_count}, URL: ${repo.html_url})`
).join("\n");
}
// Function to get combined information for different criteria
export async function getTopReposByCriteria() {
const reposLastWeek = await topGitHubRepos(1000, 7, "Created Last Week"); // Last week, over 1000 stars
const reposLastMonth = await topGitHubRepos(3000, 30, "Created Last Month"); // Last month, over 3000 stars
const reposLastSixMonths = await topGitHubRepos(10000, 180, "Created 6 Months Ago"); // Last 6 months, over 10000 stars
const reposLastYear = await topGitHubRepos(20000, 365, "Created a Year Ago"); // Last year, over 20000 stars
return `${reposLastWeek}\n\n${reposLastMonth}\n\n${reposLastSixMonths}\n\n${reposLastYear}`;
}
// Call the function to get and print the information
getTopReposByCriteria().then(console.log);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 17, 2024