gitprovider

package
v0.3.103-beta Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// TopicPROpened is published when a pull request is opened.
	TopicPROpened = "git.pr_opened"
	// TopicPRReviewSubmitted is published when a review is submitted (approved/changes_requested/commented/dismissed).
	TopicPRReviewSubmitted = "git.pr_review_submitted"
	// TopicPRMerged is published when a pull request is merged.
	TopicPRMerged = "git.pr_merged"
	// TopicPRClosed is published when a pull request is closed without merging.
	TopicPRClosed = "git.pr_closed"
	// TopicPush covers a push to an existing branch, both exact and wildcard rules; not a delete (see TopicBranchDeleted).
	TopicPush = "git.push"
	// TopicBranchDeleted is published when a branch is deleted, the one unambiguous teardown signal.
	TopicBranchDeleted = "git.branch_deleted"
	// TopicPRCommentCreated is published for both a general conversation comment and an inline review comment on the diff.
	TopicPRCommentCreated = "git.pr_comment"
	// TopicIssue is published for an issue opened, edited, closed, reopened, labeled, assigned, deleted or transferred; never a pull request.
	TopicIssue = "git.issue"
	// TopicIssueComment is published for a comment created, edited or deleted on an issue; a pull request's stays git.pr_comment.
	TopicIssueComment = "git.issue_comment"
)
View Source
const (
	// TopicProviderEvent is published for every accepted delivery as one provider-agnostic envelope, all types.
	TopicProviderEvent = "git.provider_event"
)

Variables

This section is empty.

Functions

func HandlePROpened

func HandlePROpened(ctx context.Context, linker TicketLinker, ev eventbus.Event) error

HandlePROpened links the PR to every ticket it references.

func MCPTools

func MCPTools(p GitProvider, cc ChangeContextReader, g Gate) []mcptool.Tool

MCPTools returns the pull request tools; cc answers which tickets, docs, and decisions a pull request carries.

func TicketKeys

func TicketKeys(title, body, branch string) []string

TicketKeys returns the ticket keys a PR names in its title, after a closing word in its body, and in its head branch, uppercased, in order, once each.

func Topics

func Topics() []eventbus.Topic

Topics returns every topic gitprovider publishes; TopicProviderEvent is declared in envelope.go but lives here.

Types

type BranchDeletedEvent

type BranchDeletedEvent struct {
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
	Branch string `json:"branch"`
}

BranchDeletedEvent is the payload for git.branch_deleted.

type ChangeBug

type ChangeBug struct {
	ID    string `json:"id"`
	Key   string `json:"key"`
	Title string `json:"title"`
	Done  bool   `json:"done"`
}

ChangeBug is a bug found after the ticket was done, linked to it by found-in (ADR 0064).

type ChangeContext

type ChangeContext struct {
	Owner     string         `json:"owner"`
	Repo      string         `json:"repo"`
	PR        *PR            `json:"pr"`
	Tickets   []ChangeTicket `json:"tickets"`
	Decisions []string       `json:"decisions"`
}

ChangeContext answers "why does this code exist": the PR, its tickets, and the decisions-log entries citing them.

func GetChangeContext

func GetChangeContext(ctx context.Context, g Gate, p GitProvider, r ChangeContextReader, ref ChangeRef) (*ChangeContext, error)

GetChangeContext walks a change back to its why: PR, tickets, their docs and later bugs, and the decisions citing them.

type ChangeContextReader

type ChangeContextReader interface {
	TicketsForPR(ctx context.Context, owner, repo string, number int) ([]ChangeTicket, error)
	// DecisionEntries returns the project's decisions-log entries naming any of refs.
	DecisionEntries(ctx context.Context, projectID string, refs []string) ([]string, error)
}

ChangeContextReader is the change context's seam onto tickets, docs, and memories (ADR 0017).

type ChangeDoc

type ChangeDoc struct {
	ID    string `json:"id"`
	Title string `json:"title"`
}

ChangeDoc is the doc a changed ticket came from.

type ChangeRef

type ChangeRef struct {
	Owner  string
	Repo   string
	Number int
	Commit string
}

ChangeRef names the change to explain: a PR number, or a commit SHA resolved to the PR that contains it.

type ChangeTicket

type ChangeTicket struct {
	ID        string      `json:"id"`
	Key       string      `json:"key"`
	Title     string      `json:"title"`
	ProjectID string      `json:"project_id"`
	Done      bool        `json:"done"`
	Doc       *ChangeDoc  `json:"doc"`
	BugsFound []ChangeBug `json:"bugs_found"`
}

ChangeTicket is one ticket a pull request is linked to, with the doc it came from and the bugs found after it.

type CommentRef

type CommentRef struct {
	Body   string `json:"body"`
	Author string `json:"author"`
}

