Skip to content

Conversation

@dblanchette
Copy link
Contributor

This adds support for GitHub App authentication using the main class which is simpler for users (see #1855)

import Github

github_client = Github(app_id=MY_APP_ID, app_private_key=MY_PRIVATE_KEY)

Also, the credentials are refreshed when needed (tokens lasts for one hour). This should happen transparently to the users, as the token expiration is checked at every call.

Caveats and other notes:

  • Uses the first found installation for an app. This means that it only works in the context of private apps
  • I'm not sure how to add tests correctly and there does not seem to be any for GithubIntegration, so I skipped that part. Manual testing works and existing tests are not broken
  • I could not resist fixing some type stubs along the way

@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2021

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Contributor Author

@dblanchette dblanchette left a comment

Choose a reason for hiding this comment

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

Added some comments for easier reviewing.

deploymentStatusEnhancementsPreview = "application/vnd.github.flash-preview+json"


DEFAULT_BASE_URL = "https://api.github.com"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved those here since they are used in 2 files now (MainClass and GithubIntegration)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Comparing this is really difficult. Would have been better to do the refactoring (without changes) in a separate PR and base this PR on that. Then we would see only changes, not moving unchanged code around.

"""

def __init__(self, status, data, headers):
def __init__(self, status, data, headers=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a 404 while testing and had an exception because the headers parameters was not passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There seems to be a fix there for the same issue: #2079

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think fixing the calling code as in #2079 is better than changing the signature.

@@ -0,0 +1,140 @@
import time
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from MainClass, it's already big as it is and that does not really belong there.

status=response.status_code, data=response.text
)

@deprecated.deprecated("Use get_repo_installation")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if that does not suit you. I feel that this call is badly named

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the existing call? It should probably also state it's deprecated in the docstring. Also, it should mention the class, not just the bare function.

def get_repo_installation(self, owner, repo):
return self.get_installation(owner, repo)

def get_installations(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part I added in that file. Users having a private app with more than one installations can use this call as the main class always uses the first found installation.

):
self._initializeDebugFeature()

self.__installation_authorization = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The heart of the changes I made is here!

@maxdanilov
Copy link

also very interested in seeing this implemented, are there any updates on this feature?

@simkimsia
Copy link
Contributor

Will this be integrated?

@jonapich
Copy link

@s-t-e-v-e-n-k sorry to ping you directly; there hasn't been any feedback from the maintainers on this PR for close to a month now and I'm not sure who's in charge. What can we do to speed up things and help you out?

@tscully49
Copy link

Would also really like to see this feature! How can we help?

@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 8, 2022
@ghost
Copy link

ghost commented Jan 10, 2022

Hi, Could you merge this PR?

@stale stale bot removed the stale label Jan 10, 2022
@ThomasJRyan
Copy link

Would definitely appreciate this feature being merged in

"""

def __init__(self, status, data, headers):
def __init__(self, status, data, headers=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think fixing the calling code as in #2079 is better than changing the signature.

@dblanchette
Copy link
Contributor Author

Thanks for the review! I made the requested changes.

@dblanchette
Copy link
Contributor Author

@EnricoMi @ThomasJRyan Anything else I should do?

@dblanchette
Copy link
Contributor Author

I went and look at all the files I changed to make sure there were no default values left in pyi. Crossing my fingers that everything is ok now 🤞

@dblanchette
Copy link
Contributor Author

I hate to ask again, but is it all good?

I'm looking forward to go back to using the official library instead of our fork.

Thanks for your work maintaining this library!

@dblanchette
Copy link
Contributor Author

Now fails tests with E AttributeError: module 'github' has no attribute 'AppAuthentication'

That is fixed. I must say I find the imports in this project to be done in a peculiar fashion.

@dblanchette
Copy link
Contributor Author

Comparing this is really difficult. Would have been better to do the refactoring (without changes) in a separate PR and base this PR on that. Then we would see only changes, not moving unchanged code around.

Agreed. I tend to go all out in refactoring as you've seen with the unrelated changes. I'll know to do that in the future.

Thank you both for the reviews!

@dblanchette dblanchette requested review from EnricoMi and s-t-e-v-e-n-k and removed request for EnricoMi and s-t-e-v-e-n-k February 1, 2023 16:23
@dblanchette
Copy link
Contributor Author

All good now? I'm excited to see this release :)

@dblanchette dblanchette requested a review from EnricoMi February 3, 2023 14:29
@s-t-e-v-e-n-k s-t-e-v-e-n-k merged commit 5e27c10 into PyGithub:master Feb 6, 2023
@EnricoMi
Copy link
Collaborator

@dblanchette can you please take a look at #2420 / #2425?

@EnricoMi
Copy link
Collaborator

@dblanchette another issue likely being introduced by this PR: #2431

@EnricoMi
Copy link
Collaborator

Another issue: #2432

@EnricoMi
Copy link
Collaborator

EnricoMi commented Mar 1, 2023

This is quite some fallout, another issue reported: #2436

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.