Search code examples
githubgithub-apirenaming

How to access a renamed private GitHub repo via its new name


After I have renamed a private GitHub repo from foo/bar to foo/qux via the UI, if I try to get

https://api.github.com/repos/foo/qux

I get a 404.

If I request via the old name (https://api.github.com/repos/foo/bar) I get a redirect. But in general I don't have the previous repository names to work with so that's not an option.

The best solution I can think of is to get https://api.github.com/user/repos, page through all the repos and find the repo named foo/qux. But this sucks, and I'm sure the GitHub UI is not doing this when I go to https://github.com/foo/qux. So is there an easier way to get the ID of the repo now named foo/qux?


Solution

  • It appears the GitHub API will respond with a redirect for the old private repository name even if you don't have permission to read the repository itself (which is why I was getting a 404 when I requested it by its new name or even its numeric ID).

    This led me to mistakenly conclude that the API knew about the old name but not the new name.

    Select the "Full control of private repositories" scope on the personal auth token and you should be able to request a private repository by its new name.