-
Notifications
You must be signed in to change notification settings - Fork 406
Add support for repository invitations #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for repository invitations #877
Conversation
self.token_login() | ||
cassette_name = self.cassette_name('invitations') | ||
with self.recorder.use_cassette(cassette_name): | ||
repository = self.gh.repository('jacquerie', 'flask-shell-bpython') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I needed a repository for which I have admin rights, otherwise it returns a 403.
e0270d2
to
2b1c696
Compare
"git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", | ||
"git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", | ||
"git_url": "git:github.com/octocat/Hello-World.git", | ||
"hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note that I added this manually because it's not part of the response documented by GitHub's API documentation: https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation
2b1c696
to
694f52e
Compare
', '.join(sorted(self.allowed_permissions)) | ||
)) | ||
url = self._build_url( | ||
'invitations', self.id, base_url=self.repository.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This URL-building logic is repeated in delete
and update
. Should I do it once in _update_attributes
and assign to self._api
? (The url
returned by the API is sadly not the right one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crux of the issue is that there's two API URLs, one used by the inviter to cancel/update an invitation, the other used by the invitee to accept/decline. WDYT of computing two private properties called _invitee_api
and _inviter_api
in _update_attributes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We build/rebuild URLs in a few places. I don't think it's the worst thing to have these work this way.
c467595
to
e616115
Compare
src/github3/users.py
Outdated
@@ -742,6 +742,23 @@ def _update_attributes(self, user): | |||
if self.plan is not None: | |||
self.plan = Plan(self.plan, self) | |||
|
|||
def repository_invitations(self, number=-1, etag=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silly question, but should this method have the requires_auth
decorator? I guess that if one has an AuthenticatedUser
in their hand it's a given that they authenticated at some point, but I can see an argument for being even more explicit about it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had hopes of using the decorator to update docstrings so that users can see in the documentation which methods require them to have valid authentication and which can be used anonymously. I think on similar objects we haven't been as disciplined so it's okay to simply ignore it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so here's the other thing. Right now GitHub
has most of the endpoints that are /user/repository_invitations
like. So this means that this method probably belongs there and should also probably have the @requires_auth
decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now
GitHub
has most of the endpoints that are/user/repository_invitations
like.
Ah, silly me for missing this! I was surprised to see no methods in AuthenticatedUser
, I should have noticed this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
This is kind of done, except for the questions above and the fact that I'm missing the integration tests of this feature from the users' point of view, since I'd need someone else to invite me to some repository to record the test fixtures. |
688fbfe
to
6978022
Compare
This is no longer true thanks to @michamos ! |
6978022
to
3a55874
Compare
tests/integration/test_users.py
Outdated
class TestAuthenticatedUser(IntegrationHelper): | ||
"""Integration tests for the AuthenticatedUser object.""" | ||
|
||
def test_repository_invitations(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You won't need to re-record this test to move the method to the GitHub
object. You can just rename the cassette to GitHub_repository_invitations.json
in the cassettes directory and it should Just Work:tm:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple changes necessary, but otherwise this looks excellent.
Add support for the repository invitations API documented in https://developer.github.com/v3/repos/invitations/. Closes sigmavirus24#739
3a55874
to
61476a4
Compare
Thanks so much for addressing that feedback so quickly! |
Closes #739