Skip to content
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

Reworking GithubIntegration #2461

Closed
wants to merge 11 commits into from

Conversation

EnricoMi
Copy link
Collaborator

@EnricoMi EnricoMi commented Mar 19, 2023

The GithubIntegration (Github App installations) can be used as follows:

gi = GithubIntegration(app_id, private_key, ...)
ri = gi.get_repo_installation(owner, repo)
gh = gi.get_github_for_installation(ri.id, permissions)

Then, gh is a github.Github instance, authenticated as Github App installation ri.

The arguments of Github(...) and GithubIntegration(...) have to stay in sync, except for those related to authentication. A test is added to assert this.

Allows Requester(jwt=...) to be given a method instead of a static token string. That method is called whenever a request is made. This ensures the JWT token (which has an expiry) is always up-to-date.

A Requester(app_auth=...) asks app_auth._get_access_token_func to return a function that provides an active token. Method _get_access_token_func reuses a requester (the calling requester) with JWT authentication. The caching and refreshing is moved into AppAuthentication.

All requesters use the same values for verify, retry, base_url, ... as given to GithubIntegration(...).

Btw., current AppAuthentication is better called AppInstallationAuthentication, as it authenticates an Github App installation (app id, private key, installation id). The (app id, private key) tuple is used to authentcate as an Github App (e.g. to fetch installations), so that is better called AppAuthentication.

With this rework, I don't see a need for users to call create_jwt or get_access_token, they will expire anyway.

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2023

Codecov Report

Patch coverage: 98.21% and project coverage change: +0.01 🎉

Comparison is base (822fc05) 98.77% compared to head (892b6e9) 98.79%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2461      +/-   ##
==========================================
+ Coverage   98.77%   98.79%   +0.01%     
==========================================
  Files         117      117              
  Lines       11674    11673       -1     
==========================================
+ Hits        11531    11532       +1     
+ Misses        143      141       -2     
Impacted Files Coverage Δ
github/AppAuthentication.py 97.91% <97.36%> (-2.09%) ⬇️
github/GithubIntegration.py 97.05% <100.00%> (+0.44%) ⬆️
github/MainClass.py 99.23% <100.00%> (+<0.01%) ⬆️
github/Requester.py 98.19% <100.00%> (+0.77%) ⬆️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@trim21
Copy link
Contributor

trim21 commented May 13, 2023

can we just have inline type annotation for new file?

@EnricoMi EnricoMi added this to the Version 1.59.0 milestone Jun 13, 2023
@EnricoMi
Copy link
Collaborator Author

Fixed by #2528 and #2556.

@EnricoMi EnricoMi closed this Jun 19, 2023
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.

None yet

3 participants