Skip to content

Commit 839f108

Browse files
committed
Add proxy support for github plugin
Signed-off-by: Han Han <hhan@redhat.com>
1 parent f037155 commit 839f108

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

did/plugins/github.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
4242
timeout = 10
4343
44+
Use ``proxy`` to configure the proxy. See the `Proxies`__ documentation
45+
for the format of proxy url.
46+
47+
__ https://requests.readthedocs.io/en/latest/user/advanced/#proxies
4448
""" # noqa: W505,E501 # pylint:disable=line-too-long
4549

4650
import json
@@ -75,10 +79,11 @@ class GitHub():
7579
# pylint: disable=too-few-public-methods
7680

7781
def __init__(self, *, url, token=None, user=None,
78-
org=None, repo=None, exclude_org=None, timeout=TIMEOUT):
82+
org=None, repo=None, exclude_org=None, timeout=TIMEOUT, proxy=None):
7983
""" Initialize url and headers """
8084
self.url = url.rstrip("/")
8185
self.timeout = timeout
86+
self.proxy = {"all": proxy}
8287
if token is not None:
8388
self.headers = {'Authorization': f'token {token}'}
8489
else:
@@ -134,7 +139,7 @@ def request(self, url):
134139
reraise=True):
135140
with attempt:
136141
response = requests.get(
137-
url, headers=self.headers, timeout=self.timeout
142+
url, headers=self.headers, timeout=self.timeout, proxies=self.proxy
138143
)
139144
log.debug("Response headers:\n%s", response.headers)
140145
except (requests.exceptions.RequestException, RetryError) as error:
@@ -377,7 +382,9 @@ def __init__(self, option, name=None, parent=None, user=None):
377382
user=config.get("user"),
378383
repo=config.get("repo"),
379384
exclude_org=config.get("exclude_org"),
380-
timeout=config.get("timeout"))
385+
timeout=config.get("timeout"),
386+
proxy=config.get("proxy"),
387+
)
381388

382389
# Create the list of stats
383390
self.stats = [

0 commit comments

Comments
 (0)