Skip to content

Commit 51d2db5

Browse files
committed
Add project filter support for migrations list
1 parent 74611f5 commit 51d2db5

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

azure-devops/azext_devops/dev/migration/arguments.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def load_migration_arguments(self, _):
1717
with self.argument_context('devops migrations list') as context:
1818
context.argument('include_inactive', options_list='--include-inactive', action='store_true',
1919
help='Include inactive (completed, abandoned, failed) migrations in the results.')
20+
context.argument('project', options_list='--project',
21+
help='Optional project name or ID to filter migrations.')
2022

2123
with self.argument_context('devops migrations create') as context:
2224
context.argument('target_repository', options_list='--target-repository',

azure-devops/azext_devops/dev/migration/migration.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55

66
import re
7+
from urllib.parse import quote_plus
78

89
from msrest import Configuration
910
from msrest.service_client import ServiceClient
@@ -44,12 +45,15 @@
4445
_URL_PATTERN = re.compile(r'^https?://[^\s]+$', re.IGNORECASE)
4546

4647

47-
def list_migrations(include_inactive=False, organization=None, detect=None):
48+
def list_migrations(include_inactive=False, project=None, organization=None, detect=None):
4849
organization = _resolve_org_for_auth(organization, detect)
4950
client = _get_service_client(organization)
5051
url = _build_migration_url(organization)
5152
if include_inactive:
5253
url += '&includeInactiveMigrations=true'
54+
project = _normalize_optional_text(project)
55+
if project:
56+
url += '&project={}'.format(quote_plus(project))
5357
return _send_request(client, 'GET', url)
5458

5559

azure-devops/azext_devops/tests/latest/migration/test_migration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ def test_list_migrations_include_inactive(self):
5353
self.assertEqual(args[1], 'GET')
5454
self.assertIn('includeInactiveMigrations=true', args[2])
5555

56+
def test_list_migrations_with_project_filter(self):
57+
with patch('azext_devops.dev.migration.migration.resolve_instance') as mock_resolve, \
58+
patch('azext_devops.dev.migration.migration._get_service_client') as mock_client, \
59+
patch('azext_devops.dev.migration.migration._send_request') as mock_send:
60+
mock_send.return_value = {}
61+
mock_resolve.return_value = self._TEST_ORG
62+
63+
list_migrations(project='MyProject', organization=self._TEST_ORG, detect=False)
64+
65+
args = mock_send.call_args[0]
66+
self.assertEqual(args[1], 'GET')
67+
self.assertIn('project=MyProject', args[2])
68+
69+
def test_list_migrations_with_project_filter_url_encoded(self):
70+
with patch('azext_devops.dev.migration.migration.resolve_instance') as mock_resolve, \
71+
patch('azext_devops.dev.migration.migration._get_service_client') as mock_client, \
72+
patch('azext_devops.dev.migration.migration._send_request') as mock_send:
73+
mock_send.return_value = {}
74+
mock_resolve.return_value = self._TEST_ORG
75+
76+
list_migrations(project='My Project', organization=self._TEST_ORG, detect=False)
77+
78+
args = mock_send.call_args[0]
79+
self.assertEqual(args[1], 'GET')
80+
self.assertIn('project=My+Project', args[2])
81+
5682
def test_create_migration_payload_defaults_validate_only_false(self):
5783
with patch('azext_devops.dev.migration.migration.resolve_instance') as mock_resolve, \
5884
patch('azext_devops.dev.migration.migration._get_service_client') as mock_client, \

doc/elm_migrations_tsg.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ See if any migrations already exist for your org:
126126
# Active migrations only
127127
az devops migrations list --detect false
128128
129+
# Filter by project name or ID
130+
az devops migrations list --detect false --project MyProject
131+
129132
# All migrations including completed/failed/suspended
130133
az devops migrations list --detect false --include-inactive
131134
```

doc/migrations.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ az repos show --repository MyRepo --project MyProject --query id -o tsv
5252

5353
## Command reference
5454

55-
- `list`: List migrations for the org. Use `--include-inactive` to include completed/failed/suspended migrations.
55+
- `list`: List migrations for the org. Use `--include-inactive` to include completed/failed/suspended migrations. Use `--project` to filter by project name or ID.
5656
- `status`: Show migration status for a repository GUID.
5757
- `create`: Create a migration. Use `--validate-only` for pre-migration checks only.
5858
- `pause`: Pause an active migration.
@@ -97,6 +97,12 @@ What this does:
9797
az devops migrations list --org https://dev.azure.com/myorg
9898
```
9999

100+
### List migrations for a project
101+
102+
```bash
103+
az devops migrations list --org https://dev.azure.com/myorg --project MyProject
104+
```
105+
100106
### List all migrations including inactive
101107

102108
```bash

0 commit comments

Comments
 (0)