sigmavirus24 / github3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.
https://github3.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.21k stars 403 forks source link

Organization._api uses faulty URL #618

Open AndreasBackx opened 8 years ago

AndreasBackx commented 8 years ago

Some requests like /repo/:owner/:repo return a users URL for an organization causing further use of the model Organization to act as a user. Requests like Organization.teams built on top of that faulty url causing the url /users/:user/teams which does not exist, it should be /orgs/:org/teams.

Example of what is returned for /repos/:owner/:repo:

{
    "organization": {
        "login": "octocat",
        "id": 1,
        "avatar_url": "https://github.com/images/error/octocat_happy.gif",
        "gravatar_id": "",
        // It shows /users/octocat, but we need /orgs/octocat for getting its teams.
        "url": "https://api.github.com/users/octocat",
        "html_url": "https://github.com/octocat",
        "followers_url": "https://api.github.com/users/octocat/followers",
        "following_url": "https://api.github.com/users/octocat/following{/other_user}",
        "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
        "organizations_url": "https://api.github.com/users/octocat/orgs",
        "repos_url": "https://api.github.com/users/octocat/repos",
        "events_url": "https://api.github.com/users/octocat/events{/privacy}",
        "received_events_url": "https://api.github.com/users/octocat/received_events",
        "type": "Organization",
        "site_admin": false
    }
    // There is more here, this is just the important part
}

This string is set in BaseAccount. In my opinion this is an error in the GitHub API itself because it clearly states the dictionary value is an organization even though it uses user endpoints. It might be worth making an issue for the GitHub API. Currently I would set the _api field in code for the User and Organization models.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/35271803-organization-_api-uses-faulty-url?utm_campaign=plugin&utm_content=tracker%2F183477&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F183477&utm_medium=issues&utm_source=github).
sigmavirus24 commented 8 years ago

So this is absolutely, IMO, something that should be reported to support@github.com. If you can send them an email and CC me, that would be wonderful. We rely on their information to be correct for most things and when that fails, we try our best to not munge their values into correctness unless we absolutely have to.

AndreasBackx commented 8 years ago

The e-mail has been sent, we'll see what their opinion is.

sigmavirus24 commented 8 years ago

So based on the (unsurprisingly) unhelpful conversation with GitHub support, it looks like we should move away from trusting any URLs that the GitHub returns to us and start constructing everything from scratch. 😢