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

Use PyGithub to reuse auth headers to do requests #113

Merged
merged 2 commits into from
Jan 26, 2024

Conversation

bwrsandman
Copy link
Contributor

@bwrsandman bwrsandman commented Jan 19, 2024

Clean-up custom url creation and use PyGithub objects for that.
Use PyGithub checker function to catch 400+ codes.

This fixes app authenticated sessions losing the authentication for requests when downloading diffs and posting reviews.
This fixes ~/.netrc authentication hijacking the authentication through the requests library.

Re-use the hashable comment class to filter already posted comments

@bwrsandman bwrsandman force-pushed the authenticated-requests branch 2 times, most recently from 367a47d to a2c3d14 Compare January 19, 2024 21:41
@bwrsandman bwrsandman marked this pull request as ready for review January 19, 2024 21:53
@bwrsandman
Copy link
Contributor Author

@ZedThree this is probably the last set of large PRs for my needs

@bwrsandman
Copy link
Contributor Author

Worth noting that you need specific permissions for an app installation

  • Contents (Read): Download the diff
  • Pull requests (Read and Write): Read and post Review comments

@bwrsandman
Copy link
Contributor Author

bwrsandman commented Jan 19, 2024

I tried getting the pr diff with pull_request.diff_url which is https://github.com/<ORG>/<REPO>/pull/<PR_NUMBER>.diff but the response is empty.
It could be due to the redirection done with githubusercontent.com or something else.

f"WARNING: Couldn't automatically download artifacts for workflow '{workflow_id}', response was: {r}: {r.reason}"
)
return None, None
_, data = pull.repo._requester.requestJsonAndCheck(
Copy link
Owner

Choose a reason for hiding this comment

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

Might be nice to retain the more specific error message if this fails?

Comment on lines +1024 to +1052
unposted_comments = set(map(lambda c: HashableComment(**c), review["comments"]))
posted_comments = set(
map(lambda c: HashableComment(**c), pull_request.get_pr_comments())
)

review["comments"] = [
c.__dict__ for c in sorted(unposted_comments - posted_comments)
]
Copy link
Owner

Choose a reason for hiding this comment

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

This is a lot clearer, thanks!

@ZedThree
Copy link
Owner

I tried getting the pr diff with pull_request.diff_url which is https://github.com/<ORG>/<REPO>/pull/<PR_NUMBER>.diff but the response is empty. It could be due to the redirection done with githubusercontent.com or something else.

Is this something that still needs looking at, or is the PR ready as is?

@bwrsandman
Copy link
Contributor Author

bwrsandman commented Jan 22, 2024

Is this something that still needs looking at, or is the PR ready as is?

It's very minor. I wanted to reduce the custom API stuff but looks like it's needed here.

I am going to put the PR in draft just so I can test it but I will put it back to ready today and you can merge/tag.
Done!

@bwrsandman bwrsandman marked this pull request as draft January 22, 2024 13:52
@bwrsandman bwrsandman marked this pull request as ready for review January 22, 2024 14:16
@bwrsandman
Copy link
Contributor Author

@ZedThree is there anything left to do ?

Copy link
Owner

@ZedThree ZedThree left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @bwrsandman !

@ZedThree ZedThree merged commit 4923dc7 into ZedThree:master Jan 26, 2024
1 check passed
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

2 participants