Created
April 24, 2023 14:11
-
-
Save orzklv/510e389ac755b669506f65f77e8dbf9c to your computer and use it in GitHub Desktop.
Transfer all repositories of an organization to another
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'); | |
const GITHUB_TOKEN = 'YOUR_GITHUB_TOKEN'; | |
const SOURCE_ORG = 'SOURCE_ORG'; | |
const TARGET_ORG = 'TARGET_ORG'; | |
const api = axios.create({ | |
baseURL: 'https://api.github.com', | |
headers: { | |
'Authorization': `token ${GITHUB_TOKEN}`, | |
'Accept': 'application/vnd.github+json', | |
}, | |
}); | |
async function transferRepositories() { | |
try { | |
const response = await api.get(`/orgs/${SOURCE_ORG}/repos?type=all&per_page=100`); | |
const repositories = response.data; | |
for (const repo of repositories) { | |
console.log(`Transferring ${repo.name} to ${TARGET_ORG}...`); | |
await api.post(`/repos/${repo.full_name}/transfer`, { | |
new_owner: TARGET_ORG, | |
}); | |
console.log(`Successfully transferred ${repo.name} to ${TARGET_ORG}.`); | |
} | |
} catch (error) { | |
console.error('Error transferring repositories:', error.message); | |
} | |
} | |
transferRepositories(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment