GitHub repositories are often busy with resources constantly being updated. It is not just files that can added or removed but two other attributes: repository owner and repository name could change too. In such scenarios, if you are using the GitHub API to track a certain repository, chances are you would get a 404 Not Found. With an upcoming version 3 release in July, GitHub API will support redirects that will provide you with the new location so that your application does not break.
GitHub identifies a repository location by its owner name and repository name. As per the blog post, GitHub will mark the repository location as changed if:
- The owner changes the repository name.
- The owner renames the user account or organization name.
- The owner transfers ownership to a new owner.
Any of the above changes results in a 404, and that is what the redirects API functionality will address. The feature was announced in preview mode in April, and it is ready for a full rollout in the v3 release starting July 21.
The redirects feature is available to all developers today, and all you need to do is provide the custom media type in the Accept header as given below:
If you make a call with the repository’s old name, you will get a HTTP 301 or 307 Redirect, and you can use that redirect link to the new location.