Skip to content

Commit 11ab8c6

Browse files
skarimCopilot
andcommitted
Remove unused GraphQL fields to reduce API rate limit consumption
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>
1 parent 7d9ee8c commit 11ab8c6

4 files changed

Lines changed: 26 additions & 99 deletions

File tree

internal/github/client_interface.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package github
55
// Tests can substitute a MockClient.
66
type ClientOps interface {
77
FindPRForBranch(branch string) (*PullRequest, error)
8-
FindAnyPRForBranch(branch string) (*PullRequest, error)
98
FindPRByNumber(number int) (*PullRequest, error)
109
FindPRDetailsForBranch(branch string) (*PRDetails, error)
1110
CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)

internal/github/github.go

Lines changed: 26 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type MergeQueueEntry struct {
2020
type PullRequest struct {
2121
ID string `graphql:"id"`
2222
Number int `graphql:"number"`
23-
Title string `graphql:"title"`
2423
State string `graphql:"state"`
2524
URL string `graphql:"url"`
2625
HeadRefName string `graphql:"headRefName"`
@@ -85,7 +84,14 @@ func (c *Client) FindPRForBranch(branch string) (*PullRequest, error) {
8584
var query struct {
8685
Repository struct {
8786
PullRequests struct {
88-
Nodes []PullRequest
87+
Nodes []struct {
88+
ID string `graphql:"id"`
89+
Number int `graphql:"number"`
90+
URL string `graphql:"url"`
91+
BaseRefName string `graphql:"baseRefName"`
92+
IsDraft bool `graphql:"isDraft"`
93+
MergeQueueEntry *MergeQueueEntry `graphql:"mergeQueueEntry"`
94+
}
8995
} `graphql:"pullRequests(headRefName: $head, states: [OPEN], first: 1)"`
9096
} `graphql:"repository(owner: $owner, name: $name)"`
9197
}
@@ -109,53 +115,9 @@ func (c *Client) FindPRForBranch(branch string) (*PullRequest, error) {
109115
return &PullRequest{
110116
ID: n.ID,
111117
Number: n.Number,
112-
Title: n.Title,
113-
State: n.State,
114-
URL: n.URL,
115-
HeadRefName: n.HeadRefName,
116-
BaseRefName: n.BaseRefName,
117-
IsDraft: n.IsDraft,
118-
Merged: n.Merged,
119-
MergeQueueEntry: n.MergeQueueEntry,
120-
}, nil
121-
}
122-
123-
// FindAnyPRForBranch finds the most recent PR by head branch name regardless of state.
124-
func (c *Client) FindAnyPRForBranch(branch string) (*PullRequest, error) {
125-
var query struct {
126-
Repository struct {
127-
PullRequests struct {
128-
Nodes []PullRequest
129-
} `graphql:"pullRequests(headRefName: $head, last: 1)"`
130-
} `graphql:"repository(owner: $owner, name: $name)"`
131-
}
132-
133-
variables := map[string]interface{}{
134-
"owner": graphql.String(c.owner),
135-
"name": graphql.String(c.repo),
136-
"head": graphql.String(branch),
137-
}
138-
139-
if err := c.gql.Query("FindAnyPRForBranch", &query, variables); err != nil {
140-
return nil, fmt.Errorf("querying PRs: %w", err)
141-
}
142-
143-
nodes := query.Repository.PullRequests.Nodes
144-
if len(nodes) == 0 {
145-
return nil, nil
146-
}
147-
148-
n := nodes[0]
149-
return &PullRequest{
150-
ID: n.ID,
151-
Number: n.Number,
152-
Title: n.Title,
153-
State: n.State,
154118
URL: n.URL,
155-
HeadRefName: n.HeadRefName,
156119
BaseRefName: n.BaseRefName,
157120
IsDraft: n.IsDraft,
158-
Merged: n.Merged,
159121
MergeQueueEntry: n.MergeQueueEntry,
160122
}, nil
161123
}
@@ -165,14 +127,9 @@ func (c *Client) CreatePR(base, head, title, body string, draft bool) (*PullRequ
165127
var mutation struct {
166128
CreatePullRequest struct {
167129
PullRequest struct {
168-
ID string
169-
Number int
170-
Title string
171-
State string
172-
URL string `graphql:"url"`
173-
HeadRefName string
174-
BaseRefName string
175-
IsDraft bool
130+
ID string
131+
Number int
132+
URL string `graphql:"url"`
176133
}
177134
} `graphql:"createPullRequest(input: $input)"`
178135
}
@@ -208,14 +165,9 @@ func (c *Client) CreatePR(base, head, title, body string, draft bool) (*PullRequ
208165

209166
pr := mutation.CreatePullRequest.PullRequest
210167
return &PullRequest{
211-
ID: pr.ID,
212-
Number: pr.Number,
213-
Title: pr.Title,
214-
State: pr.State,
215-
URL: pr.URL,
216-
HeadRefName: pr.HeadRefName,
217-
BaseRefName: pr.BaseRefName,
218-
IsDraft: pr.IsDraft,
168+
ID: pr.ID,
169+
Number: pr.Number,
170+
URL: pr.URL,
219171
}, nil
220172
}
221173

@@ -282,14 +234,12 @@ func (c *Client) repositoryID() (string, error) {
282234

283235
// PRDetails holds enriched pull request data for display in the TUI.
284236
type PRDetails struct {
285-
Number int
286-
Title string
287-
State string // OPEN, CLOSED, MERGED
288-
URL string
289-
IsDraft bool
290-
Merged bool
291-
IsQueued bool
292-
CommentsCount int
237+
Number int
238+
State string // OPEN, CLOSED, MERGED
239+
URL string
240+
IsDraft bool
241+
Merged bool
242+
IsQueued bool
293243
}
294244

295245
// FindPRDetailsForBranch fetches enriched PR data for display purposes.
@@ -299,19 +249,12 @@ func (c *Client) FindPRDetailsForBranch(branch string) (*PRDetails, error) {
299249
Repository struct {
300250
PullRequests struct {
301251
Nodes []struct {
302-
ID string `graphql:"id"`
303252
Number int `graphql:"number"`
304-
Title string `graphql:"title"`
305253
State string `graphql:"state"`
306254
URL string `graphql:"url"`
307-
HeadRefName string `graphql:"headRefName"`
308-
BaseRefName string `graphql:"baseRefName"`
309255
IsDraft bool `graphql:"isDraft"`
310256
Merged bool `graphql:"merged"`
311257
MergeQueueEntry *MergeQueueEntry `graphql:"mergeQueueEntry"`
312-
Comments struct {
313-
TotalCount int `graphql:"totalCount"`
314-
} `graphql:"comments"`
315258
}
316259
} `graphql:"pullRequests(headRefName: $head, last: 1)"`
317260
} `graphql:"repository(owner: $owner, name: $name)"`
@@ -334,14 +277,12 @@ func (c *Client) FindPRDetailsForBranch(branch string) (*PRDetails, error) {
334277

335278
n := nodes[0]
336279
return &PRDetails{
337-
Number: n.Number,
338-
Title: n.Title,
339-
State: n.State,
340-
URL: n.URL,
341-
IsDraft: n.IsDraft,
342-
Merged: n.Merged,
343-
IsQueued: n.MergeQueueEntry != nil && n.MergeQueueEntry.ID != "",
344-
CommentsCount: n.Comments.TotalCount,
280+
Number: n.Number,
281+
State: n.State,
282+
URL: n.URL,
283+
IsDraft: n.IsDraft,
284+
Merged: n.Merged,
285+
IsQueued: n.MergeQueueEntry != nil && n.MergeQueueEntry.ID != "",
345286
}, nil
346287
}
347288

@@ -357,7 +298,6 @@ func (c *Client) FindPRByNumber(number int) (*PullRequest, error) {
357298
PullRequest struct {
358299
ID string `graphql:"id"`
359300
Number int `graphql:"number"`
360-
Title string `graphql:"title"`
361301
State string `graphql:"state"`
362302
URL string `graphql:"url"`
363303
HeadRefName string `graphql:"headRefName"`
@@ -386,7 +326,6 @@ func (c *Client) FindPRByNumber(number int) (*PullRequest, error) {
386326
return &PullRequest{
387327
ID: n.ID,
388328
Number: n.Number,
389-
Title: n.Title,
390329
State: n.State,
391330
URL: n.URL,
392331
HeadRefName: n.HeadRefName,

internal/github/mock_client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package github
55
// ClientOps method call. When nil, a reasonable default is returned.
66
type MockClient struct {
77
FindPRForBranchFn func(string) (*PullRequest, error)
8-
FindAnyPRForBranchFn func(string) (*PullRequest, error)
98
FindPRByNumberFn func(int) (*PullRequest, error)
109
FindPRDetailsForBranchFn func(string) (*PRDetails, error)
1110
CreatePRFn func(string, string, string, string, bool) (*PullRequest, error)
@@ -27,13 +26,6 @@ func (m *MockClient) FindPRForBranch(branch string) (*PullRequest, error) {
2726
return nil, nil
2827
}
2928

30-
func (m *MockClient) FindAnyPRForBranch(branch string) (*PullRequest, error) {
31-
if m.FindAnyPRForBranchFn != nil {
32-
return m.FindAnyPRForBranchFn(branch)
33-
}
34-
return nil, nil
35-
}
36-
3729
func (m *MockClient) FindPRByNumber(number int) (*PullRequest, error) {
3830
if m.FindPRByNumberFn != nil {
3931
return m.FindPRByNumberFn(number)

internal/tui/stackview/data_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func TestLoadBranchNodes_IgnoresStaleMergedPRDetails(t *testing.T) {
128128
FindPRDetailsForBranchFn: func(branch string) (*ghapi.PRDetails, error) {
129129
return &ghapi.PRDetails{
130130
Number: 20,
131-
Title: "Old merged PR",
132131
State: "MERGED",
133132
Merged: true,
134133
}, nil
@@ -174,7 +173,6 @@ func TestLoadBranchNodes_ShowsTrackedMergedPRDetails(t *testing.T) {
174173
FindPRDetailsForBranchFn: func(branch string) (*ghapi.PRDetails, error) {
175174
return &ghapi.PRDetails{
176175
Number: 20,
177-
Title: "Legitimately merged PR",
178176
State: "MERGED",
179177
Merged: true,
180178
}, nil
@@ -214,7 +212,6 @@ func TestLoadBranchNodes_ShowsOpenPRDetails(t *testing.T) {
214212
FindPRDetailsForBranchFn: func(branch string) (*ghapi.PRDetails, error) {
215213
return &ghapi.PRDetails{
216214
Number: 50,
217-
Title: "Active PR",
218215
State: "OPEN",
219216
}, nil
220217
},

0 commit comments

Comments
 (0)