Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Project
azure-devops-runner-config.json
vsts-runner-config.json

# Editors
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Now you can run `runner.py` with no arguments to see available options.

> **VERY IMPORTANT**: some samples are destructive! It is recommended that you run these samples against a test organization.

1. Get a [personal access token](https://docs.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts).
1. Get a [personal access token](https://docs.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops).

2. Store the PAT and organization URL you'll be running samples against (note: some samples are destructive, so use a test organization):
* `python runner.py config url --set-to https://fabrikam.visualstudio.com`
* `python runner.py config url --set-to https://dev.azure.com/fabrikam`
* `python runner.py config pat --set-to ABC123`
* If you don't want your PAT persisted to a file, you can put it in an environment variable called `AZURE_DEVOPS_PAT` instead

Expand Down
2 changes: 1 addition & 1 deletion contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
def get_repos(context):
project = find_any_project(context)

git_client = context.connection.get_client("vsts.git.git_client.GitClient")
git_client = context.connection.clients.get_git_client()

repos = git_client.get_repositories(project.id)
for repo in repos:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# if you just want the command-line samples experience, use this requirements file
vsts==0.1.8
azure-devops==5.0.0b5
8 changes: 7 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from utils import emit


DEFAULT_CONFIG_FILE_NAME = "vsts-runner-config.json"
DEFAULT_CONFIG_FILE_NAME = "azure-devops-runner-config.json"
OLD_DEFAULT_CONFIG_FILE_NAME = "vsts-runner-config.json"
CONFIG_KEYS = [
'url',
'pat',
Expand All @@ -25,6 +26,11 @@ def __init__(self, filename=None):
with open(filename) as config_fp:
self._config = json.load(config_fp)
except FileNotFoundError:
emit("warning: no config file found.")
emit("The default filename has changed. You may need to rename")
emit(OLD_DEFAULT_CONFIG_FILE_NAME)
emit("to")
emit(DEFAULT_CONFIG_FILE_NAME)
self._config = {}
except json.JSONDecodeError:
emit("possible bug: config file exists but isn't parseable")
Expand Down
6 changes: 3 additions & 3 deletions src/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# logging.basicConfig(level=logging.INFO)

from vsts.credentials import BasicAuthentication
from vsts.vss_connection import VssConnection
from azure.devops.credentials import BasicAuthentication
from azure.devops.connection import Connection

from config import Config
import http_logging
Expand All @@ -30,7 +30,7 @@ def main(url, area, resource, auth_token, output_path=None):
context.runner_cache = SimpleNamespace()

# setup the connection
context.connection = VssConnection(
context.connection = Connection(
base_url=url,
creds=BasicAuthentication('PAT', auth_token),
user_agent='azure-devops-python-samples/' + __VERSION__)
Expand Down
2 changes: 1 addition & 1 deletion src/samples/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@resource('projects')
def get_projects(context):
core_client = context.connection.get_client("vsts.core.v4_1.core_client.CoreClient")
core_client = context.connection.clients.get_core_client()

projects = core_client.get_projects()

Expand Down
4 changes: 2 additions & 2 deletions src/samples/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def get_repos(context):
project = find_any_project(context)

git_client = context.connection.get_client("vsts.git.v4_1.git_client.GitClient")
git_client = context.connection.clients.get_git_client()

repos = git_client.get_repositories(project.id)

Expand All @@ -28,7 +28,7 @@ def get_repos(context):
def get_refs(context):
repo = find_any_repo(context)

git_client = context.connection.get_client("vsts.git.v4_1.git_client.GitClient")
git_client = context.connection.clients.get_git_client()

refs = git_client.get_refs(repo.id, repo.project.id)

Expand Down
10 changes: 5 additions & 5 deletions src/samples/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@


def get_project_names(context):
core_client = context.connection.get_client("vsts.core.v4_1.core_client.CoreClient")
core_client = context.connection.clients.get_core_client()
return (project.name for project in core_client.get_projects())


@resource("test_plans")
def get_plans(context):
test_client = context.connection.get_client("vsts.test.v4_1.test_client.TestClient")
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for plan in test_client.get_plans(project):
Expand All @@ -29,7 +29,7 @@ def get_plans(context):

@resource("test_suites")
def get_test_suites_for_plan(context):
test_client = context.connection.get_client("vsts.test.v4_1.test_client.TestClient")
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for plan in test_client.get_plans(project):
Expand All @@ -45,7 +45,7 @@ def get_test_suites_for_plan(context):

@resource("test_runs")
def get_test_runs(context):
test_client = context.connection.get_client("vsts.test.v4_1.test_client.TestClient")
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for run in test_client.get_test_runs(project, top=16):
Expand All @@ -60,7 +60,7 @@ def get_test_runs(context):

@resource("test_results")
def get_test_results(context):
test_client = context.connection.get_client("vsts.test.v4_1.test_client.TestClient")
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for run in test_client.get_test_runs(project, top=10):
Expand Down
14 changes: 4 additions & 10 deletions src/samples/work_item_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from samples import resource
from utils import emit

from vsts.work_item_tracking.v4_1.models.wiql import Wiql
from azure.devops.v5_1.work_item_tracking.models import Wiql

logger = logging.getLogger(__name__)

Expand All @@ -24,9 +24,7 @@ def print_work_item(work_item):

@resource("work_items")
def get_work_items(context):
wit_client = context.connection.get_client(
"vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"
)
wit_client = context.connection.clients.get_work_item_tracking_client()

desired_ids = range(1, 51)
work_items = wit_client.get_work_items(ids=desired_ids, error_policy="omit")
Expand All @@ -42,9 +40,7 @@ def get_work_items(context):

@resource("work_items")
def get_work_items_as_of(context):
wit_client = context.connection.get_client(
"vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"
)
wit_client = context.connection.clients.get_work_item_tracking_client()

desired_ids = range(1, 51)
as_of_date = datetime.datetime.now() + datetime.timedelta(days=-7)
Expand All @@ -63,9 +59,7 @@ def get_work_items_as_of(context):

@resource("wiql_query")
def wiql_query(context):
wit_client = context.connection.get_client(
"vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"
)
wit_client = context.connection.clients.get_work_item_tracking_client()
wiql = Wiql(
query="""
select [System.Id],
Expand Down
4 changes: 2 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def find_any_project(context):
return context.runner_cache.project

with http_logging.temporarily_disabled():
core_client = context.connection.get_client("vsts.core.v4_1.core_client.CoreClient")
core_client = context.connection.clients.get_core_client()
projects = core_client.get_projects()

try:
Expand All @@ -44,7 +44,7 @@ def find_any_repo(context):

with http_logging.temporarily_disabled():
project = find_any_project(context)
git_client = context.connection.get_client("vsts.git.v4_1.git_client.GitClient")
git_client = context.connection.clients.get_git_client()
repos = git_client.get_repositories(project.id)

try:
Expand Down