8000 Add support for repository invitations by jacquerie · Pull Request #877 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

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

Merged

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')
Copy link
Collaborator Author

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.

@jacquerie jacquerie force-pushed the add-repository-invitations branch from e0270d2 to 2b1c696 Compare August 1, 2018 23:28
"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",
Copy link
Collaborator Author

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

@jacquerie jacquerie force-pushed the add-repository-invitations branch from 2b1c696 to 694f52e Compare August 2, 2018 00:30
', '.join(sorted(self.allowed_permissions))
))
url = self._build_url(
'invitations', self.id, base_url=self.repository.url)
Copy link
Collaborator Author

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.)

Copy link
Collaborator Author
@jacquerie jacquerie Aug 2, 2018

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 ?

Copy link
Owner

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.

@jacquerie jacquerie force-pushed the add-repository-invitations branch 2 times, most recently from c467595 to e616115 Compare August 2, 2018 01:53
@@ -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):
Copy link
Collaborator Author
@jacquerie jacquerie Aug 2, 2018

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...

Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Collaborator Author

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...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries :)

@jacquerie
Copy link
Collaborator Author

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.

@jacquerie jacquerie force-pushed the add-repository-invitations branch 2 times, most recently from 688fbfe to 6978022 Compare August 2, 2018 11:38
@jacquerie
Copy link
Collaborator Author

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

This is no longer true thanks to @michamos !

@jacquerie jacquerie changed the title WIP Add support for repository invitations Add support for repository invitations Aug 2, 2018
@jacquerie jacquerie force-pushed the add-repository-invitations branch from 6978022 to 3a55874 Compare August 2, 2018 16:50
class TestAuthenticatedUser(IntegrationHelper):
"""Integration tests for the AuthenticatedUser object."""

def test_repository_invitations(self):
Copy link
Owner

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:

Copy link
Owner
@sigmavirus24 sigmavirus24 left a 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
@jacquerie jacquerie force-pushed the add-repository-invitations branch from 3a55874 to 61476a4 Compare August 5, 2018 15:12
@sigmavirus24 sigmavirus24 merged commit 37b3cf9 into sigmavirus24:master Aug 5, 2018
@sigmavirus24
Copy link
Owner

Thanks so much for addressing that feedback so quickly!

@jacquerie jacquerie deleted the add-repository-invitations branch August 5, 2018 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0