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

fix: use GitHub App token when authed with GitHub App #103

Merged
merged 5 commits into from
Apr 26, 2024

Conversation

jmeridth
Copy link
Member

@jmeridth jmeridth commented Apr 24, 2024

Fixes #98

Pull Request

Proposed Changes

Currently we are still trying to use the GH_TOKEN env var when making graphql calls even after authenticating with a GitHub App Installation. This change fixes that.

Also fixed a few other things while in here:

  • add all missing env var options to .env-example
  • ensure .env file contents are not used in env var tests
  • alphabetize things, as they should be
  • add test for github auth change token usage

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

Reviewer

  • Label as either bug, documentation, enhancement, infrastructure, maintenance or breaking

@jmeridth jmeridth self-assigned this Apr 24, 2024
@jmeridth
Copy link
Member Author

Still testing this

@jmeridth jmeridth force-pushed the jm-use-app-token-in-graphql-when-using-github-app branch from 66717f0 to 0297d19 Compare April 26, 2024 14:25
@jmeridth jmeridth marked this pull request as ready for review April 26, 2024 14:25
@jmeridth jmeridth requested a review from zkoppert as a code owner April 26, 2024 14:25
Fixes #98

Currently we are still trying to use the GH_TOKEN env var
when making graphql calls even after authing with a GitHub App Installation.
This change fixes that.

Alsof fixed a few other things while in here:

- [x] add all missing env var options to .env-example
- [x] ensure .env file contents are not used in env var tests
- [x] alphabetize things, as they should be
- [x] add test for github auth change token usage

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth force-pushed the jm-use-app-token-in-graphql-when-using-github-app branch from 0297d19 to 9205dd0 Compare April 26, 2024 14:26
@@ -42,6 +42,11 @@ def main(): # pragma: no cover
token, gh_app_id, gh_app_installation_id, gh_app_private_key, ghe
)

if not token and gh_app_id and gh_app_installation_id and gh_app_private_key:
Copy link
Member Author

Choose a reason for hiding this comment

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

core change of this PR

str: the GitHub App token
"""
jwt_headers = github3.apps.create_jwt_headers(gh_app_private_key_bytes, gh_app_id)
url = f"https://api.github.com/app/installations/{gh_app_installation_id}/access_tokens"
Copy link
Member Author

Choose a reason for hiding this comment

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

core change of this PR

.env-example Outdated Show resolved Hide resolved
.env-example Outdated Show resolved Hide resolved
jmeridth and others added 2 commits April 26, 2024 11:55
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
env.py Outdated Show resolved Hide resolved
Co-authored-by: Zack Koppert <zkoppert@github.com>
auth.py Outdated Show resolved Hide resolved
Change from 20 seconds to 5
@jmeridth jmeridth merged commit 70533c5 into main Apr 26, 2024
25 checks passed
@jmeridth jmeridth deleted the jm-use-app-token-in-graphql-when-using-github-app branch April 26, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project Support Permissions
2 participants