github

package
v0.0.0-...-c35f4d5 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package github implements the scm.PRTarget port by delivering a remediation as a real GitHub pull request. Each Deliver call branches off the configured base branch, writes change.Patch as the FULL file body via the Contents API, and opens a PR from the new branch into the base branch.

The adapter treats change.Patch as the complete file body (per the port's "full file body" contract for this target), not a unified diff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Owner is the repository owner (user or org).
	Owner string
	// Repo is the repository name.
	Repo string
	// BaseBranch is the branch PRs target and branch from; defaults to "main".
	BaseBranch string
	// Token is the GitHub access token used for authentication.
	Token string
	// BaseURL overrides the GitHub API base URL (e.g. an httptest server in
	// tests, or a GitHub Enterprise host). Empty means public github.com.
	BaseURL string
	// HTTPClient overrides the transport used to reach GitHub. When nil, an
	// oauth2 client carrying Token is used.
	HTTPClient *http.Client
}

Config configures a GitHubTarget. Token is never logged.

type GitHubTarget

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

GitHubTarget delivers a Change as a GitHub pull request. It implements scm.PRTarget. Construct with New or NewWithClient.

func New

func New(cfg Config) (*GitHubTarget, error)

New builds a GitHubTarget from cfg, constructing a *github.Client wired with the configured token and (optional) base URL. The token is held only inside the HTTP transport and is never logged.

func NewWithClient

func NewWithClient(client *gh.Client, owner, repo, baseBranch string) *GitHubTarget

NewWithClient builds a GitHubTarget from an already-constructed *github.Client. This is the test seam: callers point the client at an httptest.Server. An empty baseBranch defaults to "main".

func (*GitHubTarget) Deliver

func (t *GitHubTarget) Deliver(ctx context.Context, change scm.Change) (scm.Ref, error)

Deliver opens a pull request carrying change.Patch as the full body of change.FilePath:

  1. read the base branch ref to find its commit SHA;
  2. create a new branch ref off that SHA (tolerating an already-exists branch);
  3. create-or-update change.FilePath via the Contents API with the full body;
  4. open a PR from the new branch into the base branch.

It returns scm.Ref{ID: PR number, URL: PR html_url}.

func (*GitHubTarget) Name

func (t *GitHubTarget) Name() string

Name identifies the adapter.

Jump to

Keyboard shortcuts

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