Created
March 24, 2022 08:48
-
-
Save shajanjp/b95c5fc2c92bf7c91912510062637acb to your computer and use it in GitHub Desktop.
Search most recently updated forks of a github repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios").default; | |
(async () => { | |
async function getForkByPage(repoUrl, page) { | |
console.log(`Fetching page ${page}`); | |
return axios | |
.get(`${repoUrl}/forks?page=${page}`) | |
.then((res) => { | |
return res.data || []; | |
}) | |
.catch((error) => { | |
return []; | |
}); | |
} | |
async function getForksSortedByUpdatedDate(repoUrl) { | |
const repos = []; | |
let nextPageAvailable = true; | |
let page = 1; | |
while (nextPageAvailable) { | |
const forks = await getForkByPage(repoUrl, page); | |
repos.push( | |
...forks.map((f) => ({ url: f.url, updatedAt: f.updated_at })) | |
); | |
if (!forks.length) { | |
nextPageAvailable = false; | |
} | |
page++; | |
} | |
return repos.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)); | |
} | |
const sortedForks = await getForksSortedByUpdatedDate(`https://api.github.com/repos/statping/statping`); | |
console.log(sortedForks); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment