Help us shape the future of Go! Take the 2026 Go Developer Survey

ado

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ado is the Azure DevOps provider. It works through the az CLI and its azure-devops extension, except for the two pull request changes az cannot make (changing the target branch, and completing with a rebase), which go to the REST API directly.

Index

Constants

This section is empty.

Variables

View Source
var Info = protocol.Info{
	Name:         "ado",
	Terms:        protocol.Terms{Short: "PR", Long: "pull request", Ref: "!%d"},
	MaxBody:      4000,
	MergeMethods: []string{protocol.MethodMerge, protocol.MethodSquash, protocol.MethodRebase},
}

Info describes the Azure DevOps provider. Descriptions are limited to 4000 characters.

Functions

func ExecRunner

func ExecRunner(args ...string) ([]byte, error)

ExecRunner runs the az binary. It never installs extensions: without the azure-devops extension az fails at once, and classify says how to add it.

func Plugin

func Plugin(run Runner, rest *REST) protocol.Plugin

Plugin is the Azure DevOps provider plugin, for protocol.Serve.

Types

type Client

type Client struct {
	Run  Runner
	Repo Repository
	// REST makes the calls az cannot.
	REST *REST
}

Client makes Azure DevOps calls for one repository.

func (*Client) CreatePR

func (c *Client) CreatePR(n protocol.NewCR) (*PR, error)

CreatePR opens a pull request.

func (*Client) GetPR

func (c *Client) GetPR(id int) (*PR, error)

GetPR fetches one pull request.

func (*Client) GetRepo

func (c *Client) GetRepo() (*RepoInfo, error)

GetRepo fetches the repository.

func (*Client) ListPRs

func (c *Client) ListPRs(criteria map[string]string) ([]*PR, error)

ListPRs returns this repository's pull requests matching the search criteria (e.g. "status", "sourceRefName"), newest first. The list is project-wide (see invoke), so other repositories' PRs are dropped here.

func (*Client) Policies

func (c *Client) Policies() ([]*Policy, error)

Policies lists the project's branch policies.

func (*Client) UpdatePR

func (c *Client) UpdatePR(id int, u PRUpdate) (*PR, error)

UpdatePR changes a pull request with `az repos pr update`.

type Identity

type Identity struct {
	ID string `json:"id"`
}

Identity is a user reference.

type PR

type PR struct {
	ID                    int       `json:"pullRequestId"`
	Title                 string    `json:"title"`
	Description           string    `json:"description"`
	Status                string    `json:"status"` // active, completed, abandoned
	IsDraft               bool      `json:"isDraft"`
	SourceRefName         string    `json:"sourceRefName"`
	TargetRefName         string    `json:"targetRefName"`
	LastMergeSourceCommit *Ref      `json:"lastMergeSourceCommit"`
	AutoCompleteSetBy     *Identity `json:"autoCompleteSetBy"`
	CompletionOptions     *struct {
		DeleteSourceBranch bool `json:"deleteSourceBranch"`
	} `json:"completionOptions"`
	// MergeStatus is notSet, queued, conflicts, succeeded, rejectedByPolicy or failure.
	MergeStatus         string `json:"mergeStatus"`
	MergeFailureMessage string `json:"mergeFailureMessage"`
	// CompletionQueueTime is set once someone asked to complete the PR.
	CompletionQueueTime string          `json:"completionQueueTime"`
	ForkSource          json.RawMessage `json:"forkSource"`
	Repository          struct {
		Name string `json:"name"`
	} `json:"repository"`
}

PR is the subset of an Azure DevOps pull request that git-stack uses.

type PRUpdate

type PRUpdate struct {
	Title, Description  *string
	Draft, AutoComplete *bool
	// Status "completed" completes the PR at its current head; Squash then
	// chooses squashing.
	Status string
	Squash *bool
}

PRUpdate lists the changes `az repos pr update` can make; nil fields are left alone.

type Policy

type Policy struct {
	IsEnabled  bool `json:"isEnabled"`
	IsBlocking bool `json:"isBlocking"`
	IsDeleted  bool `json:"isDeleted"`
	Type       struct {
		ID string `json:"id"`
	} `json:"type"`
	Settings struct {
		Scope []struct {
			RepositoryID string `json:"repositoryId"`
			RefName      string `json:"refName"`
			MatchKind    string `json:"matchKind"` // exact, prefix, defaultBranch
		} `json:"scope"`
		AllowNoFastForward bool `json:"allowNoFastForward"`
		AllowSquash        bool `json:"allowSquash"`
		AllowRebase        bool `json:"allowRebase"`
		AllowRebaseMerge   bool `json:"allowRebaseMerge"`
	} `json:"settings"`
}

