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, and it is read-only.

    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.

    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.

    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.

    See also