Add RepositoriesService method GetByID for fetching a repository by its numeric ID#60
Add RepositoriesService method GetByID for fetching a repository by its numeric ID#60sqs wants to merge 1 commit into
Conversation
|
interesting, I had no idea this existed... kinda cool. I've certainly run into the renaming issue as well. It looks like at least some of the other repo-related endpoints have equivalents using this style. For example:
My only hesitation with adding |
|
You can rely on it. In fact, we encourage it, since repository names can change. We actually rewrite endpoints like "repos/owner/name/" to "repositories/123/". Edit: I should add, there's a similar endpoint for users: "/user/:id". |
|
Thanks, @technoweenie! @willnorris Yeah, it would essentially double the number of methods to support both owner/repo and ID schemes, which would not be ideal. I suppose there could be only one method to handle both cases that would take a parameter that has a concrete value of either If we were starting from scratch, I would probably want this latter solution. |
|
@sqs Aside from Google, I suspect that SourceGraph is one of the larger users of the library. If you're fine with the change, I don't mind either at this stage. Would you mind taking a first pass at supporting both name and ID in a single function? The thing to keep in mind is that URL construction will need to change as well, since it's different for different identifiers... |
|
Yep, will do. |
|
FWIW, just noting it here in case anyone else experiences a similar issue, I noticed that there are some cases where the "owner/repo" endpoint succeeds and the numeric ID repositories endpoint fails (intermittently). E.g., right now, So far we haven't noticed a big difference in reliability, but now that we're aware of the potential for different behavior, we'll be on the lookout. |
|
Closing and moving discussion to the more general potential solution at #68. |
This PR adds a
GetByID(id int)method toRepositoriesServicethat fetches a GitHub repository by its numeric ID from the undocumented/repositories/:idendpoint.Being able to fetch a repository by its ID is useful for tracking it when its name changes. The API does not redirect from the old name to the new name (and even if it did, if you created a 2nd repo with the old name, the redirect would have to be removed). The numeric ID is also useful because it takes up less space than the (owner, name) tuple.
Users should use this method with caution⚠️ because it uses an undocumented API endpoint. @willnorris, if you think it's a bad idea to merge this method in, I would understand.