Commit Graph
140 Commits
Author SHA1 Message Date
Enrico Minack 8bf542aedd Pass Requester arguments to AppInstallationAuth.__integration (#2695) 2023-08-28 15:43:49 +02:00
YugoHinoandEnrico Minack a7bfdf2d65 Adding feature for enterprise consumed license (#2626)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
2023-08-17 21:21:20 +02:00
Jirka Borovec 13e178a3ab Set line length to 120 characters (#2599) 2023-07-13 17:37:20 +02:00
Enrico Minack bc68626941 Publish version 2.0.0 (#2583) 2023-07-04 07:59:53 +02:00
Enrico MinackandJohn T. Wodder II 0177f7c513 Make datetime objects timezone-aware (#2565)
Comparing timestamps returned by the API with naive datetime objects (without timezone information) will raise an error. Add `tzinfo=datetime.timezone.utc` to your datetime instance.

Co-authored-by: John T. Wodder II <git@varonathe.org>
2023-06-28 21:47:48 +02:00
Enrico Minack 99155806ed Throttle requests to mitigate RateLimitExceededExceptions (#2145)
This introduces a throttling of requests to the Github REST API (1s for writes, 0.25s for reads, configurable)
to mitigate secondary rate limit errors and comply with Github's best practices:

https://docs.github.com/en/rest/guides/best-practices-for-integrators?apiVersion=2022-11-28#dealing-with-secondary-rate-limits
2023-06-28 21:38:29 +02:00
Enrico Minack 0bb72ca004 Retry retryable 403 (rate limit) (#2387) 2023-06-28 12:49:20 -04:00
Enrico Minack 14ae2cad4c Release 1.59.0 (#2563) 2023-06-22 19:41:10 +02:00
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
Jonathan GregandEnrico Minack 517ad33654 Add Webhook Deliveries (#2508)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
2023-06-20 08:49:02 +02:00
chantra 6d4b6d1419 Add support for get_app() with App authentication (#2549)
Moves `Github.get_app()` called without `slug` parameter into `GithubIntegration`, because it needs an `AppAuth`,
and we collect all such endpoints there. Calling `Github.get_app()` without `slug` parameter is now deprecated.

Replaces `datetime.utcnow()` with `datetime.now(timezone.utc)`, as it is deprecated in Python 3.12.
2023-06-16 08:09:16 +02:00
Enrico Minack 84912a675c Make MainClass.get_app return completed GithubApp when slug is given (#2543)
Fixes slug attribute to fetch app when not set. Loads app with slug lazily, fetch complete app without slug.
2023-06-08 10:06:28 +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
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
Steve Kowalik f1faf941ec Cover all code paths in search_commits (#2087)
The search_commits method was only very lightly tested, meaning over
half of it was not covered. Write another test case, covering all code
paths.
2021-10-22 08:39:31 +11:00
Mark Walker ab36b89aa5 Fixed links to github docs. [#2009] 2021-07-31 02:34:34 +01:00
Sachi King e4168109dd Use property decorator to improve typing compatibility (#1925)
As a property these functions are expected to be accessed without the
private __get_ and __set_ functions, however while the functions are
typed, the property is not, and mypy shows an attribute error.

As this codebase no-longer requires support for python versions without
support for @property.setter(2.6?) this updates the functions to use
decorators and updates the type files to reflect the attribute
existence.
2021-04-26 14:23:34 +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 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 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
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
Steve Kowalik 19e46bbf90 Remove older MainClass.get_installation() (#1738)
There are two get_installation() methods in MainClass, with different
arguments. get_installation(owner, repo) is documented and tested, and
get_installation(id) is neither. Remove it to avoid confusion.
2020-11-11 18:14:55 +11:00
Omar Brikaa 4cfc9912c0 Added a method for getting a user by their id (#1691)
* Added a method for getting a user by their id

* Added get_user_by_id to MainClass stubs

Fixes #1615
2020-11-10 14:52:58 +11:00
Mahesh Raju 260558c101 Add initial support for Github Apps. (#1631)
* Add initial support for Github Apps.

Needed for #1621
2020-08-09 19:04:41 +10:00
Jannis Gebauer 2002d8b2cb Merge pull request #1021 from rigaspapas/implement-apps-oauth-endpoints
Implement OAuth for apps
2020-07-20 11:51:32 +02:00
Steve Kowalik 3668f866e3 More precise typing for MainClass.get_user() (#1575)
Use typing.overload for MainClass.get_user() since it can return two
disparate types. Correct the docstring for it, as well as locking down
Sphinx to <3 due to built docs issue and drive-by link correction.

Fixes #1550
2020-06-24 16:21:18 +10:00
Denis Blanchette cc1b884c98 Remove "api_preview" parameter from type stubs and docstrings (#1559) 2020-06-18 18:30:33 +10:00
Steve Kowalik 2475fa669a Raise a FutureWarning on use of client_{id,secret} (#1506)
client_id and client_secret are sent to GitHub encoded on the query
string, which GitHub has firmly deprecated, so much so as to email
people who are doing so. To discourage its use, raise a FutureWarning if
they are specified.

Fixes #1500
2020-05-05 21:23:22 +10:00
Florent Clarret 63855409b9 feature: get the project column by id (#1466)
Add a method to fetch a project column by id.

Fixes #1057
2020-05-01 12:01:09 +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
Nikolay Edigaryev 5cf9950b25 Ability to retrieve public events (#1481) 2020-04-26 10:03:54 +08:00
Steve Kowalik 83bef0f7b2 Correct typos found with codespell (#1467)
Correct misspellings and typos located using the codespell tool. Add
codespell to pre-commit to avoid further regressions.

Fixes #1459
2020-04-16 13:25:01 +10:00
Alice GIRARDandLiuyang Wan 91433fe925 Type stubs for mypy (#1231)
* First attempt at stubs

* fix AuthenticatedUser.piy

* fix PullRequest.piy

* fix Authorization.piy

* fix Branch.piy

* fix Clones.piy

* fix Commit.piy

* fix CommitCombinedStatus.piy

* fix CommitComment.piy

* fix CommitStatus.piy

* fix ContentFile.piy

* fix Download.piy

* fix Event.piy

* fix File.piy

* fix Gist.piy

* fix GistComment.piy

* fix GistFile.piy

* fix GitAuthor.piy

* fix GitBlob.piy

* fix GitCommit.piy

* fix GitRef.piy

* fix GitRelease.piy

* renamed stubs into pyi files

* fix Notification

* fix Repository

* fix GitReleaseAsset

* fix GitTag

* fix GitTree

* fix GitTreeElement

* fix GithubException

* fix GithubObject

* fix GitignoreTemplate

* fix HookDescription

* fix HookResponse

* fix InputGitAuthor

* fix Installation

* fix InstallationAuthorization

* fix Invitation

* fix Issue

* fix IssueComment

* Fix random issues found while testing

* fix IssuePullRequest

* fix Label

* fix License

* fix Migration

* fix Milestone

* fix NamedUser

* fix NotificationSubject

* fix Organization

* fix PaginatedList

* fix Path

* fix Permissions

* fix Plan

* fix Project

* fix ProjectCard

* fix ProjectColumn

* fix PullRequestComment

* fix PullRequestMergeStatus

* fix PullRequestPart

* fix PullRequestReview

* fix Rate

* fix RateLimit

* fix Reaction

* fix Referrer

* fix RepositoryKey

* fix RequiredPullRequestReviews

* fix RequiredStatusChecks

* fix SourceImport

* fix Stargazer

* fix StatsCodeFrequency

* fix StatsCommitActivity

* fix StatsContributor

* fix Tag

* fix Team

* fix Topic

* fix UserKey

* fix MainClass

* fix Requester

* added stubs for View

* added stubs for Membership

* various syntax errors

* silence mypy noise

* keeping track of recent changes

* black + isort

Co-authored-by: Liuyang Wan <lwan@zendesk.com>
2020-03-22 19:33:23 +08: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
Wan Liuyang 540a085001 Fix isort - add known first and third party 2019-12-11 00:54:59 +08:00
Wan Liuyang 6ceb9e9a15 Apply black to whole codebase (#1303) 2019-12-10 17:14:33 +08:00
Adam Baratz a076508370 Stop ignoring unused imports and remove them (#1250)
* Stop ignoring unused imports and remove them

* Stop ignoring * imports
2019-10-19 16:43:14 +11:00
Steve Kowalik e33858a3dc Support non-default URLs in GithubIntegration (#1229)
The get_installation() method of GithubIntegration was hardcoded to
always use the default URL of api.github.com, making it impossible to
fetch the installation of an GitHub Enterprise installation.
2019-09-25 23:01:31 +10:00
Jake Klingensmith 850da5af27 Fix redundant int checks (#1226) 2019-09-23 16:28:07 +10: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 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 6e79d2704b Correct return type of MainClass.get_organizations (#1179)
The doc string and the code disagreed about the return type of
MainClass.get_organizations(), correct the code, which was incorrect.

Fixes #1177
2019-07-23 22:38:36 +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
chillipeper 6cd0d644cf Add support for custom base_url in GithubIntegration class (#1093)
* Add support for custom base_url in GithubIntegration

* Fix non default argument issue
2019-06-20 16:08:04 +08:00
Tomas Tomecek 18187045a4 GithubIntegration: enable getting installation (#1135)
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
2019-06-20 16:05:53 +08:00
Caleb Sweeney 54065792b8 fixes #1106 for GitHub Enterprise API (#1110) 2019-05-03 09:24:59 +08:00
Jake Wilkins 818bd78fe9 Use non-deprecated path for creating GitHub App access tokens (#1086)
/installations/<installation_id>/access_tokens was deprecated as of
https://developer.github.com/changes/2018-08-16-renaming-and-deprecation-of-github-app-installation-access-token-route/
2019-04-10 10:11:06 +08:00