ghfake

package
v0.0.0-...-c98162d Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

It is not a faithful simulator: only the endpoints gitea-mq calls are implemented, with just enough state to drive the adapter and integration tests deterministically without network access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckRun

type CheckRun struct {
	ID         int64
	Name       string
	HeadSHA    string
	Status     string
	Conclusion string
	DetailsURL string
	Output     struct{ Title, Summary string }
}

type HookConfig

type HookConfig struct {
	URL         string `json:"url,omitempty"`
	Secret      string `json:"secret,omitempty"`
	ContentType string `json:"content_type,omitempty"`
}

HookConfig mirrors the App-level webhook config (PATCH /app/hook/config).

type Installation

type Installation struct {
	ID    int64
	Repos []string // owner/name
}

type PR

type PR struct {
	Number    int64
	Title     string
	State     string // open, closed
	Merged    bool
	User      string
	HeadRef   string
	HeadSHA   string
	BaseRef   string
	NodeID    string
	AutoMerge bool
	HTMLURL   string
	Labels    []string
}

type Repo

type Repo struct {
	Owner, Name   string
	DefaultBranch string

	PRs  map[int64]*PR
	Refs map[string]string // branch -> sha
	// Parents[sha] lists a commit's parent SHAs. hMerge records the merge
	// commit's parents here so hUpdateRef can do a real ancestry walk for
	// its fast-forward check.
	Parents   map[string][]string
	CheckRuns map[string][]*CheckRun
	Rulesets  []*Ruleset
	// BehindBy["base...head"] feeds GET /compare/{base}...{head}.behind_by.
	// Missing entries default to 0 (head up to date with base).
	BehindBy map[string]int
	// ConflictOn[head] makes POST /merges with that head return 409.
	ConflictOn map[string]bool
	// Settings tracks PATCH /repos/{o}/{r} keys.
	Settings map[string]any

	// ProtectedRefs[branch]=true makes a non-force PATCH on that ref return
	// 403, simulating a ruleset/branch-protection rejection.
	ProtectedRefs map[string]bool

	// RequiredChecks[branch] feeds /rules/branches/{b} as a synthetic
	// required_status_checks rule, decoupled from Rulesets so tests can
	// stub rule evaluation directly.
	RequiredChecks map[string][]string

	// ProtectionChecks[branch] feeds classic branch protection; absent
	// branches answer 404 like unprotected ones.
	ProtectionChecks map[string][]string

	// Stacks feeds GET /stacks; nil answers 404 (feature disabled).
	Stacks []Stack
	// AsyncMerges records PUT /pulls/{n}/merge-async calls.
	AsyncMerges []int64
	// AsyncMergeStatus is the reported status (default "pending").
	AsyncMergeStatus string
	// AsyncMergeConflict makes merge-async return 409.
	AsyncMergeConflict bool
}

type Ruleset

type Ruleset struct {
	ID          int64           `json:"id"`
	Name        string          `json:"name"`
	Target      string          `json:"target"`
	Enforcement string          `json:"enforcement"`
	Conditions  json.RawMessage `json:"conditions,omitempty"`
	Rules       []RulesetRule   `json:"rules"`
}

type RulesetRule

type RulesetRule struct {
	Type       string          `json:"type"`
	Parameters json.RawMessage `json:"parameters,omitempty"`
}

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

func New

func New() *Server

func (*Server) AddInstallation

func (s *Server) AddInstallation(id int64, fullNames ...string) *Installation

func (*Server) AddPR

func (s *Server) AddPR(owner, name string, pr PR) *PR

func (*Server) AddRepo

func (s *Server) AddRepo(owner, name string) *Repo

func (*Server) Client

func (s *Server) Client() *gh.Client

func (*Server) HookConfig

func (s *Server) HookConfig() HookConfig

func (*Server) Repo

func (s *Server) Repo(owner, name string) *Repo

type Stack

type Stack struct {
	BaseRef string
	PRs     []int64 // bottom→top, resolved against Repo.PRs
}

Jump to

Keyboard shortcuts

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