@@ -4744,6 +4744,69 @@ def import_project(
47444744 "/projects/import" , post_data = data , files = files , ** kwargs
47454745 )
47464746
4747+ def import_github (
4748+ self , personal_access_token , repo_id , target_namespace , new_name = None , ** kwargs
4749+ ):
4750+ """Import a project from Github to Gitlab (schedule the import)
4751+
4752+ This method will return when an import operation has been safely queued,
4753+ or an error has occurred. After triggering an import, check the
4754+ `import_status` of the newly created project to detect when the import
4755+ operation has completed.
4756+
4757+ NOTE: this request may take longer than most other API requests.
4758+ So this method will specify a 60 second default timeout if none is specified.
4759+ A timeout can be specified via kwargs to override this functionality.
4760+
4761+ Args:
4762+ personal_access_token (str): GitHub personal access token
4763+ repo_id (int): Github repository ID
4764+ target_namespace (str): Namespace to import repo into
4765+ new_name (str): New repo name (Optional)
4766+ **kwargs: Extra options to send to the server (e.g. sudo)
4767+
4768+ Raises:
4769+ GitlabAuthenticationError: If authentication is not correct
4770+ GitlabListError: If the server failed to perform the request
4771+
4772+ Returns:
4773+ dict: A representation of the import status.
4774+
4775+ Example:
4776+ ```
4777+ gl = gitlab.Gitlab_from_config()
4778+ print "Triggering import"
4779+ result = gl.projects.import_github(ACCESS_TOKEN,
4780+ 123456,
4781+ "my-group/my-subgroup")
4782+ project = gl.projects.get(ret['id'])
4783+ print "Waiting for import to complete"
4784+ while project.import_status == u'started':
4785+ time.sleep(1.0)
4786+ project = gl.projects.get(project.id)
4787+ print "Github import complete"
4788+ ```
4789+ """
4790+ data = {
4791+ "personal_access_token" : personal_access_token ,
4792+ "repo_id" : repo_id ,
4793+ "target_namespace" : target_namespace ,
4794+ }
4795+ if new_name :
4796+ data ["new_name" ] = new_name
4797+ if (
4798+ "timeout" not in kwargs
4799+ or self .gitlab .timeout is None
4800+ or self .gitlab .timeout < 60.0
4801+ ):
4802+ # Ensure that this HTTP request has a longer-than-usual default timeout
4803+ # The base gitlab object tends to have a default that is <10 seconds,
4804+ # and this is too short for this API command, typically.
4805+ # On the order of 24 seconds has been measured on a typical gitlab instance.
4806+ kwargs ["timeout" ] = 60.0
4807+ result = self .gitlab .http_post ("/import/github" , post_data = data , ** kwargs )
4808+ return result
4809+
47474810
47484811class RunnerJob (RESTObject ):
47494812 pass
0 commit comments