githubtestrepo

package
v0.3.0-20261008172002-... Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package githubtestrepo gives tests real pull requests on github.com to land.

The GitHub merger and the GitHub change provider talk to GitHub's REST API, and only real pull requests show what that API actually does — an in-process fake encodes only our reading of the docs. The suites that verify them (the merger extension test and TestGitHubLandE2E) share this package to open branches and pull requests, link them into stacks, push a new head, read back whether GitHub merged them and with which commit, and remove what they opened.

New skips the calling test unless SQ_GITHUB_TOKEN and SQ_GITHUB_TEST_REPO ("owner/repo") are set, so runs without the credential never touch GitHub. Where the credential is expected — SQ_GITHUB_TEST_REQUIRED=true, which CI sets on every run that can read its secrets — a missing one fails the test instead, so a deleted secret cannot quietly turn these suites into skips. A token GitHub rejects (expired or revoked) always fails. Fixtures are named under sq-it/<run id>/ and closed and deleted when the test ends; what a test merges stays on the repository's default branch.

Index

Constants

View Source
const (
	// TokenEnv names the variable holding a token with write access to the
	// test repository.
	TokenEnv = "SQ_GITHUB_TOKEN"
	// RepoEnv names the variable holding the test repository, "owner/repo".
	RepoEnv = "SQ_GITHUB_TEST_REPO"
	// RequiredEnv names the variable that, when "true", makes a missing
	// TokenEnv or RepoEnv fail the test rather than skip it.
	RequiredEnv = "SQ_GITHUB_TEST_REQUIRED"

	// Host is the GitHub instance the test repository's change URIs name.
	Host = "github.com"
	// APIBaseURL is the REST API root for Host.
	APIBaseURL = "https://api.github.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Pull

type Pull struct {
	// Number is the pull request number.
	Number int
	// Branch is the pull request's head branch.
	Branch string
	// Head is the head commit the pull request was opened at.
	Head string
}

Pull is a fixture pull request.

type PullState

type PullState struct {
	// State is "open" or "closed".
	State string `json:"state"`
	// Merged reports whether the pull request was merged.
	Merged bool `json:"merged"`
}

PullState is what GitHub reports about a fixture pull request.

type TestRepo

type TestRepo struct {
	// contains filtered or unexported fields
}

TestRepo creates fixtures in the test repository and removes them when the test ends.

func New

func New(t testing.TB) *TestRepo

New returns a TestRepo for the configured repository. When the credential or repository is not configured it skips the test, or fails it if RequiredEnv is "true".

func (*TestRepo) AwaitPullHead

func (r *TestRepo) AwaitPullHead(number int, head string)

AwaitPullHead waits until GitHub reports head as the pull request's head. A push reaches the pull request asynchronously, so a staleness check run before that would compare against the old head. Bounded by the test runner's timeout.

func (*TestRepo) CommitFile

func (r *TestRepo) CommitFile(branch, path, content string) string

CommitFile writes a file on branch and returns the new head commit.

func (*TestRepo) FileOnTrunk

func (r *TestRepo) FileOnTrunk(path string) bool

FileOnTrunk reports whether path exists on the trunk.

func (*TestRepo) FilePath

func (r *TestRepo) FilePath(name string) string

FilePath is the path of the file a fixture named name adds.

func (*TestRepo) HTTPClient

func (r *TestRepo) HTTPClient() *http.Client

HTTPClient is an authenticated client rooted at APIBaseURL.

func (*TestRepo) MergeCommit

func (r *TestRepo) MergeCommit(number int) string

MergeCommit is the commit GitHub's merged event records for a pull request, or "" when it has none.

func (*TestRepo) OpenChain

func (r *TestRepo) OpenChain(name string, n int) []Pull

OpenChain opens n pull requests stacked by base branch without creating a GitHub stack.

func (*TestRepo) OpenPull

func (r *TestRepo) OpenPull(name, base string) Pull

OpenPull opens one pull request against base that adds a file unique to it.

func (*TestRepo) OpenStack

func (r *TestRepo) OpenStack(name string, n int) []Pull

OpenStack opens n pull requests, each adding its own file, the first based on the trunk and each later one on the branch below it, and links them into a GitHub stack.

func (*TestRepo) Owner

func (r *TestRepo) Owner() string

Owner is the test repository's owner.

func (*TestRepo) PullState

func (r *TestRepo) PullState(number int) PullState

PullState reads a pull request's current state.

func (*TestRepo) Repo

func (r *TestRepo) Repo() string

Repo is the test repository's name.

func (*TestRepo) RunID

func (r *TestRepo) RunID() string

RunID uniquely names this test run's fixtures.

func (*TestRepo) Token

func (r *TestRepo) Token() string

Token is the credential the test repository is reached with.

func (*TestRepo) Trunk

func (r *TestRepo) Trunk() string

Trunk is the test repository's default branch.

func (*TestRepo) URI

func (r *TestRepo) URI(p Pull) string

URI is the change URI naming p at the head it was opened with.

func (*TestRepo) URIs

func (r *TestRepo) URIs(pulls ...Pull) []string

URIs is URI for each pull request, in order.

Jump to

Keyboard shortcuts

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