29
29
30
30
import gitlab
31
31
from gitlab .exceptions import * # noqa
32
+ from gitlab import utils
32
33
33
34
34
35
class jsonEncoder (json .JSONEncoder ):
@@ -889,22 +890,31 @@ def keep_artifacts(self, **kwargs):
889
890
r = self .gitlab ._raw_post (url )
890
891
raise_error_from_response (r , GitlabGetError , 200 )
891
892
892
- def artifacts (self , ** kwargs ):
893
+ def artifacts (self , streamed = False , action = None , chunk_size = 1024 ,
894
+ ** kwargs ):
893
895
"""Get the build artifacts.
894
896
897
+ Args:
898
+ streamed (bool): If True the data will be processed by chunks of
899
+ `chunk_size` and each chunk is passed to `action` for
900
+ treatment.
901
+ action (callable): Callable responsible of dealing with chunk of
902
+ data.
903
+ chunk_size (int): Size of each chunk.
904
+
895
905
Returns:
896
- str: The artifacts.
906
+ str: The artifacts if `streamed` is False, None otherwise .
897
907
898
908
Raises:
899
909
GitlabConnectionError: If the server cannot be reached.
900
910
GitlabGetError: If the artifacts are not available.
901
911
"""
902
912
url = '/projects/%s/builds/%s/artifacts' % (self .project_id , self .id )
903
- r = self .gitlab ._raw_get (url )
913
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
904
914
raise_error_from_response (r , GitlabGetError , 200 )
905
- return r . content
915
+ return utils . response_content ( r , streamed , action , chunk_size )
906
916
907
- def trace (self , ** kwargs ):
917
+ def trace (self , streamed = False , action = None , chunk_size = 1024 , ** kwargs ):
908
918
"""Get the build trace.
909
919
910
920
Returns:
@@ -915,9 +925,9 @@ def trace(self, **kwargs):
915
925
GitlabGetError: If the trace is not available.
916
926
"""
917
927
url = '/projects/%s/builds/%s/trace' % (self .project_id , self .id )
918
- r = self .gitlab ._raw_get (url )
928
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
919
929
raise_error_from_response (r , GitlabGetError , 200 )
920
- return r . content
930
+ return utils . response_content ( r , streamed , action , chunk_size )
921
931
922
932
923
933
class ProjectBuildManager (BaseManager ):
@@ -972,7 +982,8 @@ def diff(self, **kwargs):
972
982
973
983
return r .json ()
974
984
975
- def blob (self , filepath , ** kwargs ):
985
+ def blob (self , filepath , streamed = False , action = None , chunk_size = 1024 ,
986
+ ** kwargs ):
976
987
"""Generate the content of a file for this commit.
977
988
978
989
Args:
@@ -988,10 +999,9 @@ def blob(self, filepath, **kwargs):
988
999
url = ('/projects/%(project_id)s/repository/blobs/%(commit_id)s' %
989
1000
{'project_id' : self .project_id , 'commit_id' : self .id })
990
1001
url += '?filepath=%s' % filepath
991
- r = self .gitlab ._raw_get (url , ** kwargs )
1002
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
992
1003
raise_error_from_response (r , GitlabGetError )
993
-
994
- return r .content
1004
+ return utils .response_content (r , streamed , action , chunk_size )
995
1005
996
1006
def builds (self , ** kwargs ):
997
1007
"""List the build for this commit.
@@ -1734,7 +1744,8 @@ def blob(self, sha, filepath, **kwargs):
1734
1744
DeprecationWarning )
1735
1745
return self .repository_blob (sha , filepath , ** kwargs )
1736
1746
1737
- def repository_blob (self , sha , filepath , ** kwargs ):
1747
+ def repository_blob (self , sha , filepath , streamed = False , action = None ,
1748
+ chunk_size = 1024 , ** kwargs ):
1738
1749
"""Return the content of a file for a commit.
1739
1750
1740
1751
Args:
@@ -1750,11 +1761,12 @@ def repository_blob(self, sha, filepath, **kwargs):
1750
1761
"""
1751
1762
url = "/projects/%s/repository/blobs/%s" % (self .id , sha )
1752
1763
url += '?filepath=%s' % (filepath )
1753
- r = self .gitlab ._raw_get (url , ** kwargs )
1764
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
1754
1765
raise_error_from_response (r , GitlabGetError )
1755
- return r . content
1766
+ return utils . response_content ( r , streamed , action , chunk_size )
1756
1767
1757
- def repository_raw_blob (self , sha , ** kwargs ):
1768
+ def repository_raw_blob (self , sha , streamed = False , action = None ,
1769
+ chunk_size = 1024 , ** kwargs ):
1758
1770
"""Returns the raw file contents for a blob by blob SHA.
1759
1771
1760
1772
Args:
@@ -1768,9 +1780,9 @@ def repository_raw_blob(self, sha, **kwargs):
1768
1780
GitlabGetError: If the server fails to perform the request.
1769
1781
"""
1770
1782
url = "/projects/%s/repository/raw_blobs/%s" % (self .id , sha )
1771
- r = self .gitlab ._raw_get (url , ** kwargs )
1783
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
1772
1784
raise_error_from_response (r , GitlabGetError )
1773
- return r . content
1785
+ return utils . response_content ( r , streamed , action , chunk_size )
1774
1786
1775
1787
def repository_compare (self , from_ , to , ** kwargs ):
1776
1788
"""Returns a diff between two branches/commits.
@@ -1813,7 +1825,8 @@ def archive(self, sha=None, **kwargs):
1813
1825
DeprecationWarning )
1814
1826
return self .repository_archive (sha , ** kwargs )
1815
1827
1816
- def repository_archive (self , sha = None , ** kwargs ):
1828
+ def repository_archive (self , sha = None , streamed = False , action = None ,
1829
+ chunk_size = 1024 , ** kwargs ):
1817
1830
"""Return a tarball of the repository.
1818
1831
1819
1832
Args:
@@ -1829,9 +1842,9 @@ def repository_archive(self, sha=None, **kwargs):
1829
1842
url = '/projects/%s/repository/archive' % self .id
1830
1843
if sha :
1831
1844
url += '?sha=%s' % sha
1832
- r = self .gitlab ._raw_get (url , ** kwargs )
1845
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
1833
1846
raise_error_from_response (r , GitlabGetError )
1834
- return r . content
1847
+ return utils . response_content ( r , streamed , action , chunk_size )
1835
1848
1836
1849
def create_file (self , path , branch , content , message , ** kwargs ):
1837
1850
"""Creates file in project repository
0 commit comments