github

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID        int       `json:"id"`
	Body      string    `json:"body"`
	User      User      `json:"user"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// Review comment specific fields
	Path     string `json:"path,omitempty"`
	Line     int    `json:"line,omitempty"`
	Position int    `json:"position,omitempty"`

	// Computed fields
	Type string `json:"-"` // "issue" or "review"
}

Comment represents a GitHub comment (issue or review)

type DiffFile

type DiffFile struct {
	Filename string
	Lines    map[int]bool // line numbers that exist in the diff
}

DiffFile represents a file in a PR diff

type GitHubAPI

type GitHubAPI interface {
	// Comment operations
	ListIssueComments(owner, repo string, prNumber int) ([]Comment, error)
	ListReviewComments(owner, repo string, prNumber int) ([]Comment, error)
	CreateIssueComment(owner, repo string, prNumber int, body string) (*Comment, error)
	CreateReviewCommentReply(owner, repo string, commentID int, body string) (*Comment, error)

	// Reaction operations
	AddReaction(owner, repo string, commentID int, reaction string) error
	RemoveReaction(owner, repo string, commentID int, reaction string) error

	// Comment operations
	EditComment(owner, repo string, commentID int, body string) error
	AddReviewComment(owner, repo string, pr int, comment ReviewCommentInput) error

	// PR operations
	FetchPRDiff(owner, repo string, pr int) (*PullRequestDiff, error)
	GetPRDetails(owner, repo string, pr int) (map[string]interface{}, error)

	// Review operations
	CreateReview(owner, repo string, pr int, review ReviewInput) error

	// GraphQL operations
	ResolveReviewThread(threadID string) error
	FindReviewThreadForComment(owner, repo string, prNumber, commentID int) (string, error)
}

GitHubAPI defines the interface for GitHub API operations

type MockClient

type MockClient struct {
	IssueComments  []Comment
	ReviewComments []Comment
	CreatedComment *Comment
	ResolvedThread string

	// Error simulation
	ListIssueCommentsError  error
	ListReviewCommentsError error
	CreateCommentError      error
	ResolveThreadError      error
}

MockClient implements GitHubAPI for testing

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client for testing

func (*MockClient) AddReaction

func (m *MockClient) AddReaction(owner, repo string, commentID int, reaction string) error

func (*MockClient) AddReviewComment

func (m *MockClient) AddReviewComment(owner, repo string, pr int, comment ReviewCommentInput) error

func (*MockClient) CreateIssueComment

func (m *MockClient) CreateIssueComment(owner, repo string, prNumber int, body string) (*Comment, error)

func (*MockClient) CreateReview

func (m *MockClient) CreateReview(owner, repo string, pr int, review ReviewInput) error

func (*MockClient) CreateReviewCommentReply

func (m *MockClient) CreateReviewCommentReply(owner, repo string, commentID int, body string) (*Comment, error)

func (*MockClient) EditComment

func (m *MockClient) EditComment(owner, repo string, commentID int, body string) error

func (*MockClient) FetchPRDiff

func (m *MockClient) FetchPRDiff(owner, repo string, pr int) (*PullRequestDiff, error)

func (*MockClient) FindReviewThreadForComment

func (m *MockClient) FindReviewThreadForComment(owner, repo string, prNumber, commentID int) (string, error)

func (*MockClient) GetPRDetails

func (m *MockClient) GetPRDetails(owner, repo string, pr int) (map[string]interface{}, error)

func (*MockClient) ListIssueComments

func (m *MockClient) ListIssueComments(owner, repo string, prNumber int) ([]Comment, error)

Mock implementations

func (*MockClient) ListReviewComments

func (m *MockClient) ListReviewComments(owner, repo string, prNumber int) ([]Comment, error)

func (*MockClient) RemoveReaction

func (m *MockClient) RemoveReaction(owner, repo string, commentID int, reaction string) error

func (*MockClient) ResolveReviewThread

func (m *MockClient) ResolveReviewThread(threadID string) error

type PullRequestDiff

type PullRequestDiff struct {
	Files []DiffFile
}

PullRequestDiff represents PR diff information

type RealClient

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

RealClient implements GitHubAPI using actual GitHub API calls

func NewRealClient

func NewRealClient() (*RealClient, error)

NewRealClient creates a new GitHub API client

func (*RealClient) AddReaction

func (c *RealClient) AddReaction(owner, repo string, commentID int, reaction string) error

AddReaction adds a reaction to a comment

func (*RealClient) AddReviewComment

func (c *RealClient) AddReviewComment(owner, repo string, pr int, comment ReviewCommentInput) error

AddReviewComment adds a line-specific comment to a PR

func (*RealClient) CreateIssueComment

func (c *RealClient) CreateIssueComment(owner, repo string, prNumber int, body string) (*Comment, error)

CreateIssueComment adds a general comment to a PR

func (*RealClient) CreateReview

func (c *RealClient) CreateReview(owner, repo string, pr int, review ReviewInput) error

CreateReview creates a new review with comments

func (*RealClient) CreateReviewCommentReply

func (c *RealClient) CreateReviewCommentReply(owner, repo string, commentID int, body string) (*Comment, error)

CreateReviewCommentReply adds a reply to a review comment

func (*RealClient) EditComment

func (c *RealClient) EditComment(owner, repo string, commentID int, body string) error

EditComment edits an existing comment

func (*RealClient) FetchPRDiff

func (c *RealClient) FetchPRDiff(owner, repo string, pr int) (*PullRequestDiff, error)

FetchPRDiff fetches the diff for a pull request

func (*RealClient) FindReviewThreadForComment

func (c *RealClient) FindReviewThreadForComment(owner, repo string, prNumber, commentID int) (string, error)

FindReviewThreadForComment finds the thread ID for a review comment

func (*RealClient) GetPRDetails

func (c *RealClient) GetPRDetails(owner, repo string, pr int) (map[string]interface{}, error)

GetPRDetails fetches basic PR information

func (*RealClient) ListIssueComments

func (c *RealClient) ListIssueComments(owner, repo string, prNumber int) ([]Comment, error)

ListIssueComments fetches all issue comments for a PR

func (*RealClient) ListReviewComments

func (c *RealClient) ListReviewComments(owner, repo string, prNumber int) ([]Comment, error)

ListReviewComments fetches all review comments for a PR

func (*RealClient) RemoveReaction

func (c *RealClient) RemoveReaction(owner, repo string, commentID int, reaction string) error

RemoveReaction removes a reaction from a comment

func (*RealClient) ResolveReviewThread

func (c *RealClient) ResolveReviewThread(threadID string) error

ResolveReviewThread resolves a review thread

type ReviewCommentInput

type ReviewCommentInput struct {
	Body      string `json:"body"`
	Path      string `json:"path"`
	Line      int    `json:"line,omitempty"`
	StartLine int    `json:"start_line,omitempty"`
	Side      string `json:"side,omitempty"`
	CommitID  string `json:"commit_id"`
}

ReviewCommentInput represents input for creating a review comment

type ReviewInput

type ReviewInput struct {
	Body     string               `json:"body,omitempty"`
	Event    string               `json:"event"`
	Comments []ReviewCommentInput `json:"comments,omitempty"`
}

ReviewInput represents input for creating a review

type User

type User struct {
	Login     string `json:"login"`
	ID        int    `json:"id"`
	AvatarURL string `json:"avatar_url"`
}

User represents a GitHub user

Jump to

Keyboard shortcuts

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