Automate transfer of repository between organizations within the enterprise

Over the course of our work with Github and Github Classroom, we’ve run into some situations where faculty accidentally used our main organization repo for their course, causing thousands of repos to be created in that organization over several semesters of such mistakes.

I’ve written some code using the “octokit.js” library that can get listings of all the repos in an organization and can archive repos in an organization, which work as expected. That still leaves those repos in the main list for the org, so if possible, I’d really like to transfer them to appropriate new orgs of their own within our enterprise.

However, it seems that, while there’s an endpoint in the API to support it and both organizations are within our enterprise, in order to transfer a repo, there has to be a button click acceptance on the new owner repo. For bulk transferring repos in the thousands, that’s a non-starter.

Has anyone successfully scripted this? Is there some webhook we can add/use that allows responding to a repo transfer request in an automated way?

Thanks in advance for any assistance!

Alternatively, you may create a brand new repository in the destination organization that will contain the exact same history of the source repository. This approach certainly requires more coding (e.g. to clone locally, change the Git origin of the branches and push them up) but it should be programmatically doable.

1 Like

Yes, this seems like a good workaround approach. I was hoping that with a repository transfer option available via the API, both sides would be feasible to automate directly, but so far that doesn’t seem to be the case. I’ll give this a shot for now.

1 Like