githubclient

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL is the GitHub API base URL
	DefaultBaseURL = "https://api.github.com"

	// UserAgent identifies AurumCode
	UserAgent = "AurumCode/1.0"

	// MaxRetries is the maximum number of retry attempts
	MaxRetries = 3

	// InitialBackoff is the initial backoff duration
	InitialBackoff = 1 * time.Second
)

Variables

View Source
var ErrNoWritePermission = errors.New("token lacks write permission on repository")

ErrNoWritePermission is returned by the publishing methods (PostIssueComment, PostReviewComment, SetStatus) when the authenticated token does not carry write permission on the target repository. The client refuses before any POST leaves the process.

Functions

This section is empty.

Types

type Client

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

Client is a GitHub API client with retry and rate-limit handling

func NewClient

func NewClient(token string) *Client

NewClient creates a new GitHub API client

func NewClientWithBaseURL

func NewClientWithBaseURL(token, baseURL string) *Client

NewClientWithBaseURL creates a client with a custom base URL (for testing)

func (*Client) GetPullRequestDiff

func (c *Client) GetPullRequestDiff(ctx context.Context, owner, repo string, number int) (*Diff, error)

GetPullRequestDiff retrieves the diff for a pull request with ETag caching

func (*Client) HasWritePermission

func (c *Client) HasWritePermission(ctx context.Context, owner, repo string) (bool, error)

HasWritePermission reports whether the authenticated token can write to owner/repo, from the "permissions" object of GET /repos/{owner}/{repo}. A repository answer without a permissions object counts as no write permission: the check fails closed. Verdicts are cached per owner/repo for the lifetime of the client.

func (*Client) ListChangedFiles

func (c *Client) ListChangedFiles(ctx context.Context, owner, repo string, number int) ([]string, error)

ListChangedFiles retrieves the list of changed files in a pull request with pagination

func (*Client) PostIssueComment

func (c *Client) PostIssueComment(ctx context.Context, owner, repo string, number int, body string) error

PostIssueComment posts a general comment on a pull request (not tied to a specific line). It refuses with ErrNoWritePermission when the token cannot write to the repository.

func (*Client) PostReviewComment

func (c *Client) PostReviewComment(ctx context.Context, owner, repo string, number int, comment ReviewComment, idempotencyKey string) error

PostReviewComment posts a review comment on a pull request with idempotency. It refuses with ErrNoWritePermission when the token cannot write to the repository.

func (*Client) SetStatus

func (c *Client) SetStatus(ctx context.Context, owner, repo, sha string, status CommitStatus) error

SetStatus sets the commit status for a specific SHA

type CommitStatus

type CommitStatus struct {
	State       string `json:"state"`                 // "pending", "success", "error", or "failure"
	TargetURL   string `json:"target_url,omitempty"`  // Optional URL
	Description string `json:"description,omitempty"` // Short description
	Context     string `json:"context"`               // Label to differentiate this status
}

CommitStatus represents a commit status update

type Diff

type Diff struct {
	Files []DiffFile `json:"files" yaml:"files"`
}

Diff represents the complete parsed diff

type DiffFile

type DiffFile struct {
	Path  string     `json:"path" yaml:"path"`
	Lang  string     `json:"lang" yaml:"lang"`
	Hunks []DiffHunk `json:"hunks" yaml:"hunks"`
}

DiffFile represents a single file in a diff

type DiffHunk

type DiffHunk struct {
	OldStart int      `json:"old_start" yaml:"old_start"`
	OldLines int      `json:"old_lines" yaml:"old_lines"`
	NewStart int      `json:"new_start" yaml:"new_start"`
	NewLines int      `json:"new_lines" yaml:"new_lines"`
	Lines    []string `json:"lines" yaml:"lines"`
}

DiffHunk represents a single hunk within a file diff

type ReviewComment

type ReviewComment struct {
	Body     string `json:"body"`
	CommitID string `json:"commit_id"`
	Path     string `json:"path"`
	Line     int    `json:"line,omitempty"`     // For single-line comments
	Position int    `json:"position,omitempty"` // Alternative to Line (deprecated by GitHub)
}

ReviewComment represents a review comment to be posted

Jump to

Keyboard shortcuts

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