Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Created November 17, 2021 22:24
Show Gist options
  • Save royashbrook/edf49fb6fd03b18c03471ec0715d3360 to your computer and use it in GitHub Desktop.
Save royashbrook/edf49fb6fd03b18c03471ec0715d3360 to your computer and use it in GitHub Desktop.
transfer git repo to new owner with js
const { Octokit } = require("@octokit/core")
// you need a personal access token that controls the repos, once you get one, put it down below
const octokit = new Octokit({ auth: `REPLACEME!!!` });
octokit.request('GET /user/repos', {
type: "private",
per_page: "100"
})
.then(x => x
.data
.filter(x => /FO.+/g.test(x.full_name))
.forEach(x =>
// this will just log it. the octokit call below is what i used to move
// note that you need to replace the owner with the current owner
// or figure out a way to pass that in and you need a new owner that you want
// to use. i had spotty results with the catch, but this was just a one time
// use for me so i didn't chase it or mess with it
console.log(x.full_name)
// octokit.request('POST /repos/{owner}/{repo}/transfer', {
// owner: 'REPLACEME!!',
// repo: x.name,
// new_owner: 'REPLACEME!!'
// })
// .then(x => console.log(`repo moved to ${x.full_name}`)) //this yields undefined, but i didn't mess with it after things were moved
// .catch(x => console.log('failed to move', x))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment