Reputation: 113
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
Upvotes: 2
Views: 3079
Reputation: 18978
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
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
Upvotes: 1