CommentRef is the comment body and author, shared by both general and inline review comments.

type Gate

type Gate interface {
	RequireRepo(ctx context.Context, owner, name string, action permissions.Action) error
}

Gate is the permission check a repository's pull requests pass: the caller needs the action in the workspace of the project the repository belongs to (ADR 0087).

type GitProvider

type GitProvider interface {
	GetRepo(ctx context.Context, owner, name string) (*Repo, error)
	ListPRs(ctx context.Context, owner, name string, opts PROpts) ([]*PR, error)
	GetPR(ctx context.Context, owner, name string, number int) (*PR, error)
	// PRsForCommit lists the pull requests with a commit: the merged one that introduced it, else the open ones carrying it.
	PRsForCommit(ctx context.Context, owner, name, sha string) ([]*PR, error)
	// MergedInto reports whether merged pull request number's merge commit is sha or one of sha's ancestors.
	MergedInto(ctx context.Context, owner, name string, number int, sha string) (bool, error)
	CreateWebhook(ctx context.Context, owner, name string, cfg WebhookConfig) (string, error)
	ListWebhooks(ctx context.Context, owner, name string) ([]Webhook, error)
	// UpdateWebhook sets the hook's events to the ones the receiver dispatches, what a Stale hook lacks.
	UpdateWebhook(ctx context.Context, owner, name, hookID string) error
	DeleteWebhook(ctx context.Context, owner, name, hookID string) error
	// GetTree returns the recursive git tree at ref; an empty ref resolves to the repo's default branch.
	GetTree(ctx context.Context, owner, name, ref string) ([]TreeEntry, error)
	// GetFile returns a file's decoded content at ref; an empty ref resolves to the repo's default branch.
	GetFile(ctx context.Context, owner, name, ref, path string) ([]byte, error)
	// ListIssues returns one page of issues, pull requests left out, and the next page number, 0 after the last.
	ListIssues(ctx context.Context, owner, name string, opts IssueOpts) ([]*Issue, int, error)
	GetIssue(ctx context.Context, owner, name string, number int) (*Issue, error)
	CreateIssue(ctx context.Context, owner, name string, in IssueInput) (*Issue, error)
	UpdateIssue(ctx context.Context, owner, name string, number int, patch IssuePatch) (*Issue, error)
	// ListIssueComments returns every comment on issue number updated at or after since; a zero since returns them all.
	ListIssueComments(ctx context.Context, owner, name string, number int, since time.Time) ([]*IssueComment, error)
	CreateIssueComment(ctx context.Context, owner, name string, number int, body string) (*IssueComment, error)
	UpdateIssueComment(ctx context.Context, owner, name string, commentID int64, body string) (*IssueComment, error)
	DeleteIssueComment(ctx context.Context, owner, name string, commentID int64) error
}

GitProvider is the seam to a git host; GitLab/Gitea add a package satisfying this interface.

type Handler

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

Handler adapts the gitprovider use-cases to the HTTP/JSON gateway (ADR 0019); the browser never talks to MCP directly.

func NewHandler

func NewHandler(p GitProvider, g Gate) *Handler

NewHandler wires the gitprovider REST gateway over the given provider.

func (*Handler) Routes

func (h *Handler) Routes() http.Handler

Routes returns the gitprovider REST endpoints.

func (*Handler) WithChangeContext

func (h *Handler) WithChangeContext(cc ChangeContextReader) *Handler

WithChangeContext adds the change-context route, which walks a PR or commit back to its tickets and decisions.

type Installation

type Installation struct {
	ID int64
	// AccountID is the git host's numeric id of the account, which survives a rename.
	AccountID    int64
	AccountLogin string
	// AccountType is "user" or "organization".
	AccountType      string
	AccountAvatarURL string
	// RepositorySelection is "all" or "selected".
	RepositorySelection string
	// RepositoryCount is set only for a "selected" installation; "all" follows the account's repositories.
	RepositoryCount *int
	// HTMLURL is the installation's settings page on the git host.
	HTMLURL string
	// Problem says why the git host refused to read this installation; the others read on.
	Problem string
	// MissingPermissions names what the App asks for that this installation has not accepted, such as "issues".
	MissingPermissions []string
}

Installation is one account or organisation the git host's App is installed on, as the connected user sees it.

type Issue

type Issue struct {
	ID          int64     `json:"id"`
	Number      int       `json:"number"`
	Title       string    `json:"title"`
	Body        string    `json:"body"`
	State       string    `json:"state" enum:"open,closed"`
	StateReason string    `` /* 141-byte string literal not displayed */
	Labels      []string  `json:"labels" jsonschema:"Label names."`
	Assignees   []string  `json:"assignees" jsonschema:"Assignee logins."`
	Author      string    `json:"author"`
	HTMLURL     string    `json:"html_url"`
	UpdatedAt   time.Time `json:"updated_at"`
	Comments    int       `json:"comments" jsonschema:"How many comments the issue has."`
}

