github

package
v0.0.0-...-c660401 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package github provides GitHub API integration for maestro.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPullRequestChangesWithMCP

func GetPullRequestChangesWithMCP(ctx context.Context, owner, repo string, prNumber int, bashHelper *MCPBashHelper, localRepoPath string) (*types.PRChanges, error)

GetPullRequestChangesWithMCP retrieves PR changes using MCP bash helper instead of GitHub API. It explicitly scopes gh commands to the provided owner/repo to avoid cwd-dependent behavior. localRepoPath is the path to the cloned repo on disk for reading file contents.

func Indent

func Indent(s string, spaces int) string

Indent adds indentation to each line of a string.

func ParseHunks

func ParseHunks(patch string, filePath string) ([]types.ChangeHunk, error)

ParseHunks parses diff hunks from a patch.

func ShouldSkipFile

func ShouldSkipFile(filename string) bool

ShouldSkipFile determines if a file should be skipped for review.

func VerifyTokenPermissions

func VerifyTokenPermissions(ctx context.Context, token, owner, repo string) error

VerifyTokenPermissions verifies the GitHub token has required permissions.

Types

type CodeContext

type CodeContext struct {
	StartLine int
	Lines     []string
}

CodeContext represents lines of code around a specific line.

func ExtractContext

func ExtractContext(content string, line int, contextLines int) (*CodeContext, error)

ExtractContext gets lines of code around a specific line number.

type DiffPosition

type DiffPosition struct {
	Path     string // File path
	Line     int    // Line number in the new file
	Position int    // Position in the diff (required by GitHub API)
}

DiffPosition represents a position in a diff.

type FileDiffInfo

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

FileDiffInfo holds diff information for a single file.

type Interface

type Interface interface {
	GetPullRequestChanges(ctx context.Context, prNumber int) (*types.PRChanges, error)
	GetFileContent(ctx context.Context, path string) (string, error)
	FilterReviewComments(ctx context.Context, prNumber int, comments []types.PRReviewComment) ([]types.PRReviewComment, error)
	CreateReviewComments(ctx context.Context, prNumber int, comments []types.PRReviewComment) error
	GetLatestCommitSHA(ctx context.Context, branch string) (string, error)
	MonitorPRComments(ctx context.Context, prNumber int, callback func(comment *github.PullRequestComment)) error
	PreviewReview(ctx context.Context, console types.ConsoleInterface, prNumber int, comments []types.PRReviewComment, metric types.MetricsCollector) ([]types.PRReviewComment, bool, error)

	GetAuthenticatedUser(ctx context.Context) string
	GetRepositoryInfo(ctx context.Context) types.RepositoryInfo
	ListPullRequestComments(ctx context.Context, owner, repo string, prNumber int, opts *github.PullRequestListCommentsOptions) ([]*github.PullRequestComment, *github.Response, error)
	ListPullRequestReviews(ctx context.Context, owner, repo string, prNumber int, opts *github.ListOptions) ([]*github.PullRequestReview, *github.Response, error)
	CreatePullRequestReviewComment(ctx context.Context, owner, repo string, prNumber int, comment *github.PullRequestReviewRequest) (*github.PullRequestReview, *github.Response, error)

	GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*github.PullRequest, *github.Response, error)
	GetRepository(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error)
	GetRepositoryContents(ctx context.Context, owner, repo, path string, opts *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error)
	CompareCommits(ctx context.Context, owner, repo, base, head string, opts *github.ListOptions) (*github.CommitsComparison, *github.Response, error)
	ListLanguages(ctx context.Context, owner, repo string) (map[string]int, *github.Response, error)
	Client() *github.Client
}

Interface defines the interface for GitHub operations.

func NewTools

func NewTools(token, owner, repo string) Interface

NewTools creates a new GitHub tools instance.

type MCPBashHelper

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

MCPBashHelper provides a simple interface to execute bash commands via MCP.

func NewMCPBashHelper

func NewMCPBashHelper() (*MCPBashHelper, error)

NewMCPBashHelper creates a new MCP bash helper.

func (*MCPBashHelper) Close

func (h *MCPBashHelper) Close() error

Close closes the MCP connection and terminates the server.

func (*MCPBashHelper) ExecuteCommand

func (h *MCPBashHelper) ExecuteCommand(ctx context.Context, command string) (string, error)

ExecuteCommand executes a bash command and returns the output.

func (*MCPBashHelper) ExecuteGHCommand

func (h *MCPBashHelper) ExecuteGHCommand(ctx context.Context, args ...string) (string, error)

ExecuteGHCommand executes a gh CLI command.

