Commit Graph
175 Commits
Author SHA1 Message Date
Enrico Minack ea45237d3b Sync GithubIntegration __init__ arguments with github.Github (#2556)
Github and GithubIntegration now both support the same (full) set of Requester arguments.
Creating a Github instance for a Github App Installation coming from GithubIntegration uses the same
Requester arguments (except for auth).
2023-06-21 09:04:19 +02:00
Trim21andEnrico Minack cb50dec5ba Merge PaginatedList.pyi back to source (#2555)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
2023-06-20 08:13:20 +02:00
b6258f4be9 merge GithubObject.pyi/Requester.pyi stubs back to source (#2463)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
Co-authored-by: Jonathan Leitschuh <jonathan.leitschuh@gmail.com>
2023-06-16 11:57:35 -04:00
Enrico Minack f291a368bb Implement AppUserAuth for Github App user tokens (#2546)
Allows to refresh Github App user token. Integrates `ApplicationOAuth` into `github.Auth`.
2023-06-14 19:40:29 +02:00
Enrico Minack 7be3f76372 Make Requester.__createException robust against missing message and body (#2159) 2023-06-13 11:14:14 +02:00
Enrico Minack 6407512079 Fix auth issues with Installation.get_repos (#2547) 2023-06-13 08:35:47 +02:00
Enrico Minack fc2d0e150a Add authentication classes, move auth logic there (#2528)
This adds argument `auth` and deprecates `login_or_token`, `password`, `jwt`, and `app_auth` arguments of `github.Github`.

This adds argument `auth` and deprecates `integration_id`, `private_key` of `github.GithubIntegration`.

This deprecates the `create_jwt` method of `github.GithubIntegration`, replaced by `github.Auth.AppAuth.create_jwt`.
2023-06-08 09:17:25 +02:00
Enrico Minack 17cd0b7964 Raise error on unsupported redirects, log supported redirects (#2524) 2023-05-13 20:36:08 +02:00
Enrico Minack 45f3d723ce Remove RLock from Requester (#2446) 2023-03-15 09:40:43 +11:00
Phillip Tran bdceae2f52 pass requester base URL to integration (#2420) 2023-02-20 13:29:04 -06:00
5e27c10a31 Support full GitHub app authentication (#1986)
* Support full GitHub app authentication
 Refactor GithubIntegration class and add test case for app authentication
Add permissions and repository properties in InstallationAuthorization
Set JWT_EXPIRY=60 by default in GithubIntegration constructor
* Modify existing testcases for GithubIntegration as per the framework and add missing tests
* Provide installation ID for creating the access token instead of getting the first installation
* Add optional permissions support for installation access token
* Add lock around app authentication
* Keep compatibility for importing GithubIntegration from MainClass
* Group app authentication parameters in a class

Co-authored-by: Malik Ammar Akbar <malikammar.akbar@pfizer.com>
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
2023-02-06 20:50:15 +11:00
Liuyang Wan 7e6333da1a Fix CI (#2330) 2022-10-13 08:56:18 +08:00
Mark Walker ab36b89aa5 Fixed links to github docs. [#2009] 2021-07-31 02:34:34 +01:00
Steve Kowalik 1265747e99 Do not transform requestHeaders when logging (#1965)
Requester.__log() sanitizes the headers of the request so that
authentication details are not logged, but this has the side effect of
meaning that future requests that use the same Requester object will
fail. Usually, this is perfectly fine, since almost every method will
only make one request -- where this falls down is when we make another
after a redirect. Make a copy of the requestHeaders, and sanitize those.

Fixes #1959
2021-06-02 15:00:00 +10:00
Steve Kowalik babcbcd04f Update most URLs to docs.github.com (#1896)
Now that GitHub have moved their documentation from
developer.github.com, we should update our links. I have also tried to
update the call strings to their new format, but since it was done via
regex, some of them may not match exactly.
2021-03-26 20:43:48 +11:00
Steve Kowalik 916da53bef Re-raise the exception when failing to parse JSON (#1892)
Since GitHub has the bad manners to return bare strings for some API
endpoints, one sharp edge has been that JSON decoding errors were masked
since we wrap the string in a dictionary. However, this makes it
difficult to debug malformed JSON in replay data, so re-raise the
exception if the first character is a { or [ (IE, it's an object or
list.)
2021-03-24 13:56:54 +11:00
Steve Kowalik 901af8c862 Remove client_id/client_secret authentication (#1888)
Authenticating via client_id and client_secret is dangerous, since they
appended to the query string, and can be easily seen from the URL.

client_id/client_secret have been deprecated since May 2020, and ignored
by GitHub since late 2020, so it's high time they were removed.
2021-03-23 14:48:47 +11:00
Steve Kowalik ddd437a7cd Export headers in GithubException (#1887)
Since the headers that led to an exception are also useful, firstly pass
them into the constructor, and then export them in a property. Test one
specific use case to make sure of coverage.

Fixes #1814
2021-03-23 13:47:05 +11:00
Steve Kowalik 290b62726f Switch all string addition to using f-strings (#1774)
Now that we no longer support Python 3.5, stop using string addition
everywhere it makes sense, and move to the best feature 3.6+ gives us,
f-strings!
2021-03-03 14:50:57 +11:00
Amador Pahim a77d4f48cb Enabling connetion pool_size definition
requests has a default connections pool of 10. Creating multiple threads
will consume from that same pool, since the underlying implementation of
the requests pool is a singletown.

Let's make the pool_size configurable, so clients can set the proper
number for their use case when running multiple threads.

Signed-off-by: Amador Pahim <apahim@redhat.com>
2021-01-08 11:55:36 +00:00
Amador Pahim aaec0a0f0f Always define the session adapter
This represents no change of behaviour, but it enables us to set more
options to the adapter.

Signed-off-by: Amador Pahim <apahim@redhat.com>
2021-01-08 11:55:36 +00:00
Steve Kowalik e113e37de1 Add pyupgrade to pre-commit configuration (#1783)
To help us switch to f-strings and other 3.6+ changes, add pyupgrade to
our pre-commit configuration to keep the codebase clean.
2020-12-15 14:07:33 +11:00
Jesse Li a778639362 upload_asset with data in memory (#1601)
* Expose upload from memory functionality
* Upload from memory basic test
* Test for custom file like object
* Reorganized existing release tests
* Remove docstrings & comments from tests
* Modify logic
* Explain why encode ignores its argument

Fixes #1140
2020-08-03 18:42:06 +10:00
Rigas Papathanasopoulos 4b43711017 Add OAuth support for GitHub applications
Create the ApplicationOAuth class which is responsible for
handling a GitHub application's OAuth authorization process.
2020-04-28 22:10:48 +03:00
Steve Kowalik b7894ea00c Drop Python 2 support (#1329)
With the Python 2 deadline gone, it's time to move with the times and
switch to Python 3 only.
2020-01-06 18:01:38 +11:00
Steve Kowalik 88e30057a7 Remove API preview parameter (#1325)
The API preview flag for both MainClass and Requester was the last
hard-coded custom header, and it seems to not be relevant since
mid-2015. Remove it, if any users are using it, they shouldn't be. Its
code path was also entirely untested.
2019-12-29 10:49:45 +11:00
Steve Kowalik b0ef1909f9 Refactor Logging tests (#1315)
To stop skipping logging tests on Python 3, refactor them to mock out
the logger and check arguments directly, rather than naively comparing
strings. Allow a logger to be injected into Requester for this.
2019-12-11 16:02:14 +11:00
Wan Liuyang 6ceb9e9a15 Apply black to whole codebase (#1303) 2019-12-10 17:14:33 +08:00
Steve Kowalik 6ad592b1b6 Correct header check for 2FA required (#1274)
Currently, we were checking for an uppercase header if GitHub was
refusing our authentication because we didn't provide a token. Requests
returns headers with all lowercase. Fix the const, and add a test for
good measure.

Fixes #1273
2019-10-25 21:01:58 +11:00
Steve Kowalik a0f01cf9cf Remove more Python version specific code (#1193)
Remove a bunch of other call sites that behaved differently between
Python 2 and 3, massively cleaning up a few messy methods.
2019-08-28 15:24:54 +10:00
Steve Kowalik cca8e3a5b4 Remove some uses of atLeastPython3 (#1191)
There are a number of call sites that would behave differently depending
on Python 2 or 3. A fair amount of them are left over from Python 3.2 or
Python 2.6 were the current versions, and it was much harder to write
compatible code for both versions. Happily, that is now in the past, so
refactor some of them out.
2019-08-05 16:14:39 +10:00
Steve Kowalik f93207b4ca Run flake8 in Travis (#1163)
Clean up a few errors I missed, ignore another, and configure flake8 using
a config file to ignore certain errors. The next step would be to remove
the F* ignores.
2019-08-05 15:03:10 +10:00
Steve Kowalik dc2f2ad8cb Switch to using six (#1189)
With the Python 2.7 deadline fast approaching, modernize the codebase
making use of the modernize module to switch to using six, as well as
other upcoming features, such as absolute imports . Stop using 2to3
for Travis, yay!
2019-08-05 14:06:19 +10:00
Steve Kowalik 828b53b756 Silence more flake8 errors (#1160)
Make more whitespace changes to silence flake8 errors under the github
directory only.
2019-07-02 17:55:04 +08:00
Steve Kowalik b8dad9817e Clean up a lot of pyflakes warnings (#1153)
Clean up unused imports or unused variables to mostly silence pyflakes.
We aren't quite yet in a place where we can run it via Travis, but baby
steps.
2019-07-02 18:06:09 +10:00
Isac Souza 5ae7af55ea Adding communications Retry functionality into requests via urllib3 retry object. (#1002)
This is a continuation of the work started by @allevin on https://github.com/PyGithub/PyGithub/pull/860.

I have refactored the testing Framework to use the `httpretty` library in order to use the urllib3 retry feature and therefore be able to test it.

Please refer to https://github.com/PyGithub/PyGithub/pull/860 for additional context.

cc: @allevin @mfonville @jrouquie @sfdye

Closes #757 
Closes #860
2019-04-05 13:49:01 +08:00
Shubham Singh b4d895eddd Adding migration api wrapper (#899)
Closes #818
2018-12-21 12:01:01 +08:00
Arda Kuyumcu 8ccf9a9485 Add support for JWT authentication (#948)
APIs such as https://developer.github.com/v3/apps/#find-organization-installation use a JWT for authentication. Adding support for JWT auth.
2018-10-31 08:11:50 +08:00
Tuuu Nya 972446d5bf Fix unable to trigger RateLimitExceededException. (#943)
I found when authorized, the ratelimit error message is different from unauthorized.

so i add this.

After studying hard with my 2b colleagues @AnYeMoWang , we finally realized how tests wrote.

😸 😸 😸 😸 😸 😸 😸
2018-10-23 17:03:03 +08:00
Steve Kowalik 6833245d99 Fix handling of 301 redirects (#916)
Requester.__requestRaw() was handling 301 redirects by passing the full
URL to itself, when it only expects a URL path, so parse out the path,
and pass that in. Add a test for this behaviour.

Closes: #906
2018-10-04 21:41:17 +08:00
Wan Liuyang ae5cdb285e Refactor common header constants and custom media type 2018-08-21 15:01:23 +08:00
Wan Liuyang 3f0caa4057 Sync copyright header 2018-08-19 10:47:41 +08:00
Dylan 43d325a552 Add allow_redirects option (#858)
Fixes #830

Latest release v1.40 has broken get_archive_link
https://github.com/PyGithub/PyGithub/issues/830
2018-08-19 10:41:32 +08:00
Maarten Fonville 3aead15818 Handle HTTP 202 HEAD&GET with a retry (#791)
* Handle HTTP 202
Fixes #564
After some testing, it seems GitHub seems to be able to process the chrunching of statistics
for every repository I tested in around 2 seconds. So a delay of around 5 seconds should be
plenty to be very certain that the next try should succeed.
Another option would be to put this value lower and possibly waste an extra retry on it.

* Only re-request data if HEAD or GET (those are 'safe')
to e.g. avoid running a duplicate POST or PUT, that can change stuff on the server
Using RFC 2616 and https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html as guideline

* Fix testStatistics

* change wait time to 2 secs
2018-06-22 16:54:32 +08:00
Maarten Fonville 8bdac23ca1 Fix github API requests after asset upload (#771)
In the old code the self.__hostname would be overwritten with uploads.github.com
but it could not be correctly re-set to api.github.com after completing the upload
Create a separate connection if hostname or port differ in requestBlobAndCheck

in the end this became quite a large overhaul, to also make this change generic
for e.g. connecting to status.github.com and similar methods

~~not sure if tests need (more) updating, if so I will update the PR accordingly~~
2018-06-22 12:46:46 +08:00
Maarten Fonville 23395f5f14 Fix Content-Length invalid headers exception (#787) 2018-05-17 14:05:32 +08:00
Mike Miller 85a9124b09 Add ability to skip SSL verify from requests (#758) 2018-04-26 14:46:44 +08:00
Mike Miller 9aed19ddbe Use 'requests' instead of 'httplib' (#664)
* works (but tests fail)

* Refactor to use python requests rather than httplib

* add requests dependency in setup.py

* touch so travis-ci will run

* clean up some unused comments

* Handle HTTP vs HTTPS; handle custom base_url

* Use requests session

* Don't use a persistent session in tests (which don't use the real requests library)

* Use an older version of requests for python 3.2

Requests dropped support for Python 3.2 in the 2.10 series (though it
didn't detect this until 2.11).

PyGithub probably doesn't need to support Python 3.2 at all; it's quite
old, with negligably few users, but that should be addressed elsewhere.

* Revert "Use an older version of requests for python 3.2"

This reverts commit fb0367614f5413968eeab98f4094e710aa1bc2d1.

* Improve readability

* Update requirements.txt

* Disable custom proxy handling code (unneeded and broken); use requests'

* Remove comment and superflous code

* Fix iteritems() removal from Python3

* pin requests to 2.14.0 or greater in prep for no_proxy

* pin requests to 2.14.0 or greater in prep for no_proxy
2018-04-17 10:25:42 +08:00
sfdye 365a0a24d3 Apply fix_headers script to update copyright info 2018-03-17 20:06:16 +08:00
sfdye 58e1ef9ccb Fix copyright formatting 2018-03-13 22:30:47 +08:00