devops_utils.core.azure_devops.repos module
Git repository queries against the Azure DevOps REST API.
Three search tiers, from most to least portable:
list_repositories()withname_filter— repo metadata, everywhere.find_repo_items()— file paths via the Git Items API, everywhere.code_search()— content search via the Search extension, which cloud always has but on-prem servers may lack (it fails with a clear error there).
- devops_utils.core.azure_devops.repos.code_search(client: AzureDevOpsClient, project: str, text: str, *, repo: str | None = None, branch: str | None = None, top: int = 25) list[dict[str, Any]][source]
Search code content via the Search extension API.
Cloud (dev.azure.com) always has the extension; on-prem servers need the Code Search extension installed — without it this raises a clear error, and
find_repo_items()/ WIQL work-item search are the fallbacks.- Parameters:
text – Search text (supports the code-search syntax, e.g.
def:Foo).repo – Optional repository name to scope to.
branch – Optional branch to scope to.
top – Maximum number of results.
- Returns:
A list of
{path, repo, project, matches}dicts, wherematchescounts content hits in the file.
- devops_utils.core.azure_devops.repos.find_repo_items(client: AzureDevOpsClient, project: str, repo: str, *, path_pattern: str = '*', branch: str | None = None, top: int = 100) list[dict[str, Any]][source]
Find files in a repository by path pattern (no Search extension needed).
Lists the full tree via the Git Items API and matches each path against
path_patternwithfnmatch(*also crosses/here because a bare filename pattern like*.ymlshould match at any depth).- Parameters:
path_pattern – Glob matched against the repo-relative path (leading
/stripped), e.g.*.ymlorsrc/*/pipeline*.branch – Optional branch to list (defaults to the repo default branch).
top – Maximum number of matches to return.
- Returns:
A list of
{path, size, commit, url}dicts for matching blobs.
- devops_utils.core.azure_devops.repos.list_repositories(client: AzureDevOpsClient, project: str | None = None, *, name_filter: str | None = None) list[dict[str, Any]][source]
List Git repositories, optionally scoped to a single project.
- Parameters:
name_filter – Optional case-insensitive substring to filter repo names by.
Returns a trimmed list of
{id, name, project, default_branch, web_url}.
- devops_utils.core.azure_devops.repos.resolve_repo(client: AzureDevOpsClient, project: str, repo: str) dict[str, str][source]
Look up a repository by id or name and return its ids.
Returns
{"project_id": ..., "repo_id": ...}. Both GUIDs are needed to build thevstfs://artifact URIs used for commit/PR/branch links.