github

package
v0.0.0-...-b206e16 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 13 Imported by: ? 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 (
	// MaxCommentSize is GitHub's limit for comment body size.
	MaxCommentSize = 65536
	// CommentsPerPage is the number of comments to fetch per API call.
	CommentsPerPage = 100
	// MaxRetries is the maximum number of API retries.
	MaxRetries = 3
	// RetryDelay is the base delay between retries.
	RetryDelay = time.Second
)

Variables

View Source
var (
	// Context errors.
	ErrNotGitHubActions        = errors.New("not running in GitHub Actions environment")
	ErrRepositoryNotSet        = errors.New("GITHUB_REPOSITORY environment variable not set")
	ErrInvalidRepositoryFormat = errors.New("invalid GITHUB_REPOSITORY format")
	ErrEventNameNotSet         = errors.New("GITHUB_EVENT_NAME environment variable not set")
	ErrCommentUUIDNotSet       = errors.New("GOTCHA_COMMENT_UUID environment variable not set")
	ErrGitHubTokenNotAvailable = errors.New("GitHub token not available")
	ErrUnsupportedEventType    = errors.New("event type is not supported for PR comments")
	ErrEventPathNotSet         = errors.New("GITHUB_EVENT_PATH not set")
	ErrNoPRNumberInEvent       = errors.New("no PR number found in event payload")
	ErrNoPRNumberInEnv         = errors.New("no PR number found in environment variables")

	// Comment manager errors.
	ErrUUIDCannotBeEmpty  = errors.New("UUID cannot be empty")
	ErrGitHubContextIsNil = errors.New("GitHub context cannot be nil")

	// Mock client errors.
	ErrCommentNotFound = errors.New("comment not found")
)

GitHub-related static errors.

Functions

func GetPRNumberFromEnv

func GetPRNumberFromEnv() (int, error)

GetPRNumberFromEnv attempts to get PR number from environment variables as fallback.

Types

type Client

type Client interface {
	ListIssueComments(ctx context.Context, owner, repo string, issueNumber int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)
	CreateComment(ctx context.Context, owner, repo string, issueNumber int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
	UpdateComment(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
}

Client interface for GitHub operations to enable mocking.

func NewClient

func NewClient(token string) Client

NewClient creates a new GitHub client with authentication.

type CommentManager

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

CommentManager handles GitHub PR comment operations.

func NewCommentManager

func NewCommentManager(client Client, logger *log.Logger) *CommentManager

NewCommentManager creates a new comment manager.

func (*CommentManager) FindExistingComment

func (m *CommentManager) FindExistingComment(ctx context.Context, owner, repo string, prNumber int, uuid string) (*github.IssueComment, error)

FindExistingComment searches for a comment with the specified UUID marker. It handles pagination to search through all comments on the PR.

func (*CommentManager) PostOrUpdateComment

func (m *CommentManager) PostOrUpdateComment(ctx context.Context, ghCtx *Context, markdown string) error

PostOrUpdateComment creates a new comment or updates an existing one.

type Context

type Context struct {
	Owner       string
	Repo        string
	PRNumber    int
	CommentUUID string
	Token       string
	EventName   string
	IsActions   bool
}

Context represents GitHub Actions environment information.

func DetectContext

func DetectContext() (*Context, error)

DetectContext checks if running in GitHub Actions and extracts context information.

func (*Context) IsSupported

func (c *Context) IsSupported() bool

IsSupported checks if the current GitHub context supports PR comments.

func (*Context) String

func (c *Context) String() string

String returns a string representation of the context.

type MockClient

type MockClient struct {
	Comments   []*github.IssueComment
	CallCount  map[string]int
	ListFunc   func(ctx context.Context, owner, repo string, issueNumber int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)
	CreateFunc func(ctx context.Context, owner, repo string, issueNumber int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
	UpdateFunc func(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

	// State tracking
	CreatedComments []*github.IssueComment
	UpdatedComments []*github.IssueComment
}

MockClient for testing GitHub operations.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client for testing.

func (*MockClient) AddComment

func (m *MockClient) AddComment(id int64, body string)

AddComment adds a comment to the mock for testing.

func (*MockClient) CreateComment

func (m *MockClient) CreateComment(ctx context.Context, owner, repo string, issueNumber int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

CreateComment mocks creating a new comment.

func (*MockClient) GenerateMockComments

func (m *MockClient) GenerateMockComments(count int, uuidMarker string, targetIndex int)

GenerateMockComments creates a specified number of mock comments for pagination testing.

func (*MockClient) ListIssueComments

func (m *MockClient) ListIssueComments(ctx context.Context, owner, repo string, issueNumber int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)

ListIssueComments mocks listing comments with pagination support.

func (*MockClient) UpdateComment

func (m *MockClient) UpdateComment(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

UpdateComment mocks updating an existing comment.

type RealClient

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

RealClient wraps the actual GitHub client.

func (*RealClient) CreateComment

func (c *RealClient) CreateComment(ctx context.Context, owner, repo string, issueNumber int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

CreateComment creates a new comment on an issue.

func (*RealClient) ListIssueComments

func (c *RealClient) ListIssueComments(ctx context.Context, owner, repo string, issueNumber int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)

ListIssueComments lists comments for an issue with pagination support.

func (*RealClient) UpdateComment

func (c *RealClient) UpdateComment(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)

UpdateComment updates an existing comment.

Jump to

Keyboard shortcuts

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