@@ -15,11 +15,14 @@ import (
1515// Uses library functions from pkg/github and pkg/cost for fetching, sampling,
1616// and extrapolation - all functionality is available to external clients.
1717func analyzeRepository (ctx context.Context , owner , repo string , sampleSize , days int , cfg cost.Config , token , dataSource string ) error {
18+ // Create GitHub client without caching (for CLI)
19+ client := github .NewClientWithoutCache ()
20+
1821 // Calculate since date
1922 since := time .Now ().AddDate (0 , 0 , - days )
2023
2124 // Fetch all PRs modified since the date using library function
22- prs , err := github .FetchPRsFromRepo (ctx , owner , repo , since , token , nil )
25+ prs , err := client .FetchPRsFromRepo (ctx , owner , repo , since , token , nil )
2326 if err != nil {
2427 return fmt .Errorf ("failed to fetch PRs: %w" , err )
2528 }
@@ -59,14 +62,14 @@ func analyzeRepository(ctx context.Context, owner, repo string, sampleSize, days
5962 }
6063
6164 // Convert samples to PRSummaryInfo format
62- var summaries []cost.PRSummaryInfo
63- for _ , pr := range samples {
64- summaries = append ( summaries , cost.PRSummaryInfo {
65- Owner : pr .Owner ,
66- Repo : pr .Repo ,
67- Number : pr .Number ,
68- UpdatedAt : pr .UpdatedAt ,
69- })
65+ summaries := make ( []cost.PRSummaryInfo , len ( samples ))
66+ for i := range samples {
67+ summaries [ i ] = cost.PRSummaryInfo {
68+ Owner : samples [ i ] .Owner ,
69+ Repo : samples [ i ] .Repo ,
70+ Number : samples [ i ] .Number ,
71+ UpdatedAt : samples [ i ] .UpdatedAt ,
72+ }
7073 }
7174
7275 // Create fetcher
@@ -93,25 +96,25 @@ func analyzeRepository(ctx context.Context, owner, repo string, sampleSize, days
9396 totalAuthors := github .CountUniqueAuthors (prs )
9497
9598 // Query for actual count of open PRs (not extrapolated from samples)
96- openPRCount , err := github .CountOpenPRsInRepo (ctx , owner , repo , token )
99+ openPRCount , err := client .CountOpenPRsInRepo (ctx , owner , repo , token )
97100 if err != nil {
98101 slog .Warn ("Failed to count open PRs, using 0" , "error" , err )
99102 openPRCount = 0
100103 }
101104
102105 // Convert PRSummary to PRSummaryInfo for extrapolation
103106 prSummaryInfos := make ([]cost.PRSummaryInfo , len (prs ))
104- for i , pr := range prs {
107+ for i := range prs {
105108 prSummaryInfos [i ] = cost.PRSummaryInfo {
106- Owner : pr .Owner ,
107- Repo : pr .Repo ,
108- Author : pr .Author ,
109- AuthorType : pr .AuthorType ,
110- CreatedAt : pr .CreatedAt ,
111- UpdatedAt : pr .UpdatedAt ,
112- ClosedAt : pr .ClosedAt ,
113- Merged : pr .Merged ,
114- State : pr .State ,
109+ Owner : prs [ i ] .Owner ,
110+ Repo : prs [ i ] .Repo ,
111+ Author : prs [ i ] .Author ,
112+ AuthorType : prs [ i ] .AuthorType ,
113+ CreatedAt : prs [ i ] .CreatedAt ,
114+ UpdatedAt : prs [ i ] .UpdatedAt ,
115+ ClosedAt : prs [ i ] .ClosedAt ,
116+ Merged : prs [ i ] .Merged ,
117+ State : prs [ i ] .State ,
115118 }
116119 }
117120
@@ -128,13 +131,16 @@ func analyzeRepository(ctx context.Context, owner, repo string, sampleSize, days
128131// Uses library functions from pkg/github and pkg/cost for fetching, sampling,
129132// and extrapolation - all functionality is available to external clients.
130133func analyzeOrganization (ctx context.Context , org string , sampleSize , days int , cfg cost.Config , token , dataSource string ) error {
134+ // Create GitHub client without caching (for CLI)
135+ client := github .NewClientWithoutCache ()
136+
131137 slog .Info ("Fetching PR list from organization" )
132138
133139 // Calculate since date
134140 since := time .Now ().AddDate (0 , 0 , - days )
135141
136142 // Fetch all PRs across the org modified since the date using library function
137- prs , err := github .FetchPRsFromOrg (ctx , org , since , token , nil )
143+ prs , err := client .FetchPRsFromOrg (ctx , org , since , token , nil )
138144 if err != nil {
139145 return fmt .Errorf ("failed to fetch PRs: %w" , err )
140146 }
@@ -174,14 +180,14 @@ func analyzeOrganization(ctx context.Context, org string, sampleSize, days int,
174180 }
175181
176182 // Convert samples to PRSummaryInfo format
177- var summaries []cost.PRSummaryInfo
178- for _ , pr := range samples {
179- summaries = append ( summaries , cost.PRSummaryInfo {
180- Owner : pr .Owner ,
181- Repo : pr .Repo ,
182- Number : pr .Number ,
183- UpdatedAt : pr .UpdatedAt ,
184- })
183+ summaries := make ( []cost.PRSummaryInfo , len ( samples ))
184+ for i := range samples {
185+ summaries [ i ] = cost.PRSummaryInfo {
186+ Owner : samples [ i ] .Owner ,
187+ Repo : samples [ i ] .Repo ,
188+ Number : samples [ i ] .Number ,
189+ UpdatedAt : samples [ i ] .UpdatedAt ,
190+ }
185191 }
186192
187193 // Create fetcher
@@ -208,7 +214,7 @@ func analyzeOrganization(ctx context.Context, org string, sampleSize, days int,
208214 totalAuthors := github .CountUniqueAuthors (prs )
209215
210216 // Count open PRs across the entire organization with a single query
211- totalOpenPRs , err := github .CountOpenPRsInOrg (ctx , org , token )
217+ totalOpenPRs , err := client .CountOpenPRsInOrg (ctx , org , token )
212218 if err != nil {
213219 slog .Warn ("Failed to count open PRs in organization, using 0" , "error" , err )
214220 totalOpenPRs = 0
@@ -217,17 +223,17 @@ func analyzeOrganization(ctx context.Context, org string, sampleSize, days int,
217223
218224 // Convert PRSummary to PRSummaryInfo for extrapolation
219225 prSummaryInfos := make ([]cost.PRSummaryInfo , len (prs ))
220- for i , pr := range prs {
226+ for i := range prs {
221227 prSummaryInfos [i ] = cost.PRSummaryInfo {
222- Owner : pr .Owner ,
223- Repo : pr .Repo ,
224- Author : pr .Author ,
225- AuthorType : pr .AuthorType ,
226- CreatedAt : pr .CreatedAt ,
227- UpdatedAt : pr .UpdatedAt ,
228- ClosedAt : pr .ClosedAt ,
229- Merged : pr .Merged ,
230- State : pr .State ,
228+ Owner : prs [ i ] .Owner ,
229+ Repo : prs [ i ] .Repo ,
230+ Author : prs [ i ] .Author ,
231+ AuthorType : prs [ i ] .AuthorType ,
232+ CreatedAt : prs [ i ] .CreatedAt ,
233+ UpdatedAt : prs [ i ] .UpdatedAt ,
234+ ClosedAt : prs [ i ] .ClosedAt ,
235+ Merged : prs [ i ] .Merged ,
236+ State : prs [ i ] .State ,
231237 }
232238 }
233239
0 commit comments