def get_devopsconnection(project): token = project["token"] url = project["url"] credentials = BasicAuthentication("PAT", token) connection = Connection(base_url=url, creds=credentials) conn = connection.get_client( 'azure.devops.v5_1.work_item_tracking.work_item_tracking_client.WorkItemTrackingClient' ) return conn
def _get_client(organization: str, username: str, password: str) -> 'AzureReposGitClient': """ This method configures this client to connect to Azure Repos. Args: organization: the organization within the Azure DevOps instance username: the username for the organization password: this can be a password for no MFA, or the git credentials password that overrides MFA Returns: an instance of the azure-devops v6.0 GitClient """ base_url = f'https://dev.azure.com/{organization}' credentials = BasicAuthentication(username=username, password=password) connection = Connection(base_url=base_url, creds=credentials) client_type = 'azure.devops.v6_0.git.git_client.GitClient' return connection.get_client(client_type=client_type)
personal_access_token = 'iywk3uook2xwvsmjhoztcb7qvka4qrpjvdtjicgaif3ofy5x4gbq' organization_url = 'https://dev.azure.com/swansea-university' project_name = 'Swansea Academy of Advanced Computing' # Create a connection to the org credentials = BasicAuthentication('', personal_access_token) connection = Connection(base_url=organization_url, creds=credentials) # connection.get_client('azure.devops.released.core.core_client.CoreClient') # Get clients # the "core" client provides access to projects, teams, etc client = connection.clients.get_core_client() # the "work item track" client provides access to work items wit_client = connection.get_client( 'azure.devops.v6_0.work_item_tracking.work_item_tracking_client.WorkItemTrackingClient' ) def all_teams(): return client.get_teams(project_id=project_name) def query_work_items(q): work_item_references = wit_client.query_by_wiql(Wiql(q)).work_items work_item_ids = [item.id for item in work_item_references] return work_items_by_id(work_item_ids)