Title: [295325] trunk/Tools/Scripts/libraries
Revision
295325
Author
[email protected]
Date
2022-06-06 20:43:00 -0700 (Mon, 06 Jun 2022)

Log Message

Add proxy support to webkitscmpy's GitHub client
https://bugs.webkit.org/show_bug.cgi?id=241031
rdar://93129765

Reviewed by Jonathan Bedard.

Allow for the passing of proxy settings to the GitHub client. Use
requests.Session to pass the proxy settings to all requests made.

Additionally pass this session to the Tracker data member, for
github.com networking requests made at the Tracker level.

Version bumps webkitbugspy and webkitscmpy.

* Tools/Scripts/libraries/webkitbugspy/setup.py: version bump to 0.6.3
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py: version bump to 0.6.3
* Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py:
Add a requests.Session member to the class that can be passed into the constructor.
Call all networking requests through the session.
(Tracker.__init__):
(Tracker):
(Tracker.credentials.validater):
* Tools/Scripts/libraries/webkitscmpy/setup.py: version bump to 4.15.4
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: version bump to 4.15.4
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:
Add a proxies argument to the constructor. Will pass proxies to a request.Session member
that is used to perform networking requests to github.com from this class.
This session is passed to the Tracker member in its constructor (see webkitbugspy.github changes).
(GitHub.PRGenerator.create):
(GitHub.PRGenerator.update):
(GitHub.__init__):
(GitHub.request):
(GitHub._count_for_ref):
(GitHub._branches_for):

Canonical link: https://commits.webkit.org/251349@main

Modified Paths

Diff

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/setup.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/setup.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitbugspy',
-    version='0.6.2',
+    version='0.6.3',
     description='Library containing a shared API for various bug trackers.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/__init__.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 6, 2)
+version = Version(0, 6, 3)
 
 from .user import User
 from .issue import Issue

Modified: trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitbugspy/webkitbugspy/github.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -65,10 +65,15 @@
                 raise TypeError('Cannot invoke parent class when classmethod')
             return super(Tracker.Encoder, context).default(obj)
 
-
-    def __init__(self, url, users=None, res=None, component_color=DEFAULT_COMPONENT_COLOR, version_color=DEFAULT_VERSION_COLOR):
+    def __init__(
+            self, url, users=None, res=None,
+            component_color=DEFAULT_COMPONENT_COLOR,
+            version_color=DEFAULT_VERSION_COLOR,
+            session=None
+    ):
         super(Tracker, self).__init__(users=users)
 
+        self.session = session or requests.Session()
         self.component_color = component_color
         self.version_color = version_color
 
@@ -98,7 +103,7 @@
             if '@' in username:
                 sys.stderr.write("Provided username contains an '@' symbol. Please make sure to enter your GitHub username, not an email associated with the account\n")
                 return False
-            response = requests.get(
+            response = self.session.get(
                 '{}/user'.format(self.api_url),
                 headers=dict(Accept='application/vnd.github.v3+json'),
                 auth=HTTPBasicAuth(username, access_token),
@@ -158,7 +163,7 @@
             name=self.name,
             path='{}'.format(path) if path else '',
         )
-        response = requests.request(method, url, params=params, headers=headers, auth=auth, json=json)
+        response = self.session.request(method, url, params=params, headers=headers, auth=auth, json=json)
         if authenticated is None and not auth and response.status_code // 100 == 4:
             return self.request(path=path, params=params, method=method, headers=headers, authenticated=True, paginate=paginate, json=json, error_message=error_message)
         if response.status_code // 100 != 2:
@@ -175,7 +180,7 @@
 
         while paginate and isinstance(response.json(), list) and len(response.json()) == params['per_page']:
             params['page'] += 1
-            response = requests.get(url, params=params, headers=headers, auth=auth)
+            response = self.session.get(url, params=params, headers=headers, auth=auth)
             if response.status_code != 200:
                 raise OSError("Failed to assemble pagination requests for '{}', failed on page {}".format(url, params['page']))
             result += response.json()
@@ -189,7 +194,7 @@
             raise RuntimeError("Failed to find username for '{}'".format(name or email))
 
         url = ''.format(api_url=self.api_url, username=username)
-        response = requests.get(
+        response = self.session.get(
             url, auth=HTTPBasicAuth(*self.credentials(required=True)),
             headers=dict(Accept='application/vnd.github.v3+json'),
         )

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -29,7 +29,7 @@
 
 setup(
     name='webkitscmpy',
-    version='4.15.3',
+    version='4.15.4',
     description='Library designed to interact with git and svn repositories.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(4, 15, 3)
+version = Version(4, 15, 4)
 
 AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
 AutoInstall.register(Package('jinja2', Version(2, 11, 3)))

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py (295324 => 295325)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py	2022-06-07 02:30:53 UTC (rev 295324)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py	2022-06-07 03:43:00 UTC (rev 295325)
@@ -111,7 +111,7 @@
                 owner=self.repository.owner,
                 name=self.repository.name,
             )
-            response = requests.post(
+            response = self.repository.session.post(
                 url, auth=HTTPBasicAuth(*self.repository.credentials(required=True)),
                 headers=dict(Accept='application/vnd.github.v3+json'),
                 json=dict(
@@ -165,7 +165,7 @@
                 name=self.repository.name,
                 number=pull_request.number,
             )
-            response = requests.post(
+            response = self.repository.session.post(
                 url, auth=HTTPBasicAuth(*self.repository.credentials(required=True)),
                 headers=dict(Accept='application/vnd.github.v3+json'),
                 json=updates,
@@ -278,7 +278,7 @@
     def is_webserver(cls, url):
         return True if cls.URL_RE.match(url) else False
 
-    def __init__(self, url, dev_branches=None, prod_branches=None, contributors=None, id=None):
+    def __init__(self, url, dev_branches=None, prod_branches=None, contributors=None, id=None, proxies=None):
         match = self.URL_RE.match(url)
         if not match:
             raise self.Exception("'{}' is not a valid GitHub project".format(url))
@@ -285,6 +285,9 @@
         self.api_url = 'https://api.github.{}'.format(match.group('domain'))
         self.owner = match.group('owner')
         self.name = match.group('repository')
+        self.session = requests.Session()
+        if proxies:
+            self.session.proxies = proxies
         self._hash_link_re = re.compile(r'/{owner}/{name}/[^/]*commit[^/]*/(?P<hash>[0-9a-f]+)'.format(
             owner=self.owner,
             name=self.name,
@@ -303,7 +306,7 @@
         for contributor in contributors or []:
             if contributor.github:
                 users.create(contributor.name, contributor.github, contributor.emails)
-        self.tracker = Tracker(url, users=users)
+        self.tracker = Tracker(url, users=users, session=self.session)
 
     def credentials(self, required=True, validate=False, save_in_keyring=None):
         return self.tracker.credentials(required=required, validate=validate, save_in_keyring=save_in_keyring)
@@ -333,7 +336,7 @@
             name=self.name,
             path='/{}'.format(path) if path else '',
         )
-        response = requests.get(url, params=params, headers=headers, auth=auth)
+        response = self.session.get(url, params=params, headers=headers, auth=auth)
         if authenticated is None and not auth and response.status_code // 100 == 4:
             return self.request(path=path, params=params, headers=headers, authenticated=True, paginate=paginate)
         if response.status_code != 200:
@@ -348,7 +351,7 @@
 
         while paginate and isinstance(response.json(), list) and len(response.json()) == params['per_page']:
             params['page'] += 1
-            response = requests.get(url, params=params, headers=headers, auth=auth)
+            response = self.session.get(url, params=params, headers=headers, auth=auth)
             if response.status_code != 200:
                 raise self.Exception("Failed to assemble pagination requests for '{}', failed on page {}".format(url, params['page']))
             result += response.json()
@@ -359,7 +362,7 @@
 
         # We need the number of parents a commit has to construct identifiers, which is not something GitHub's
         # API lets us find, although the UI does have the information
-        response = requests.get('{}/tree/{}'.format(self.url, ref))
+        response = self.session.get('{}/tree/{}'.format(self.url, ref))
         if response.status_code != 200:
             raise self.Exception("Failed to query {}'s UI to find the number of parents {} has".format(self.url, ref))
 
@@ -390,7 +393,7 @@
     def _branches_for(self, hash):
         # We need to find the branch that a commit is on. GitHub's UI provides this information, but the only way to
         # retrieve this information via the API would be to check all branches for the commit, so we scrape the UI.
-        response = requests.get('{}/branch_commits/{}'.format(self.url, hash))
+        response = self.session.get('{}/branch_commits/{}'.format(self.url, hash))
         if response.status_code != 200:
             return []
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to