Issue is a provider-neutral issue, never a pull request; it is also the git.issue payload's issue.

func IssueFromGitHub

func IssueFromGitHub(i *githubapi.Issue) Issue

IssueFromGitHub converts GitHub's issue; its lists are never nil, so the payload always carries [].

type IssueComment

type IssueComment struct {
	ID              int64     `json:"id"`
	Body            string    `json:"body"`
	Author          string    `json:"author"`
	AuthorAvatarURL string    `json:"author_avatar_url"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

IssueComment is a comment on an issue; it is also the git.issue_comment payload's comment.

func IssueCommentFromGitHub

func IssueCommentFromGitHub(c *githubapi.IssueComment) IssueComment

IssueCommentFromGitHub converts GitHub's issue comment.

type IssueCommentEvent

type IssueCommentEvent struct {
	Owner       string       `json:"owner"`
	Repo        string       `json:"repo"`
	IssueNumber int          `json:"issue_number"`
	Action      string       `json:"action" enum:"created,edited,deleted"`
	Comment     IssueComment `json:"comment"`
	Sender      Sender       `json:"sender"`
}

IssueCommentEvent is the git.issue_comment payload.

type IssueEvent

type IssueEvent struct {
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
	Action string `json:"action" enum:"opened,edited,closed,reopened,labeled,unlabeled,assigned,unassigned,deleted,transferred"`
	Issue  Issue  `json:"issue"`
	Sender Sender `json:"sender"`
}

IssueEvent is the git.issue payload.

type IssueInput

type IssueInput struct {
	Title     string
	Body      string
	Labels    []string
	Assignees []string
}

IssueInput is a new issue.

type IssueOpts

type IssueOpts struct {
	// State is open, closed or all; empty reads open issues.
	State  string
	Labels []string
	// Since keeps only issues updated at or after it; zero keeps all.
	Since time.Time
	Page  int
}

IssueOpts filters ListIssues; Page starts at 1, and 0 reads the first page.

type IssuePatch

type IssuePatch struct {
	Title       *string
	Body        *string
	State       *string
	StateReason *string
	Labels      *[]string
	Assignees   *[]string
}

IssuePatch changes an issue; a nil field keeps its value, and an empty list clears labels or assignees.

type PR

type PR struct {
	Number          int      `json:"number"`
	Title           string   `json:"title"`
	Body            string   `json:"body"`
	State           PRState  `json:"state"`
	Merged          bool     `json:"merged"`
	HeadSHA         string   `json:"head_sha"`
	BaseBranch      string   `json:"base_branch"`
	Author          string   `json:"author"`
	LinkedTicketIDs []string `json:"linked_ticket_ids"`
}

PR is a provider-neutral pull request.

func GetPR

func GetPR(ctx context.Context, g Gate, p GitProvider, owner, name string, number int) (*PR, error)

GetPR fetches a single pull request, validating caller input first.

func ListPRs

func ListPRs(ctx context.Context, g Gate, p GitProvider, owner, name string, opts PROpts) ([]*PR, error)

ListPRs lists pull requests for a repository, validating caller input first (ADR 0019: one use-case per capability, shared by the HTTP and MCP adapters).

type PRCommentEvent

type PRCommentEvent struct {
	Owner   string       `json:"owner"`
	Repo    string       `json:"repo"`
	PR      PRCommentRef `json:"pr"`
	Comment CommentRef   `json:"comment"`
}

PRCommentEvent is the payload for git.pr_comment.

type PRCommentRef

type PRCommentRef struct {
	Number int `json:"number"`
}

PRCommentRef identifies the commented-on pull request.

type PREvent

type PREvent struct {
	Owner string `json:"owner"`
	Repo  string `json:"repo"`
	PR    PR     `json:"pr"`
}

PREvent is the payload for git.pr_opened/pr_merged/pr_closed; fields are part of the contract, additive-only.

type PROpts

type PROpts struct {
	State string
	Limit int
}

PROpts filters ListPRs results.

type PRRef

type PRRef struct {
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	SHA    string `json:"sha"`
}

PRRef identifies a pull request for ticket linking.

type PRState

type PRState string

PRState is the lifecycle state of a pull request.

const (
	PRStateOpen   PRState = "open"
	PRStateClosed PRState = "closed"
)

type ProviderEvent

type ProviderEvent struct {
	Provider   string          `json:"provider"`
	EventType  string          `json:"event_type"`
	DeliveryID string          `json:"delivery_id"`
	Action     string          `json:"action,omitempty"`
	Repository *RepositoryRef  `json:"repository,omitempty"`
	Payload    json.RawMessage `json:"payload" type:"object"`
	ReceivedAt time.Time       `json:"received_at"`
}

ProviderEvent is the envelope on TopicProviderEvent, additive-only; Payload carries the provider's typed JSON.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, topic string, payload any) error
}

Publisher is the fan-out slice of the event bus (ADR 0019), for git events that skip the outbox.

type PushEvent

type PushEvent struct {
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
	Branch string `json:"branch"`
	SHA    string `json:"sha"`
	Pusher string `json:"pusher,omitempty"`
}

PushEvent is the git.push payload; SHA is the branch's new HEAD, the ref a branch deployment builds from.

type Rate

type Rate struct {
	Remaining int
	Reset     time.Time
}

Rate is what is left of a token's core rate limit, and when it resets.

type RateReader

type RateReader interface {
	RateLimit(ctx context.Context) (Rate, error)
}

RateReader is a GitProvider that can say how much of its rate limit is left, which reading costs none of it.

type Recorder

type Recorder interface {
	Record(ctx context.Context, receipt string, ev eventbus.OutboxEvent) error
}

Recorder writes an event to the outbox, which the relay fans out and automations read; a receipt it holds writes nothing.

type Repo

type Repo struct {
	ID            int64  `json:"id"`
	Owner         string `json:"owner"`
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	DefaultBranch string `json:"default_branch"`
	HTMLURL       string `json:"html_url"`
	// AccountID is the id of the account whose installation listed the repository, set by installation reads.
	AccountID int64 `json:"-"`
}

Repo is a git repository as seen through a provider.

func GetRepo

func GetRepo(ctx context.Context, g Gate, p GitProvider, owner, name string) (*Repo, error)

GetRepo fetches a repository, validating caller input first.

type RepositoryRef

type RepositoryRef struct {
	ID            int64  `json:"id"`
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	Owner         string `json:"owner"`
	HTMLURL       string `json:"html_url"`
	DefaultBranch string `json:"default_branch"`
}

RepositoryRef identifies the repository a delivery concerns, shaped for future providers to map onto.

type ReviewRef

type ReviewRef struct {
	Number   int    `json:"number"`
	State    string `json:"state"`
	Reviewer string `json:"reviewer"`
}

ReviewRef identifies the pull request and the review outcome.

type ReviewSubmittedEvent

type ReviewSubmittedEvent struct {
	Owner string    `json:"owner"`
	Repo  string    `json:"repo"`
	PR    ReviewRef `json:"pr"`
}

ReviewSubmittedEvent is the git.pr_review_submitted payload: one review outcome (State: approved/etc).

type Sender

type Sender struct {
	Login string `json:"login"`
	Type  string `json:"type" jsonschema:"The account type, such as User, Bot or Organization."`
}

Sender is who caused a delivery; Type is the host's account type, such as User or Bot.

type TicketLinker

type TicketLinker interface {
	LinkPR(ctx context.Context, ticketID string, ref PRRef) error
}

TicketLinker lets gitprovider declare LinkPR without importing tickets, which implements it.

type TicketResolver

type TicketResolver interface {
	TicketIDs(ctx context.Context, owner, repo string, keys []string) ([]string, error)
}

TicketResolver turns the keys a repository's PR names into ticket ids, dropping keys that name no ticket.

type TreeEntry

type TreeEntry struct {
	Path string
	Type string
}

TreeEntry is one entry of a recursive git tree: a file (blob), directory (tree), or submodule (commit).

type Webhook

type Webhook struct {
	ID  string
	URL string
	// Stale is true when the hook's events differ from the ones the receiver dispatches; UpdateWebhook fixes them.
	Stale bool
}

Webhook is a webhook already registered on a repository.

type WebhookConfig

type WebhookConfig struct {
	URL    string
	Secret string
}

WebhookConfig describes a repository webhook to create.

type WebhookHandler

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

WebhookHandler validates GitHub signatures and records a normalized envelope, plus typed git.* topics, in the outbox.

func NewWebhookHandler

func NewWebhookHandler(secret string, events Recorder) *WebhookHandler

NewWebhookHandler wires a webhook receiver; an empty secret skips signature checks (dev only) and logs a warning.

func (*WebhookHandler) ServeHTTP

func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WebhookHandler) WithTicketResolver

func (h *WebhookHandler) WithTicketResolver(r TicketResolver) *WebhookHandler

WithTicketResolver links each PR event to the tickets its keys name; without one, a PR event links none.

Directories

Path Synopsis
Package github implements gitprovider.GitProvider against GitHub via go-github.
Package github implements gitprovider.GitProvider against GitHub via go-github.

Jump to

Keyboard shortcuts

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