Skip to content
safran

Type to search. Enter opens the first result.

    Azure Repos

    The azure-repos code host lists the Git repositories of an Azure DevOps organization, supplies the credentials to clone them, and reads completed pull requests with their linked work items and changed files. It works with Azure DevOps Services (dev.azure.com) and Azure DevOps Server. It also reads pull requests as they are now: reviewers and votes, changed files, review threads and diffs. It reads only, unless the profile turns writes on: then it can also comment on a pull request and reply in a review thread.

    Profile entry

    - id: azure
      type: azure-repos
      organization: acme
      project: Platform
      token_env: AZURE_DEVOPS_PAT

    With AZURE_DEVOPS_PAT set:

    safran repos
    safran sync
    safran links refresh --since 2026-01-01
    list-repos.ts
    import { createSafran } from "@safran/core";
    
    await using safran = await createSafran({ profile: "safran.yaml" });
    
    for (const repo of await safran.repos.list()) {
      console.log(repo.name, repo.fullName, repo.defaultBranch, repo.cloned ? "cloned" : "not cloned");
    }
    
    // Problems of the listing: a host that failed, or a repo name that exists on two hosts.
    for (const warning of safran.repos.warnings()) console.warn(warning.source, warning.code, warning.message);

    Authentication

    token_env names a variable holding a personal access token with the Code (Read) scope. A token belongs to one organization.

    • REST requests send it as HTTP Basic with an empty user name.
    • Git gets the same Basic header, and only through the environment of the git process (an http.<origin>.extraHeader setting passed as GIT_CONFIG_* variables). The token is never written into the clone URL, so it cannot end up in .git/config, in a process listing or in a log. Clone URLs reported by Azure DevOps carry organization@ in front of the host; that part is removed.

    An invalid or expired token is often answered with HTTP 203 and an HTML sign-in page instead of 401. The connector reports a 203, any redirect and any HTML answer as AUTH_FAILED, with a hint that names the variable and the organization. Redirects are never followed with the token attached.

    Several projects, or the whole organization

    - id: azure
      type: azure-repos
      organization: acme
      projects: [Platform, Mobile]
      token_env: AZURE_DEVOPS_PAT
      exclude: ["*-archive", "sandbox-*"]

    project: A is shorthand for one entry in projects; both may be given and are merged. Project names are compared case-insensitively, and the first spelling wins. With neither, the repositories of every project the token can see are listed.

    Azure DevOps Server

    - id: azure
      type: azure-repos
      url: https://devops.acme.test/tfs
      organization: DefaultCollection
      project: Platform
      token_env: AZURE_DEVOPS_PAT
      api_version: "6.0"

    url is the server root in front of the collection and organization is the collection name. These fields have the same names and meaning as in the azure-boards tracker.

    Configuration reference

    FieldTypeDefaultRequiredMeaning
    idstringyesName of this entry; the host of its repositories.
    includestring[][]noGlob patterns on repository names. Empty means all.
    excludestring[][]noGlob patterns on repository names. Exclude wins over include.
    type"azure-repos"yesSelects this plugin.
    organizationstringyesOrganization on dev.azure.com, or the collection name on Azure DevOps Server. No slashes.
    projectstringnoShorthand for a single entry in projects.
    projectsstring[][]noProjects whose repositories are listed. Empty (with no project): every project the token can see.
    token_envvariable nameyesVariable holding a personal access token with Code (Read).
    urlURLhttps://dev.azure.comnoAzure DevOps Server only: the server root in front of the collection.
    api_versionstring"7.1"noREST API version, like "7.1" or "7.1-preview.3". Quote it in YAML.
    include_disabledbooleanfalsenoDisabled repositories cannot be cloned. Off: they are left out. On: they are listed with archived: true.
    token_expiresdate (YYYY-MM-DD)noThe day this entry's token stops working, when you know it. Only used to warn two weeks ahead (safran doctor, get_server_info); never for authentication.

    How repositories are listed and named

    The repository list is not paged: one request per configured project (or one for the whole organization) returns everything in scope.

    • A repository is called by its plain name: payments-api.
    • When two projects of the entry hold a repository of the same name, both become project/repo (Platform/tools and Mobile/tools). Names are compared case-insensitively, and the result depends only on the set of repositories, not on the order the API returned them.
    • fullName is organization/project/repo.
    • A repository without a default branch has no commits yet and is skipped.
    • Disabled repositories are skipped unless include_disabled is on.

    If the same short name also exists on another code host entry, the host listed first in the profile keeps it and the later one is named <hostId>/<name>; safran.repos.warnings() reports that.

    include and exclude

    Both are applied by Safran after the listing, to the short name and to fullName: a repository is kept when no exclude pattern matches either name, and include is empty or one of its patterns matches either. The dialect is small: * is any run of characters, ? is exactly one, everything else is literal; matching is case-insensitive and covers the whole name.

    - id: azure
      type: azure-repos
      organization: acme
      token_env: AZURE_DEVOPS_PAT
      include: ["acme/Platform/*", "acme-ios", "acme-android"]
      exclude: ["*-poc"]

    Pull requests and linked tickets

    safran links refresh reads completed pull requests. For each one the host returns:

    PullRequest fieldSource
    idThe pull request id
    title, descriptionAs listed. The list endpoint cuts descriptions at 400 characters.
    mergedAtThe closed date
    mergeCommitThe last merge commit
    sourceBranch, targetBranchBranch names without refs/heads/
    linkedTicketKeysThe ids of the work items linked to the pull request in Azure DevOps
    url<repository web URL>/pullrequest/<id>

    What counts as a linked ticket. The host's own answer is the list of work items attached to the pull request: numeric ids such as 1423, which is the key of the azure-boards tracker. Reading them costs one extra request per pull request, DEFAULT_ENRICH_CONCURRENCY at a time.

    Safran then adds the keys it finds in the title, the source branch and the description, for the project keys declared under trackers[].projects. That is how the acme setup works, where code is in Azure Repos and tickets are in Jira: a pull request from the branch feature/PAY-1423-partial-refund is linked to PAY-1423 although Azure DevOps knows nothing about Jira. Because descriptions arrive cut to 400 characters, a key that only appears further down in a long description is not seen; put it in the title or the branch name.

    Changed files come from the latest iteration of the pull request, compared with the merge base. Deleted files and the old side of a rename are left out; the new side of a rename is kept.

    mergedSince is sent to Azure DevOps and applied again on the client, because the service silently ignores query parameters it does not know.

    Live pull requests

    With the capabilities pull-requests-live, pr-diff and pr-threads the connector reads pull requests as they are now: safran pulls, safran.pulls and the pull request tools.

    • References. …/{project}/_git/{repo}/pullrequest/{id} with any query (?_a=files, ?discussionId=7) or fragment, on the configured server and organization, or on {organization}.visualstudio.com for a dev.azure.com entry. The UI leaves the project out when the repository carries its name; that form matches too. Projects are limited to the configured ones.
    • Votes. Azure's numbers map one to one: 10 → approved, 5 → approved_with_suggestions, 0 → none, −5 → waiting, −10 → rejected. required is the reviewer's "required" flag.
    • Thread status. active and pending are active; fixed, wontFix, closed and byDesign are resolved, with the word kept as resolution. A thread without a status counts as active. Azure DevOps has no "outdated" state: a thread follows its line across pushes, so outdated is never used.
    • The diff is computed here. Azure Repos has no endpoint that answers a patch. For each changed file of the latest iteration the connector downloads the file version before and after by blob id and compares them line by line. The hunks describe the same change git would print but are not always split the same way. That costs up to two downloads per file; a file version over DEFAULT_AZURE_DIFF_MAX_BLOB_BYTES (512 KiB) is not diffed and comes back truncated with an empty patch, and a NUL byte among the first 8,000 bytes makes a file binary, as it does for git.

    Writes

    Off unless the profile enables them; see writes.

    • pull_request.comment (write:pr-comment): starts one thread, in the general conversation, on a file, or on a line. Azure DevOps accepts a thread on any path, and a thread on a path that does not exist is an orphan nobody finds, so the path is looked up in the changes of the latest iteration first and refused with INVALID_INPUT when the pull request does not change it. The line is not checked: a comment on an unchanged line of a changed file is legitimate here.
    • pull_request.reply (write:pr-reply): adds one comment to an existing thread. It does not resolve, reopen or vote.

    The PAT needs "Code (Read & write)" and "Pull Request Threads (Read & write)". Reading needs only Code (Read), so a PAT that lists pull requests fine can still be refused here.

    fileUrl builds a link into the web UI, with a line range when one is given:

    file-url.ts
    import { createSafran } from "@safran/core";
    
    await using safran = await createSafran({ profile: "safran.yaml" });
    
    const host = safran.hosts.get("azure");
    const url = host?.fileUrl?.("payments-api", "src/refund/service.ts", "main", { start: 40, end: 58 });
    console.log(url);

    The method is synchronous, so it uses what is already known: the repository list when it has been loaded, or the single configured project. For an entry with several projects (or none) it returns undefined until the repositories have been listed once.

    Limits

    ConstantValueMeaning
    DEFAULT_PULL_REQUEST_LIMIT / MAX_PULL_REQUEST_LIMIT50 / 500Pull requests returned per call.
    AZURE_PULL_REQUEST_PAGE_SIZE100Pull requests asked from Azure DevOps per request.
    DEFAULT_MAX_PULL_REQUEST_PAGES20Upstream pages one call reads before returning what it has, with a cursor to continue.
    AZURE_CHANGES_PAGE_SIZE500Changed paths per request.
    AZURE_MAX_CHANGES_PAGES40Pages of changes read per pull request (20,000 paths); a larger one is cut, with a warning in the log.
    DEFAULT_ENRICH_CONCURRENCY5Parallel requests for linked work items.

    Known caveats

    This connector is implemented from Microsoft's REST documentation (version 7.1) and tested against recorded-shape fixtures; it has not been run against a live organization. See verification status. The following are marked UNVERIFIED in the source:

    • Order of the pull request list. The documentation does not state it. The connector therefore does not stop at the first pull request older than mergedSince; it skips old ones and reads on. This is correct in any order, at the cost of reading more pages on a repository with a long history.

    • Iterations. The path and response shape of the iterations list, which names the latest iteration to read changes from, were not re-checked against the documentation.

    • Line ranges in file links. The line, lineEnd and column parameters of fileUrl are web UI parameters, not part of the REST documentation. If your server ignores them, the link still opens the file.

    • Live pull requests, threads, the computed diff and writes. None of the pull request endpoints was exercised against a live organization. In the diff, the documentation's samples show the two blob ids on each change entry while its schema types the entry as a string; an entry that arrives without them cannot be diffed and is reported as withheld (truncated), never as unchanged. A thread on a whole line is sent with a column offset of 1 at both ends, which the sample does not show. The discussionId in a returned comment link is how the web UI links to a thread, not part of the REST documentation.

    See also