Skip to content

Instantly share code, notes, and snippets.

@annibal
Last active April 22, 2025 18:11
Show Gist options
  • Save annibal/fdb348ce2efeb3958dd87fb32308d8f1 to your computer and use it in GitHub Desktop.
Save annibal/fdb348ce2efeb3958dd87fb32308d8f1 to your computer and use it in GitHub Desktop.
Azure : list Project's recently active Repos
async function listMostRecentlyActiveRepos(org, project, maxCommits=15) {
const base = `https://dev.azure.com/${org}/${project}/_apis/git/repositories?api-version=7.1-preview.1`;
const repos = await fetch(base).then(r => r.json());
const activeRepos = [];
const data = []
for (const repo of repos.value) {
const commitsUrl = `https://dev.azure.com/${org}/${project}/_apis/git/repositories/${repo.id}/commits?$top=${maxCommits}&api-version=7.1-preview.1`;
const commitsResp = await fetch(commitsUrl).then(r => r.json());
if (!commitsResp.value || commitsResp.value.length === 0) continue;
data.push({ repo, commits: commitsResp.value })
commitsResp.value.slice(0, maxCommits).forEach(c => {
const dt = new Date(c.committer?.date)
if (!isNaN(+dt)) {
activeRepos.push({ name: repo.name, lastCommit: dt });
}
})
}
return {
mostRecentlyActive: Array.from(new Set(activeRepos.map(l => l.name))),
nameAndCommitDates: activeRepos
.sort((a, b) => b.lastCommit - a.lastCommit)
.map(r => `${r.lastCommit.toISOString().slice(0,10).split("-").join(" . ")} : ${r.name}`),
dataRaw: data,
}
}
const { mostRecentlyActive } = await listMostRecentlyActiveRepos("ACME", "someCorpApplication", 15);
console.log(mostRecentlyActive.slice(0, 7).join("\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment