mirage / ocaml-github

GitHub APIv3 OCaml bindings
ISC License
100 stars 61 forks source link

Reintroduce user type #228

Closed Aaylor closed 4 years ago

Aaylor commented 5 years ago

Problem

TL;DR: There is no simple way to know if a "user" is an Organization or a simple User from the GitHub POV.

I've seen that the type user_type was removed, in favor of splitting user in two distinct part: user and org.

When we do not have a complete control about the GitHub username (coming from a user input for example), it becomes hard to know if we are talking about an organization or a user; the only way I found would be to call /orgs/:user first: if it returns 404, then it may be a user, otherwise it is an organization.

As an example, if we want to get information of a specific repository (for the example, let's say the ocaml repository from the ocaml organization), there is a need of extra works to know if the repository owner is an organization or a user.

Chosen solution

Reintroduce the type user_type, and adding them to both user and org type; this is the simplest solution to ensure the backward compatibility with older versions.

Other solution

Having a type looking like

type github_user =
  | User of user_info
  | Org of organization

And everywhere we may have one or another (repository owner, fetching a specific user, ...) using this type. Otherwise using the concerned type (organization when listing a user organization for example).

(Sorry, this small PR comes right after you released the last version :/)

avsm commented 4 years ago

Sorry I missed this! I'll release it along with your #230 PR