|
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() |