1313from tornado .httputil import url_concat
1414from tornado .web import HTTPError
1515
16- from ..base import CommentReply , NewComment
16+ from ..base import CommentReply , NewComment , PRConfig
1717from ..log import get_logger
1818from .manager import PullRequestsManager
1919
@@ -25,22 +25,20 @@ class GitLabManager(PullRequestsManager):
2525
2626 MINIMAL_VERSION = "13.1" # Due to pagination https://docs.gitlab.com/ee/api/README.html#pagination
2727
28- def __init__ (
29- self , base_api_url : str = "https://gitlab.com/api/v4/" , access_token : str = ""
30- ) -> None :
31- """
32- Args:
33- base_api_url: Base REST API url for the versioning service
34- access_token: Versioning service access token
35- """
36- super ().__init__ (base_api_url = base_api_url , access_token = access_token )
28+ def __init__ (self , config : PRConfig ) -> None :
29+ super ().__init__ (config )
30+
3731 # Creating new file discussion required some commit sha's so we will cache them
3832 self ._merge_requests_cache = {} # Dict[str, Dict]
3933 # Creating discussion on unmodified line requires to figure out the line number
4034 # in the diff file for the original and the new file using Myers algorithm. So
4135 # we cache the diff to speed up the process.
4236 self ._file_diff_cache = {} # Dict[Tuple[str, str], List[difflib.Match]]
4337
38+ @property
39+ def base_api_url (self ):
40+ return self ._config .api_base_url or "https://gitlab.com/api/v4/"
41+
4442 @property
4543 def per_page_argument (self ) -> Optional [Tuple [str , int ]]:
4644 """Returns query argument to set number of items per page.
@@ -57,7 +55,7 @@ async def check_server_version(self) -> bool:
5755 Returns:
5856 Whether the server version is higher than the minimal supported version.
5957 """
60- url = url_path_join (self ._base_api_url , "version" )
58+ url = url_path_join (self .base_api_url , "version" )
6159 data = await self ._call_gitlab (url , has_pagination = False )
6260 server_version = data .get ("version" , "" )
6361 is_valid = True
@@ -79,7 +77,7 @@ async def get_current_user(self) -> Dict[str, str]:
7977 # Check server compatibility
8078 await self .check_server_version ()
8179
82- git_url = url_path_join (self ._base_api_url , "user" )
80+ git_url = url_path_join (self .base_api_url , "user" )
8381 data = await self ._call_gitlab (git_url , has_pagination = False )
8482
8583 return {"username" : data ["username" ]}
@@ -227,15 +225,15 @@ async def list_prs(self, username: str, pr_filter: str) -> List[Dict[str, str]]:
227225
228226 # Use search API to find matching pull requests and return
229227 git_url = url_path_join (
230- self ._base_api_url , "/merge_requests?state=opened&" + search_filter
228+ self .base_api_url , "/merge_requests?state=opened&" + search_filter
231229 )
232230
233231 results = await self ._call_gitlab (git_url )
234232
235233 data = []
236234 for result in results :
237235 url = url_path_join (
238- self ._base_api_url ,
236+ self .base_api_url ,
239237 "projects" ,
240238 str (result ["project_id" ]),
241239 "merge_requests" ,
@@ -374,7 +372,7 @@ async def _call_gitlab(
374372 """
375373
376374 headers = {
377- "Authorization" : f"Bearer { self ._access_token } " ,
375+ "Authorization" : f"Bearer { self ._config . access_token } " ,
378376 "Accept" : "application/json" ,
379377 }
380378 return await super ()._call_provider (
@@ -481,7 +479,7 @@ def _response_to_comment(result: Dict[str, str]) -> Dict[str, str]:
481479 async def __get_content (self , project_id : int , filename : str , sha : str ) -> str :
482480 url = url_concat (
483481 url_path_join (
484- self ._base_api_url ,
482+ self .base_api_url ,
485483 "projects" ,
486484 str (project_id ),
487485 "repository/files" ,
0 commit comments