Files
Sameen Karim 9d2c44263f Remove unused GraphQL fields to reduce API rate limit consumption (#78)
Audit all 7 GraphQL operations and remove fields that are fetched but
never used in Go code:

- Remove FindAnyPRForBranch: entire function is dead code (zero call sites)
- FindPRForBranch: remove title, state, headRefName, merged (4 fields)
- CreatePR: remove title, state, headRefName, baseRefName, isDraft (5 fields)
- FindPRDetailsForBranch: remove id, title, headRefName, baseRefName,
  comments { totalCount } (4 fields + 1 nested object)
- FindPRByNumber: remove title (1 field)

Also remove Title from PullRequest struct, and Title + CommentsCount
from PRDetails struct since they are no longer populated or read.

Total: ~15 unused fields removed across 5 queries, 1 dead query deleted,
and 1 unnecessary nested object (comments) eliminated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-11 11:09:31 -04:00

91 lines
2.5 KiB
Go

package github
// MockClient is a test double for GitHub API operations.
// Each field is an optional function that, when set, handles the corresponding
// ClientOps method call. When nil, a reasonable default is returned.
type MockClient struct {
FindPRForBranchFn func(string) (*PullRequest, error)
FindPRByNumberFn func(int) (*PullRequest, error)
FindPRDetailsForBranchFn func(string) (*PRDetails, error)
CreatePRFn func(string, string, string, string, bool) (*PullRequest, error)
UpdatePRBaseFn func(int, string) error
MarkPRReadyForReviewFn func(string) error
ListStacksFn func() ([]RemoteStack, error)
CreateStackFn func([]int) (int, error)
UpdateStackFn func(string, []int) error
DeleteStackFn func(string) error
}
// Compile-time check that MockClient satisfies ClientOps.
var _ ClientOps = (*MockClient)(nil)
func (m *MockClient) FindPRForBranch(branch string) (*PullRequest, error) {
if m.FindPRForBranchFn != nil {
return m.FindPRForBranchFn(branch)
}
return nil, nil
}
func (m *MockClient) FindPRByNumber(number int) (*PullRequest, error) {
if m.FindPRByNumberFn != nil {
return m.FindPRByNumberFn(number)
}
return nil, nil
}
func (m *MockClient) FindPRDetailsForBranch(branch string) (*PRDetails, error) {
if m.FindPRDetailsForBranchFn != nil {
return m.FindPRDetailsForBranchFn(branch)
}
return nil, nil
}
func (m *MockClient) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error) {
if m.CreatePRFn != nil {
return m.CreatePRFn(base, head, title, body, draft)
}
return nil, nil
}
func (m *MockClient) UpdatePRBase(number int, base string) error {
if m.UpdatePRBaseFn != nil {
return m.UpdatePRBaseFn(number, base)
}
return nil
}
func (m *MockClient) MarkPRReadyForReview(prID string) error {
if m.MarkPRReadyForReviewFn != nil {
return m.MarkPRReadyForReviewFn(prID)
}
return nil
}
func (m *MockClient) ListStacks() ([]RemoteStack, error) {
if m.ListStacksFn != nil {
return m.ListStacksFn()
}
return nil, nil
}
func (m *MockClient) CreateStack(prNumbers []int) (int, error) {
if m.CreateStackFn != nil {
return m.CreateStackFn(prNumbers)
}
return 0, nil
}
func (m *MockClient) UpdateStack(stackID string, prNumbers []int) error {
if m.UpdateStackFn != nil {
return m.UpdateStackFn(stackID, prNumbers)
}
return nil
}
func (m *MockClient) DeleteStack(stackID string) error {
if m.DeleteStackFn != nil {
return m.DeleteStackFn(stackID)
}
return nil
}