@@ -1498,13 +1498,12 @@ class ProjectFile(GitlabObject):
1498
1498
_url = '/projects/%(project_id)s/repository/files'
1499
1499
canList = False
1500
1500
requiredUrlAttrs = ['project_id' ]
1501
- requiredGetAttrs = ['file_path' , ' ref' ]
1501
+ requiredGetAttrs = ['ref' ]
1502
1502
requiredCreateAttrs = ['file_path' , 'branch' , 'content' ,
1503
1503
'commit_message' ]
1504
1504
optionalCreateAttrs = ['encoding' ]
1505
1505
requiredDeleteAttrs = ['branch' , 'commit_message' , 'file_path' ]
1506
1506
shortPrintAttr = 'file_path'
1507
- getRequiresId = False
1508
1507
1509
1508
def decode (self ):
1510
1509
"""Returns the decoded content of the file.
@@ -1518,6 +1517,34 @@ def decode(self):
1518
1517
class ProjectFileManager (BaseManager ):
1519
1518
obj_cls = ProjectFile
1520
1519
1520
+ def raw (self , filepath , ref , streamed = False , action = None , chunk_size = 1024 ,
1521
+ ** kwargs ):
1522
+ """Return the content of a file for a commit.
1523
+
1524
+ Args:
1525
+ ref (str): ID of the commit
1526
+ filepath (str): Path of the file to return
1527
+ streamed (bool): If True the data will be processed by chunks of
1528
+ `chunk_size` and each chunk is passed to `action` for
1529
+ treatment.
1530
+ action (callable): Callable responsible of dealing with chunk of
1531
+ data.
1532
+ chunk_size (int): Size of each chunk.
1533
+
1534
+ Returns:
1535
+ str: The file content
1536
+
1537
+ Raises:
1538
+ GitlabConnectionError: If the server cannot be reached.
1539
+ GitlabGetError: If the server fails to perform the request.
1540
+ """
1541
+ url = ("/projects/%s/repository/files/%s/raw" %
1542
+ (self .parent .id , filepath .replace ('/' , '%2F' )))
1543
+ url += '?ref=%s' % ref
1544
+ r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
1545
+ raise_error_from_response (r , GitlabGetError )
1546
+ return utils .response_content (r , streamed , action , chunk_size )
1547
+
1521
1548
1522
1549
class ProjectPipeline (GitlabObject ):
1523
1550
_url = '/projects/%(project_id)s/pipelines'
@@ -1861,33 +1888,6 @@ def repository_tree(self, path='', ref_name='', **kwargs):
1861
1888
raise_error_from_response (r , GitlabGetError )
1862
1889
return r .json ()
1863
1890
1864
- def repository_blob (self , sha , filepath , streamed = False , action = None ,
1865
- chunk_size = 1024 , ** kwargs ):
1866
- """Return the content of a file for a commit.
1867
-
1868
- Args:
1869
- sha (str): ID of the commit
1870
- filepath (str): Path of the file to return
1871
- streamed (bool): If True the data will be processed by chunks of
1872
- `chunk_size` and each chunk is passed to `action` for
1873
- treatment.
1874
- action (callable): Callable responsible of dealing with chunk of
1875
- data.
1876
- chunk_size (int): Size of each chunk.
1877
-
1878
- Returns:
1879
- str: The file content
1880
-
1881
- Raises:
1882
- GitlabConnectionError: If the server cannot be reached.
1883
- GitlabGetError: If the server fails to perform the request.
1884
- """
1885
- url = "/projects/%s/repository/blobs/%s" % (self .id , sha )
1886
- url += '?%s' % (urllib .urlencode ({'filepath' : filepath }))
1887
- r = self .gitlab ._raw_get (url , streamed = streamed , ** kwargs )
1888
- raise_error_from_response (r , GitlabGetError )
1889
- return utils .response_content (r , streamed , action , chunk_size )
1890
-
1891
1891
def repository_raw_blob (self , sha , streamed = False , action = None ,
1892
1892
chunk_size = 1024 , ** kwargs ):
1893
1893
"""Returns the raw file contents for a blob by blob SHA.
0 commit comments