Skip to content

Instantly share code, notes, and snippets.

@FilBot3
Last active October 2, 2020 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FilBot3/f19792452b38151b7a1adbb3cde751cd to your computer and use it in GitHub Desktop.
Save FilBot3/f19792452b38151b7a1adbb3cde751cd to your computer and use it in GitHub Desktop.
A better formatted example, in my opinon, of the Azure DevOps REST API Example - https://github.com/microsoft/azure-devops-python-api
#!/usr/bin/env python
"""List and Sort Groups in Azure DevOps Project
.. _Azure DevOps Python API:
https://github.com/microsoft/azure-devops-python-api
"""
import configparser
import logging
import os
import pprint as pp
# import json
from azure.devops.connection import Connection # pylint: disable=import-error
from msrest.authentication import BasicAuthentication # pylint: disable=import-error
def login_bits() -> Connection:
"""Just does login precursor bits.
"""
if os.environ.get('AZDO_LOG'):
logging.basicConfig(level=logging.DEBUG)
if 'AZDO_PAT' in os.environ and 'AZDO_ORG' in os.environ:
azdo_pat = os.environ.get('AZDO_PAT')
ado_org_url = os.environ.get('AZDO_ORG')
else:
logging.info('Attempting to read ${HOME}/.local/azdo_config.ini')
azdo_config = configparser.ConfigParser()
azdo_config.read(os.environ.get('HOME') + '/.local/azdo_config.ini')
azdo_pat = azdo_config['auth']['pat']
ado_org_url = azdo_config['org']['name']
credentials = BasicAuthentication('', azdo_pat)
connection = Connection(base_url=ado_org_url, creds=credentials)
return connection
def main():
"""Main
"""
# Create a Core Client. This gives us access to the Projects API.
core_client = login_bits().clients_v5_1.get_core_client()
get_projects_response = core_client.get_projects()
index = 0
while get_projects_response is not None:
for project in get_projects_response.value:
pp.pprint('[' + str(index) + '] ' + project.name)
index += 1
if get_projects_response.continuation_token is not None \
and get_projects_response.continuation_token != "":
get_projects_response = core_client.get_projects(
continuation_token=get_projects_response.continuation_token)
else:
get_projects_response = None
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment