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~~
This commit is contained in:
Maarten Fonville
2018-06-22 12:46:46 +08:00
committed by Wan Liuyang
parent e389396405
commit 8bdac23ca1
6 changed files with 32 additions and 26 deletions
+4 -6
View File
@@ -72,6 +72,7 @@ import Invitation
atLeastPython3 = sys.hexversion >= 0x03000000
DEFAULT_BASE_URL = "https://api.github.com"
DEFAULT_STATUS_URL = "https://status.github.com"
# As of 2018-05-17, Github imposes a 10s limit for completion of API requests.
# Thus, the timeout should be slightly > 10s to account for network/front-end
# latency.
@@ -625,8 +626,7 @@ class Github(object):
"""
headers, attributes = self.__requester.requestJsonAndCheck(
"GET",
"/api/status.json",
cnx="status"
DEFAULT_STATUS_URL + "/api/status.json"
)
return Status.Status(self.__requester, headers, attributes, completed=True)
@@ -639,8 +639,7 @@ class Github(object):
"""
headers, attributes = self.__requester.requestJsonAndCheck(
"GET",
"/api/last-message.json",
cnx="status"
DEFAULT_STATUS_URL + "/api/last-message.json"
)
return StatusMessage.StatusMessage(self.__requester, headers, attributes, completed=True)
@@ -653,8 +652,7 @@ class Github(object):
"""
headers, data = self.__requester.requestJsonAndCheck(
"GET",
"/api/messages.json",
cnx="status"
DEFAULT_STATUS_URL + "/api/messages.json"
)
return [StatusMessage.StatusMessage(self.__requester, headers, attributes, completed=True) for attributes in data]