Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Last active July 3, 2025 08:59
Show Gist options
  • Save arthurattwell/f574a7471e0add19d19e1e3081a95ebd to your computer and use it in GitHub Desktop.
Save arthurattwell/f574a7471e0add19d19e1e3081a95ebd to your computer and use it in GitHub Desktop.
List repos

List repos

I use this at EBW when I want to get a list of all of our repos for maintenance purposes.

To use this script:

  1. Save it as get-repo-dates.js
  2. Replace your_personal_access_token with your actual GitHub token
  3. Run it with Node.js:
node get-repo-dates.js

The script will:

  • Fetch all repositories from the organization
  • Handle pagination automatically
  • Sort repositories by creation date
  • Show the results in a formatted table in the console
  • Save all data to a CSV file named repo_dates.csv
  • Include additional information like archived status and privacy setting
  • Handle rate limiting and potential errors

The output CSV will have columns for:

  • Repository name
  • Creation date
  • Status (Active/Archived)
  • Privacy setting (true/false)

You'll need a Personal Access Token with at least the repo and read:org scopes to access private repositories. You can create one at: https://github.com/settings/tokens

To use it for a different organization, replace electricbookworks in the script accordingly.

const https = require('https')
const fs = require('fs')
// Replace with your GitHub Personal Access Token
// https://github.com/settings/tokens
const TOKEN = 'your_personal_access_token'
// Configuration
const ORG = 'electricbookworks'
const PER_PAGE = 100
// Function to make GitHub API requests
function makeGitHubRequest (path) {
return new Promise((resolve, reject) => {
const options = {
hostname: 'api.github.com',
path: path,
headers: {
'User-Agent': 'Node.js',
'Authorization': `token ${TOKEN}`,
'Accept': 'application/vnd.github.v3+json'
}
}
https.get(options, (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
try {
resolve(JSON.parse(data))
} catch (e) {
reject(e)
}
})
}).on('error', (err) => {
reject(err)
})
})
}
async function getAllRepos () {
let page = 1
const allRepos = []
let hasMorePages = true
console.log('Fetching repositories...')
while (hasMorePages) {
const path = `/orgs/${ORG}/repos?per_page=${PER_PAGE}&page=${page}`
const repos = await makeGitHubRequest(path)
if (repos.length === 0) {
hasMorePages = false
} else {
allRepos.push(...repos)
console.log(`Fetched page ${page} (${repos.length} repositories)`)
page++
}
}
return allRepos
}
async function main () {
try {
const repos = await getAllRepos()
// Sort repositories by creation date
repos.sort((a, b) => new Date(a.created_at) - new Date(b.created_at))
// Prepare CSV data
const csvData = ['Repository,Created Date,Status,Is Private']
const consoleData = []
repos.forEach(repo => {
const status = repo.archived ? 'Archived' : 'Active'
const createdDate = new Date(repo.created_at).toISOString().split('T')[0]
csvData.push(`${repo.name},${createdDate},${status},${repo.private}`)
consoleData.push({
name: repo.name,
created: createdDate,
status: status,
private: repo.private
})
})
// Write to CSV file
fs.writeFileSync('repo_dates.csv', csvData.join('\n'))
// Console output
console.log('\nRepository Creation Dates:')
console.table(consoleData)
console.log(`\nTotal repositories: ${repos.length}`)
console.log('Results have been saved to repo_dates.csv')
} catch (error) {
console.error('Error:', error.message)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment