Allow GithubObject.update() to be passed headers (#1300)

SourceImport.update() is really GithubObject.update(), which just calls
GET on the object's URL. Refetching a source import requires an
additional header, so change GithubObject.update() to pass any it is
given, and add a test for SourceImport.update()

Fixes #1297
This commit is contained in:
Steve Kowalik
2019-11-26 14:29:24 +11:00
committed by GitHub
parent 3170cafce5
commit 989b635e33
4 changed files with 24 additions and 1 deletions
+3 -1
View File
@@ -279,7 +279,7 @@ class CompletableGithubObject(GithubObject):
self._storeAndUseAttributes(headers, data)
self.__completed = True
def update(self):
def update(self, additional_headers=None):
'''
Check and update the object with conditional request
:rtype: Boolean value indicating whether the object is changed
@@ -289,6 +289,8 @@ class CompletableGithubObject(GithubObject):
conditionalRequestHeader[Consts.REQ_IF_NONE_MATCH] = self.etag
if self.last_modified is not None:
conditionalRequestHeader[Consts.REQ_IF_MODIFIED_SINCE] = self.last_modified
if additional_headers is not None:
conditionalRequestHeader.update(additional_headers)
status, responseHeaders, output = self._requester.requestJson(
"GET",
+5
View File
@@ -23,6 +23,7 @@
################################################################################
from __future__ import absolute_import
from github import Consts
import github.GithubObject
@@ -143,6 +144,10 @@ class SourceImport(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._vcs_url)
return self._vcs_url.value
def update(self):
import_header = {"Accept": Consts.mediaTypeImportPreview}
return super(SourceImport, self).update(additional_headers=import_header)
def _initAttributes(self):
self._authors_count = github.GithubObject.NotSet
self._authors_url = github.GithubObject.NotSet