2
2
from typing import (
3
3
Any ,
4
4
Callable ,
5
- cast ,
6
5
Dict ,
7
6
Iterator ,
8
7
List ,
9
8
Optional ,
9
+ Tuple ,
10
10
TYPE_CHECKING ,
11
11
Union ,
12
12
)
20
20
from gitlab .mixins import (
21
21
CreateMixin ,
22
22
DeleteMixin ,
23
- GetMixin ,
24
23
ObjectDeleteMixin ,
25
24
SaveMixin ,
26
25
UpdateMixin ,
@@ -96,10 +95,11 @@ def delete( # type: ignore
96
95
self .manager .delete (file_path , branch , commit_message , ** kwargs )
97
96
98
97
99
- class ProjectFileManager (GetMixin , CreateMixin , UpdateMixin , DeleteMixin , RESTManager ):
98
+ class ProjectFileManager (CreateMixin , UpdateMixin , DeleteMixin , RESTManager ):
100
99
_path = "/projects/{project_id}/repository/files"
101
100
_obj_cls = ProjectFile
102
101
_from_parent_attrs = {"project_id" : "id" }
102
+ _optional_get_attrs : Tuple [str , ...] = ()
103
103
_create_attrs = RequiredOptional (
104
104
required = ("file_path" , "branch" , "content" , "commit_message" ),
105
105
optional = ("encoding" , "author_email" , "author_name" ),
@@ -112,11 +112,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa
112
112
@cli .register_custom_action (
113
113
cls_names = "ProjectFileManager" , required = ("file_path" , "ref" )
114
114
)
115
- # NOTE(jlvillal): Signature doesn't match UpdateMixin.update() so ignore
116
- # type error
117
- def get ( # type: ignore
118
- self , file_path : str , ref : str , ** kwargs : Any
119
- ) -> ProjectFile :
115
+ def get (self , file_path : str , ref : str , ** kwargs : Any ) -> ProjectFile :
120
116
"""Retrieve a single file.
121
117
122
118
Args:
@@ -131,7 +127,37 @@ def get( # type: ignore
131
127
Returns:
132
128
The generated RESTObject
133
129
"""
134
- return cast (ProjectFile , GetMixin .get (self , file_path , ref = ref , ** kwargs ))
130
+ if TYPE_CHECKING :
131
+ assert file_path is not None
132
+ file_path = utils .EncodedId (file_path )
133
+ path = f"{ self .path } /{ file_path } "
134
+ server_data = self .gitlab .http_get (path , ref = ref , ** kwargs )
135
+ if TYPE_CHECKING :
136
+ assert isinstance (server_data , dict )
137
+ return self ._obj_cls (self , server_data )
138
+
139
+ def head (
140
+ self , file_path : str , ref : str , ** kwargs : Any
141
+ ) -> "requests.structures.CaseInsensitiveDict[Any]" :
142
+ """Retrieve just metadata for a single file.
143
+
144
+ Args:
145
+ file_path: Path of the file to retrieve
146
+ ref: Name of the branch, tag or commit
147
+ **kwargs: Extra options to send to the server (e.g. sudo)
148
+
149
+ Raises:
150
+ GitlabAuthenticationError: If authentication is not correct
151
+ GitlabGetError: If the file could not be retrieved
152
+
153
+ Returns:
154
+ The response headers as a dictionary
155
+ """
156
+ if TYPE_CHECKING :
157
+ assert file_path is not None
158
+ file_path = utils .EncodedId (file_path )
159
+ path = f"{ self .path } /{ file_path } "
160
+ return self .gitlab .http_head (path , ref = ref , ** kwargs )
135
161
136
162
@cli .register_custom_action (
137
163
cls_names = "ProjectFileManager" ,
0 commit comments