3 @qhc@s`ddlmZmZmZmZmZmZmZmZddl Z ddl m Z m Z ddl m Zddl mZmZddlmZmZmZddlmZmZmZmZmZmZmZdd lmZdd lm Z dd l!m"Z"dd l#m$Z$dd l%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;mZ>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHmIZIddlJmKZKmLZLddlMmNZNdd lOmPZPdd!lQmRZRdd"lSmTZTdd#lUmVZVmWZWdd$lXmYZYdd%lZm[Z[m\Z\m]Z]dd&l^m_Z_dd'l`maZadd(lbmcZcdd)ldmeZedd*lfmgZgdd+lhmiZidd,ljmkZkdd-llmmZmmnZndd.lompZpmqZqdd/lrmsZsdd0ltmuZudd1lvmwZwdd2lxmyZyd3d4d5d6d7d8d9d:gZzGd;d3d3eZ{Gdd6d6eeZ~Gd?d7d7eZGd@d8d8eeeZGdAd9d9eeZGdBd:d:eeeeZdS)C)AnyCallablecastDictListOptional TYPE_CHECKINGUnionN)cliclient) exceptions)typesutils)RequiredOptional RESTManager RESTObject) CreateMixin CRUDMixin ListMixinObjectDeleteMixin RefreshMixin SaveMixin UpdateMixin)ProjectAccessRequestManager)ProjectAuditEventManager)ProjectBadgeManager)ProjectBoardManager)ProjectBranchManagerProjectProtectedBranchManager)ProjectClusterManager)ProjectCommitManager) ProjectRegistryRepositoryManager)ProjectCustomAttributeManager)ProjectKeyManager)ProjectDeployTokenManager)ProjectDeploymentManager)ProjectEnvironmentManager)ProjectEventManager)ProjectExportManagerProjectImportManager)ProjectFileManager)ProjectHookManager)ProjectIssueManager)ProjectJobManager)ProjectLabelManager)ProjectMemberAllManagerProjectMemberManager)ProjectApprovalManagerProjectApprovalRuleManager)ProjectMergeRequestManager)ProjectMilestoneManager)ProjectNoteManager)"ProjectNotificationSettingsManager)GenericPackageManagerProjectPackageManager)ProjectPagesDomainManager)ProjectPipelineProjectPipelineManagerProjectPipelineScheduleManager)ProjectAccessTokenManager)ProjectPushRulesManager)ProjectReleaseManager)RepositoryMixin)ProjectRunnerManager)ProjectServiceManager)ProjectSnippetManager)"ProjectAdditionalStatisticsManagerProjectIssuesStatisticsManager)ProjectProtectedTagManagerProjectTagManager)ProjectTriggerManager)ProjectUserManager)ProjectVariableManager)ProjectWikiManager GroupProjectGroupProjectManagerProjectProjectManager ProjectForkProjectForkManagerProjectRemoteMirrorProjectRemoteMirrorManagerc@s eZdZdS)rMN)__name__ __module__ __qualname__rXrXY/home/ec2-user/environment/venv/lib/python3.6/dist-packages/gitlab/v4/objects/projects.pyrMTsc@s eZdZdZeZddiZdZdS)rNz/groups/%(group_id)s/projectsgroup_ididarchived visibilityorder_bysortsearchsimpleownedstarredwith_custom_attributesinclude_subgroupswith_issues_enabledwith_merge_requests_enabled with_sharedmin_access_levelwith_security_reportsN)r\r]r^r_r`rarbrcrdrerfrgrhrirj)rUrVrW_pathrM_obj_cls_from_parent_attrs _list_filtersrXrXrXrYrNXs$c5@seZdZdZdZejddejej e e djdkdldmZ ejdejej e djdndodpZejdejeje eeee fejfdndqdrZejdejej e djdndsdtZejdejej e djdndudvZejdejej e djdndwdxZejdejej e djdndydzZejdddejej de e eee djd~ddZejddejej e e djdddZejddejej deeeeee fe edddZejdejeje djdnddZ ejddejej!deee"eee eee fdddZ#ejdddejejde$e$ee%e e ee"dddZ&ejddejej'eee ee(j)e*eee ffdddZ+ejdejej e djdnddZ,ejddejej-ee djdddZ.ejdddejejdeee$ee%e e ee"dddZ/ejddejejdeeee$ee%e e ee"dddZ0djS)rOpath access_tokensr>accessrequestsr approvalsr2 approvalrulesr3badgesrboardsrbranchesrjobsr.commitsr!customattributesr# deploymentsr& environmentsr'eventsr( audit_eventsrexportsr)filesr+forksrRgeneric_packagesr8hooksr,keysr$importsr*issuesr-labelsr/membersr1 members_allr0 mergerequestsr4 milestonesr5notesr6notificationsettingsr7packagesr9 pagesdomainsr: pipelinesr<protectedbranchesr protectedtagsrGpipelineschedulesr= pushrulesr?releasesr@remote_mirrorsrT repositoriesr"runnersrBservicesrCsnippetsrDtagsrHusersrJtriggersrI variablesrKwikisrLclustersr additionalstatisticsrEissues_statisticsrFissuesstatistics deploytokensr%forked_from_idN)rkwargsreturncKs&d|j|f}|jjj|f|dS)aCreate a forked from/to relation between existing projects. Args: forked_from_id (int): The ID of the project that was forked from **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the relation could not be created z/projects/%s/fork/%sN)get_idmanagergitlab http_post)selfrrrorXrXrYcreate_fork_relations zProject.create_fork_relation)rrcKs"d|j}|jjj|f|dS)a5Delete a forked relation between existing projects. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request z/projects/%s/forkN)rrr http_delete)rrrorXrXrYdelete_fork_relations zProject.delete_fork_relationcKsd|j}|jjj|f|S)a7Get languages used in the project with percentage value. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request z/projects/%s/languages)rrrhttp_get)rrrorXrXrY languagess zProject.languagescKs>d|j}|jjj|f|}tr0t|ts0t|j|dS)aStar a project. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request z/projects/%s/starN) rrrrr isinstancedictAssertionError _update_attrs)rrro server_datarXrXrYstars z Project.starcKs>d|j}|jjj|f|}tr0t|ts0t|j|dS)aUnstar a project. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request z/projects/%s/unstarN) rrrrrrrrr)rrrorrXrXrYunstars zProject.unstarcKs>d|j}|jjj|f|}tr0t|ts0t|j|dS)aArchive a project. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request z/projects/%s/archiveN) rrrrrrrrr)rrrorrXrXrYarchives zProject.archivecKs>d|j}|jjj|f|}tr0t|ts0t|j|dS)aUnarchive a project. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request z/projects/%s/unarchiveN) rrrrrrrrr)rrrorrXrXrY unarchive s zProject.unarchiverZ group_access expires_at)rZrrrrcKs6d|j}|||d}|jjj|fd|i|dS)aShare the project with a group. Args: group_id (int): ID of the group. group_access (int): Access level for the group. **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request z/projects/%s/share)rZrr post_dataN)rrrr)rrZrrrrodatarXrXrYshares  z Project.share)rZrrcKs&d|j|f}|jjj|f|dS)a[Delete a shared project link within a group. Args: group_id (int): ID of the group. **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request z/projects/%s/share/%sN)rrrr)rrZrrorXrXrYunshare<s zProject.unsharereftoken)rrrrrcKsX|pi}d|j}|||d}|jjj|fd|i|}trLt|tsLtt|j |S)aTrigger a CI build. See https://gitlab.com/help/ci/triggers/README.md#trigger-a-build Args: ref (str): Commit to build; can be a branch name or a tag token (str): The trigger token variables (dict): Variables passed to the build script **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request z/projects/%s/trigger/pipeline)rrrr) rrrrrrrrr;r)rrrrrrorattrsrXrXrYtrigger_pipelineMs  zProject.trigger_pipelinecKs"d|j}|jjj|f|dS)aIStart the housekeeping task. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabHousekeepingError: If the server failed to perform the request z/projects/%s/housekeepingN)rrrr)rrrorXrXrY housekeepingls zProject.housekeepingfilenamefilepath)rfiledatarrrc Ks|dkr|dkrtjd|dk r4|dk r4tjd|dk rZt|d}|j}WdQRXdd|ji}d||fi}|jjj||d}trt |t st |d |d |d d S) aUpload the specified file into the project. .. note:: Either ``filedata`` or ``filepath`` *MUST* be specified. Args: filename (str): The name of the file being uploaded filedata (bytes): The raw data of the file being uploaded filepath (str): The path to a local file to upload (optional) Raises: GitlabConnectionError: If the server cannot be reached GitlabUploadError: If the file upload fails GitlabUploadError: If ``filedata`` and ``filepath`` are not specified GitlabUploadError: If both ``filedata`` and ``filepath`` are specified Returns: dict: A ``dict`` with the keys: * ``alt`` - The alternate text for the upload * ``url`` - The direct url to the uploaded file * ``markdown`` - Markdown for the uploaded file Nz"No file contents or path specifiedz%File contents and file path specifiedrbz/projects/%(id)s/uploadsr[file)ralturlmarkdown)rrr) excGitlabUploadErroropenreadr[rrrrrrr) rrrrrfr file_inforrXrXrYupload}s"    zProject.uploadwiki)optionalF)rstreamedaction chunk_sizerrcKsLd|j}|jjj|f|dd|}trrqrrrr2rsr3rtrrurrvrrwr.rxr!ryr#rzr&r{r'r|r(r}rr~r)rr+rrRrr8rr,rr$rr*rr-rr/rr1rr0rr4rr5rr6rr7rr9rr:rr<rrrrGrr=rr?rr@rrTrr"rrBrrCrrDrrHrrJrrIrrKrrLrr rrErrFrrFrr%)4rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrrrrrrr)r)rZr)r)N)rZ)rr)N)rr)NN)r)FFNr)rr`)r)rr)r)FNr)rrr)FNr)1rUrVrWZ_short_print_attrZ _managersr Zregister_custom_actionrZ on_http_errorZGitlabCreateErrorintrrZGitlabDeleteErrorrZGitlabGetErrorr rstrrrrrrrrrrrr;rZGitlabHousekeepingErrorrrbytesrboolrrZGitlabSearchErrorr Z GitlabListrr`rZGitlabTransferProjectErrorrrrrXrXrXrYrOos     &              ,    (       c?seZdZdZeZedmd=Zednd=ZdoZ e j e j d^Z dpeeefeeed`fdadb ZdqeeeeeeeeeeefeeeeefejfdddedfZdreeeeeeeeeeeeeefejfdg dhdiZdseeeeeeeeeefejfdjdkdlZZS)trPz /projectsnameroallow_merge_on_skipped_pipelineanalytics_access_levelapprovals_before_mergeauto_cancel_pending_pipelinesauto_devops_deploy_strategyauto_devops_enabledautoclose_referenced_issuesavatarbuild_coverage_regexbuild_git_strategy build_timeoutbuilds_access_levelci_config_path&container_expiration_policy_attributescontainer_registry_enableddefault_branch descriptionemails_disabled+external_authorization_classification_labelforking_access_levelgroup_with_project_templates_id import_urlinitialize_with_readmeissues_access_levelissues_enabled jobs_enabled lfs_enabled merge_methodmerge_requests_access_levelmerge_requests_enabledmirror_trigger_buildsmirror namespace_idoperations_access_level0only_allow_merge_if_all_discussions_are_resolved%only_allow_merge_if_pipeline_succeedspackages_enabledpages_access_levelrequirements_access_level#printing_merge_request_link_enabled public_builds remove_source_branch_after_mergerepository_access_levelrepository_storagerequest_access_enabled!resolve_outdated_diff_discussionsshared_runners_enabledshow_default_award_emojissnippets_access_levelsnippets_enabledtag_list template_nametemplate_project_iduse_custom_templater]wiki_access_level wiki_enabled)rci_default_git_depthci_forward_deployment_enabled#mirror_overwrites_diverged_branchesmirror_user_idonly_mirror_protected_branchesrestrict_user_defined_variablesservice_desk_enabledsuggestion_commit_messageissues_templatemerge_requests_templater\id_after id_beforelast_activity_afterlast_activity_before membershiprir^rbrepository_checksum_failedsearch_namespacesr`rar_rc statisticstopicwiki_checksum_failedrdrfrgwith_programming_language)r+rnF)r[lazyrrc stttjf||d|S)N)r[rq)rrOsuperget)rr[rqr) __class__rXrYrs szProjectManager.getN)rror#r overwriteoverride_paramsrrc Ksvdd|dfi}|t|d} |rBx |jD]\} } | | d| <q*W|dk rR|| d<|r^|| d<|jjd | |d |S) aImport a project from an archive file. Args: file: Data or file object containing the project path (str): Name and path for the new project namespace (str): The ID or path of the namespace that the project will be imported to overwrite (bool): If True overwrite an existing project with the same path override_params (dict): Set the specific settings for the project **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the server failed to perform the request Returns: dict: A representation of the import status. rz file.tar.gzzapplication/octet-stream)roruzoverride_params[%s]Nr#r/projects/import)rr)rw)r itemsrr) rrror#rrurvrrrkvrXrXrYimport_projectszProjectManager.import_project) bitbucket_server_urlbitbucket_server_usernamepersonal_access_tokenbitbucket_server_projectbitbucket_server_reponew_nametarget_namespacerrc Ksj|||||d} |r|| d<|r(|| d<d|ksH|jjdksH|jjdkrPd|d<|jjd d| i|} | S) a^ Import a project from BitBucket Server to Gitlab (schedule the import) This method will return when an import operation has been safely queued, or an error has occurred. After triggering an import, check the ``import_status`` of the newly created project to detect when the import operation has completed. .. note:: This request may take longer than most other API requests. So this method will specify a 60 second default timeout if none is specified. A timeout can be specified via kwargs to override this functionality. Args: bitbucket_server_url (str): Bitbucket Server URL bitbucket_server_username (str): Bitbucket Server Username personal_access_token (str): Bitbucket Server personal access token/password bitbucket_server_project (str): Bitbucket Project Key bitbucket_server_repo (str): Bitbucket Repository Name new_name (str): New repository name (Optional) target_namespace (str): Namespace to import repository into. Supports subgroups like /namespace/subgroup (Optional) **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the server failed to perform the request Returns: dict: A representation of the import status. Example: .. code-block:: python gl = gitlab.Gitlab_from_config() print("Triggering import") result = gl.projects.import_bitbucket_server( bitbucket_server_url="https://some.server.url", bitbucket_server_username="some_bitbucket_user", personal_access_token="my_password_or_access_token", bitbucket_server_project="my_project", bitbucket_server_repo="my_repo", new_name="gl_project_name", target_namespace="gl_project_path" ) project = gl.projects.get(ret['id']) print("Waiting for import to complete") while project.import_status == u'started': time.sleep(1.0) project = gl.projects.get(project.id) print("BitBucket import complete") )r|r}r~rrrrtimeoutNgN@/import/bitbucket_serverr)r)rrr) rr|r}r~rrrrrrrrXrXrYimport_bitbucket_server:s B  z&ProjectManager.import_bitbucket_server)r~repo_idrrrrcKsZ|||d}|r||d<d|ks8|jjdks8|jjdkr@d|d<|jjdd|i|}|S) aImport a project from Github to Gitlab (schedule the import) This method will return when an import operation has been safely queued, or an error has occurred. After triggering an import, check the ``import_status`` of the newly created project to detect when the import operation has completed. .. note:: This request may take longer than most other API requests. So this method will specify a 60 second default timeout if none is specified. A timeout can be specified via kwargs to override this functionality. Args: personal_access_token (str): GitHub personal access token repo_id (int): Github repository ID target_namespace (str): Namespace to import repo into new_name (str): New repo name (Optional) **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the server failed to perform the request Returns: dict: A representation of the import status. Example: .. code-block:: python gl = gitlab.Gitlab_from_config() print("Triggering import") result = gl.projects.import_github(ACCESS_TOKEN, 123456, "my-group/my-subgroup") project = gl.projects.get(ret['id']) print("Waiting for import to complete") while project.import_status == u'started': time.sleep(1.0) project = gl.projects.get(project.id) print("Github import complete") )r~rrrrNgN@/import/githubr)r)rrr)rr~rrrrrrrXrXrY import_githubs4  zProjectManager.import_github);r#ror$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYr]rZr[)>r$r%r&r'r(r)r*r+r,r-r.r/r0r\r]r1r2r3r4r5r6r7r9r;r<r=r>r?r@rAr^rBr_rCr#rErFrGr`rHrIrJrarorLrMrNrOrPrQrbrRrSrTrUrcrVr]rZr[rdre)r\rfrgrhrirjrir^rbrkrOrlr`rar_rcrmrnr]rordrfrgrp)F)NNFN)NN)N)rUrVrWrkrOrlr _create_attrsrrnr ZImageAttributeZ ListAttribute_typesr r rr"rrsrrrrr{rr __classcell__rXrX)rtrYrPisH"" ( Vc@s eZdZdS)rQN)rUrVrWrXrXrXrYrQsc @sJeZdZdZeZddiZdZeddZ de e e e fe edddZdS)rRz/projects/%(project_id)s/forks project_idr[r\r]r^r_r`rarbrjrcrmrdrfrgr)rN)rrrcKs>tr|jdk st|jdd}tttj||fd|i|S)a Creates a new object. Args: data (dict): Parameters to send to the server to create the resource **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request Returns: RESTObject: A new instance of the managed object class build with the data sent by the server Nrro)rrorrrQrcreate)rrrrorXrXrYrszProjectForkManager.create) r\r]r^r_r`rarbrjrcrmrdrfrg)r)N)rUrVrWrkrQrlrmrnrrrrr rrrXrXrXrYrRs& c@s eZdZdS)rSN)rUrVrWrXrXrXrYrSsc@s2eZdZdZeZddiZed d dZed dZ d S) rTz'/projects/%(project_id)s/remote_mirrorsrr[renabledonly_protected_branches)requiredr)rN)r)rr)rr) rUrVrWrkrSrlrmrrrrXrXrXrYrTs  )typingrrrrrrrr rrr r r rr rZ gitlab.baserrrZ gitlab.mixinsrrrrrrrZaccess_requestsrr}rrtrrurrvrrrr rxr!Zcontainer_registryr"Zcustom_attributesr#Z deploy_keysr$Z deploy_tokensr%rzr&r{r'r|r(Z export_importr)r*rr+rr,rr-rwr.rr/rr0r1Zmerge_request_approvalsr2r3Zmerge_requestsr4rr5rr6Znotification_settingsr7rr8r9Zpagesr:rr;r<r=Zproject_access_tokensr>Z push_rulesr?rr@rrArrBrrCrrDrmrErFrrGrHrrIrrJrrKrrL__all__rMrNrOrPrQrRrSrTrXrXrXrYs( $                                  }v-