Documentation
¶
Index ¶
- Constants
- Variables
- func GetPRNumberFromEnv() (int, error)
- type Client
- type CommentManager
- type Context
- type MockClient
- func (m *MockClient) AddComment(id int64, body string)
- func (m *MockClient) CreateComment(ctx context.Context, owner, repo string, issueNumber int, ...) (*github.IssueComment, *github.Response, error)
- func (m *MockClient) GenerateMockComments(count int, uuidMarker string, targetIndex int)
- func (m *MockClient) ListIssueComments(ctx context.Context, owner, repo string, issueNumber int, ...) ([]*github.IssueComment, *github.Response, error)
- func (m *MockClient) UpdateComment(ctx context.Context, owner, repo string, commentID int64, ...) (*github.IssueComment, *github.Response, error)
- type RealClient
- func (c *RealClient) CreateComment(ctx context.Context, owner, repo string, issueNumber int, ...) (*github.IssueComment, *github.Response, error)
- func (c *RealClient) ListIssueComments(ctx context.Context, owner, repo string, issueNumber int, ...) ([]*github.IssueComment, *github.Response, error)
- func (c *RealClient) UpdateComment(ctx context.Context, owner, repo string, commentID int64, ...) (*github.IssueComment, *github.Response, error)
Constants ¶
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 ¶
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 ¶
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.
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 ¶
DetectContext checks if running in GitHub Actions and extracts context information.
func (*Context) IsSupported ¶
IsSupported checks if the current GitHub context supports PR comments.
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.