func (*MCPBashHelper) ExecuteSgrepCommand

func (h *MCPBashHelper) ExecuteSgrepCommand(ctx context.Context, args ...string) (string, error)

ExecuteSgrepCommand executes an sgrep CLI command for semantic code search. sgrep provides fast local semantic search using embeddings and tree-sitter chunking.

func (*MCPBashHelper) SgrepIndex

func (h *MCPBashHelper) SgrepIndex(ctx context.Context, path string) (string, error)

SgrepIndex indexes a directory for semantic search.

func (*MCPBashHelper) SgrepSearch

func (h *MCPBashHelper) SgrepSearch(ctx context.Context, query string, limit int) (string, error)

SgrepSearch performs semantic code search using sgrep. Returns JSON results with file paths, line numbers, content, and relevance scores.

type PreviewOptions

type PreviewOptions struct {
	ShowColors      bool   // Use ANSI colors for formatting
	ContextLines    int    // Number of context lines around changes
	FilePathStyle   string // How to display file paths (full, relative, basename)
	ShowLineNumbers bool   // Whether to show line numbers
}

PreviewOptions configures how review previews are displayed.

type Tools

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

Tools handles interactions with GitHub API.

func (*Tools) Client

func (g *Tools) Client() *github.Client

func (*Tools) CompareCommits

func (g *Tools) CompareCommits(ctx context.Context, owner, repo, base, head string, opts *github.ListOptions) (*github.CommitsComparison, *github.Response, error)

func (*Tools) CreatePullRequestReviewComment

func (g *Tools) CreatePullRequestReviewComment(ctx context.Context, owner, repo string, prNumber int, comment *github.PullRequestReviewRequest) (*github.PullRequestReview, *github.Response, error)

CreatePullRequestReviewComment creates a review comment on a pull request.

func (*Tools) CreateReviewComments

func (g *Tools) CreateReviewComments(ctx context.Context, prNumber int, comments []types.PRReviewComment) error

CreateReviewComments posts review comments back to GitHub.

func (*Tools) FilterReviewComments

func (g *Tools) FilterReviewComments(ctx context.Context, prNumber int, comments []types.PRReviewComment) ([]types.PRReviewComment, error)

func (*Tools) GetAuthenticatedUser

func (g *Tools) GetAuthenticatedUser(ctx context.Context) string

func (*Tools) GetFileContent

func (g *Tools) GetFileContent(ctx context.Context, filePath string) (string, error)

GetFileContent retrieves the content of a specific file from the repository. This uses the GitHub API's GetContents endpoint to fetch file content.

func (*Tools) GetLatestCommitSHA

func (g *Tools) GetLatestCommitSHA(ctx context.Context, branch string) (string, error)

func (*Tools) GetPullRequest

func (g *Tools) GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*github.PullRequest, *github.Response, error)

func (*Tools) GetPullRequestChanges

func (g *Tools) GetPullRequestChanges(ctx context.Context, prNumber int) (*types.PRChanges, error)

GetPullRequestChanges retrieves the changes from a pull request.

func (*Tools) GetRepository

func (g *Tools) GetRepository(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error)

func (*Tools) GetRepositoryContents

func (g *Tools) GetRepositoryContents(ctx context.Context, owner, repo, path string, opts *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error)

func (*Tools) GetRepositoryInfo

func (g *Tools) GetRepositoryInfo(ctx context.Context) types.RepositoryInfo

func (*Tools) ListLanguages

func (g *Tools) ListLanguages(ctx context.Context, owner, repo string) (map[string]int, *github.Response, error)

func (*Tools) ListPullRequestComments

func (g *Tools) ListPullRequestComments(ctx context.Context, owner, repo string, prNumber int, opts *github.PullRequestListCommentsOptions) ([]*github.PullRequestComment, *github.Response, error)

func (*Tools) ListPullRequestReviews

func (g *Tools) ListPullRequestReviews(ctx context.Context, owner, repo string, prNumber int, opts *github.ListOptions) ([]*github.PullRequestReview, *github.Response, error)

ListPullRequestReviews retrieves all reviews for a pull request.

func (*Tools) MonitorPRComments

func (g *Tools) MonitorPRComments(ctx context.Context, prNumber int, callback func(comment *github.PullRequestComment)) error

func (*Tools) PreviewReview

func (g *Tools) PreviewReview(ctx context.Context, console types.ConsoleInterface, prNumber int, comments []types.PRReviewComment, metric types.MetricsCollector) ([]types.PRReviewComment, bool, error)

Jump to

Keyboard shortcuts

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