How to use documentation of azure DevOps python API, I am trying to get what members an object has when API call is made?

huangapple go评论81阅读模式
英文:

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_idbase_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.

  • Get repositories:

    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))
    
  • Get branches:

    Add repository_id and base_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 and the latest update time, these message are contained in one specified branch and should be get by getting branch. At this time, the name 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
    

huangapple
  • 本文由 发表于 2020年1月6日 20:35:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定