英文:
How to use documentation of azure DevOps python API, I am trying to get what members an object has when API call is made?
问题
我正在使用Azure DevOps的Python API,尝试获取每个仓库的仓库列表和分支列表。当API调用返回对象时,我不知道对象有哪些成员。我不确定文档是否完整,如何知道对象有哪些成员?
对于“repo”对象,我猜测了“name”属性。
在上面的代码中,我只猜测了一个仓库的名称属性。我想知道这些仓库各自有哪些分支。
TIA
英文:
I'm using the python API for Azure DevOps, I am trying to get a list of repo and branches each repo has. I don't know what members an object has when the API call returns the object. I am not sure if the documentation is complete, How to know what members an object has?
like for an object of "repo", I guessed the "name" property
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint
# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'
project_name = "XYZ"
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# Get a client (the "core" client provides access to projects, teams, etc)
git_client = connection.clients.get_git_client
# Get the first page of projects
get_repos_response = git_client.get_repositories(project_name)
index = 0
for repo in get_repos_response:
pprint.pprint(str(index) + "." + repo.name)
index += 1
In the above code, I just guessed the name property of a repo. I want to know what branches each of these repos have.
TIA
答案1
得分: 1
基于这些描述,您想要应用Python API来获取存储库列表、相应存储库的分支列表以及分支的创建者。对于“分支最后使用的时间”,不确定是否指的是分支的最新更新时间。
如果是这样,请参考这个源代码示例。
-
它只能基于提供的项目名称获取,因此使用
_send
将参数传递给客户端:route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') query_parameters = {} if include_links is not None: query_parameters['includeLinks'] = self._serialize.query('include_links', include_links, 'bool') if include_all_urls is not None: query_parameters['includeAllUrls'] = self._serialize.query('include_all_urls', include_all_urls, 'bool') if include_hidden is not None: query_parameters['includeHidden'] = self._serialize.query('include_hidden', include_hidden, 'bool') response = self._send(http_method='GET', location_id='225f7195-f9c7-4d14-ab28-a83f7ff77e1f', version='6.0-preview.1', route_values=route_values, query_parameters=query_parameters) return self._deserialize('[GitRepository]', self._unwrap_collection(response))
-
获取分支:
还需要额外添加
repository_id
和base_version_descriptor
:if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') query_parameters = {} if include_links is not None: query_parameters['includeLinks'] = self._serialize.query('include_links', include_links, 'bool') if include_all_urls is not None: query_parameters['includeAllUrls'] = self._serialize.query('include_all_urls', include_all_urls, 'bool') if include_hidden is not None: query_parameters['includeHidden'] = self._serialize.query('include_hidden', include_hidden, 'bool')
-
分支创建者
和最新更新时间
,这些信息包含在一个指定的分支中,应该通过获取分支来获取。此时,name
是必需的,代表一个指定的分支名称:route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') if repository_id is not None: route_values['repositoryId'] = self._serialize.url('repository_id', repository_id, 'str') query_parameters = {} if name is not None: query_parameters['name'] = self._serialize.query('name', name, 'str') if base_version_descriptor is not None: if base_version_descriptor.version_type is not None: query_parameters['baseVersionDescriptor.versionType'] = base_version_descriptor.version_type if base_version_descriptor.version is not None: query_parameters['baseVersionDescriptor.version'] = base_version_descriptor.version if base_version_descriptor.version_options is not None: query_parameters['baseVersionDescriptor.versionOptions'] = base_version_descriptor.version_options
英文:
Based on these description, you want to apply the python api to get Repos list, branch list of corresponding repos and the creator of branch. For >>when the branch was last used, not sure whether it means the latest update time of the branch.
If this, just refer to this source code sample.
-
It can only be got based on the project name provided, so use
_send
to pass the parameters to client:route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') query_parameters = {} if include_links is not None: query_parameters['includeLinks'] = self._serialize.query('include_links', include_links, 'bool') if include_all_urls is not None: query_parameters['includeAllUrls'] = self._serialize.query('include_all_urls', include_all_urls, 'bool') if include_hidden is not None: query_parameters['includeHidden'] = self._serialize.query('include_hidden', include_hidden, 'bool') response = self._send(http_method='GET', location_id='225f7195-f9c7-4d14-ab28-a83f7ff77e1f', version='6.0-preview.1', route_values=route_values, query_parameters=query_parameters) return self._deserialize('[GitRepository]', self._unwrap_collection(response))
-
Add
repository_id
andbase_version_descriptor
additionally:if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') query_parameters = {} if include_links is not None: query_parameters['includeLinks'] = self._serialize.query('include_links', include_links, 'bool') if include_all_urls is not None: query_parameters['includeAllUrls'] = self._serialize.query('include_all_urls', include_all_urls, 'bool') if include_hidden is not None: query_parameters['includeHidden'] = self._serialize.query('include_hidden', include_hidden, 'bool')
-
branch creator
andthe latest update time
, these message are contained in one specified branch and should be get by getting branch. At this time, thename
is necessary which represent one specified branch name:route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') if repository_id is not None: route_values['repositoryId'] = self._serialize.url('repository_id', repository_id, 'str') query_parameters = {} if name is not None: query_parameters['name'] = self._serialize.query('name', name, 'str') if base_version_descriptor is not None: if base_version_descriptor.version_type is not None: query_parameters['baseVersionDescriptor.versionType'] = base_version_descriptor.version_type if base_version_descriptor.version is not None: query_parameters['baseVersionDescriptor.version'] = base_version_descriptor.version if base_version_descriptor.version_options is not None: query_parameters['baseVersionDescriptor.versionOptions'] = base_version_descriptor.version_options
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论