Policy is a branch policy configuration.

type Provider

type Provider struct {
	C *Client
}

Provider adapts Client to protocol.Provider.

func (*Provider) CancelAutoMerge

func (p *Provider) CancelAutoMerge(n int) error

CancelAutoMerge turns auto-complete off.

func (*Provider) CreateCR

func (p *Provider) CreateCR(n protocol.NewCR) (*protocol.CR, error)

CreateCR opens a pull request.

func (*Provider) FindCRForBranch

func (p *Provider) FindCRForBranch(branch string) (*protocol.CR, error)

FindCRForBranch returns the active PR whose source is branch, else the most recently completed one, else nil. PRs from forks are ignored.

func (*Provider) GetBranch

func (p *Provider) GetBranch(name string) (*protocol.Branch, error)

GetBranch reports whether name is the default branch, and whether a blocking branch policy applies to it.

func (*Provider) GetCR

func (p *Provider) GetCR(n int) (*protocol.CR, error)

GetCR fetches a pull request.

func (*Provider) GetRepo

func (p *Provider) GetRepo() (*protocol.RepoSettings, error)

GetRepo returns the default branch's preferred merge method: the first strategy its "Require a merge strategy" policy allows, else merge.

func (*Provider) ListCRsTargeting

func (p *Provider) ListCRsTargeting(branch string) ([]*protocol.CR, error)

ListCRsTargeting returns active PRs, not from forks, whose target is branch.

func (*Provider) MarkReady

func (p *Provider) MarkReady(n int) (*protocol.CR, error)

MarkReady takes a pull request out of draft.

func (*Provider) Merge

func (p *Provider) Merge(n int, method, sha string) (*protocol.CR, error)

Merge completes the pull request, if its source branch is still at sha. When Azure DevOps refuses (required reviewers, builds or other policies), it sets the PR to auto-complete instead, so it completes once the policies pass. az completes with a merge commit or a squash; a rebase goes to the REST API.

func (*Provider) SearchCRs

func (p *Provider) SearchCRs(text string) ([]*protocol.CR, error)

SearchCRs returns active PRs whose description contains text. Azure DevOps cannot search descriptions, and lists cut them short, so long ones are fetched in full.

func (*Provider) SyncStack

func (p *Provider) SyncStack([]int) error

SyncStack is a no-op: Azure DevOps has no stack object; the description block is the stack.

func (*Provider) ToCR

func (p *Provider) ToCR(pr *PR) *protocol.CR

ToCR converts an Azure DevOps pull request.

func (*Provider) Unstack

func (p *Provider) Unstack([]int) error

Unstack is a no-op, like SyncStack.

func (*Provider) UpdateCR

func (p *Provider) UpdateCR(n int, u protocol.Update) (*protocol.CR, error)

UpdateCR changes the target branch, title or description. az cannot change the target branch, so that goes to the REST API.

type REST

type REST struct {
	HTTP *http.Client
	// Auth returns the Authorization header value.
	Auth func() (string, error)
}

REST calls the Azure DevOps REST API for what az cannot do.

func NewREST

func NewREST(getenv func(string) string, run Runner) *REST

NewREST authenticates with $AZURE_DEVOPS_EXT_PAT if set, else with an access token for the az login.

func (*REST) PatchPR

func (r *REST) PatchPR(repo Repository, id int, body, out any) error

PatchPR changes a pull request.

type Ref

type Ref struct {
	CommitID string `json:"commitId"`
}

Ref is a commit reference.

type RepoInfo

type RepoInfo struct {
	ID            string `json:"id"`
	DefaultBranch string `json:"defaultBranch"`
}

RepoInfo is the subset of a repository that git-stack uses.

type Repository

type Repository struct {
	OrgURL, Project, Name string
}

Repository locates a repository: the organization (or collection) URL, the project and the repository name.

func ParseRepo

func ParseRepo(r protocol.Repo) (Repository, error)

ParseRepo finds the repository of a git-stack Repo, whose path has the form <collection...>/<project>/_git/<repo>.

func (Repository) WebURL

func (r Repository) WebURL() string

WebURL is the repository's web page.

type Runner

type Runner func(args ...string) ([]byte, error)

Runner executes az with args and returns stdout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL