4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- "os"
8
- "regexp"
9
7
"strings"
10
8
11
9
"github.com/cli/go-gh/v2/pkg/api"
@@ -132,7 +130,7 @@ func runCombine(cmd *cobra.Command, args []string) error {
132
130
defer spinner .Stop ()
133
131
134
132
// Parse repositories from args or file
135
- repos , err := parseRepositories (args )
133
+ repos , err := ParseRepositories (args , reposFile )
136
134
if err != nil {
137
135
return fmt .Errorf ("failed to parse repositories: %w" , err )
138
136
}
@@ -149,45 +147,6 @@ func runCombine(cmd *cobra.Command, args []string) error {
149
147
return nil
150
148
}
151
149
152
- // parseRepositories parses repository names from arguments or file
153
- func parseRepositories (args []string ) ([]string , error ) {
154
- var repos []string
155
-
156
- // Parse from command line arguments
157
- if len (args ) > 0 {
158
- // Check if repos are comma-separated
159
- for _ , arg := range args {
160
- if strings .Contains (arg , "," ) {
161
- splitRepos := strings .Split (arg , "," )
162
- for _ , repo := range splitRepos {
163
- if trimmedRepo := strings .TrimSpace (repo ); trimmedRepo != "" {
164
- repos = append (repos , trimmedRepo )
165
- }
166
- }
167
- } else {
168
- repos = append (repos , arg )
169
- }
170
- }
171
- }
172
-
173
- // Parse from file if specified
174
- if reposFile != "" {
175
- fileContent , err := os .ReadFile (reposFile )
176
- if err != nil {
177
- return nil , fmt .Errorf ("failed to read repositories file: %w" , err )
178
- }
179
-
180
- lines := strings .Split (string (fileContent ), "\n " )
181
- for _ , line := range lines {
182
- if trimmedLine := strings .TrimSpace (line ); trimmedLine != "" && ! strings .HasPrefix (trimmedLine , "#" ) {
183
- repos = append (repos , trimmedLine )
184
- }
185
- }
186
- }
187
-
188
- return repos , nil
189
- }
190
-
191
150
// executeCombineCommand performs the actual API calls and processing
192
151
func executeCombineCommand (ctx context.Context , spinner * Spinner , repos []string ) error {
193
152
// Create GitHub API client
@@ -245,7 +204,7 @@ func executeCombineCommand(ctx context.Context, spinner *Spinner, repos []string
245
204
branch := pull .Head .Ref
246
205
247
206
// Check if PR matches all filtering criteria
248
- if ! prMatchesCriteria (branch , pull .Labels ) {
207
+ if ! PrMatchesCriteria (branch , pull .Labels ) {
249
208
continue
250
209
}
251
210
@@ -283,112 +242,3 @@ func executeCombineCommand(ctx context.Context, spinner *Spinner, repos []string
283
242
284
243
return nil
285
244
}
286
-
287
- // prMatchesCriteria checks if a PR matches all filtering criteria
288
- func prMatchesCriteria (branch string , prLabels []struct { Name string }) bool {
289
- // Check branch criteria if any are specified
290
- if ! branchMatchesCriteria (branch ) {
291
- return false
292
- }
293
-
294
- // Check label criteria if any are specified
295
- if ! labelsMatchCriteria (prLabels ) {
296
- return false
297
- }
298
-
299
- return true
300
- }
301
-
302
- // branchMatchesCriteria checks if a branch matches the branch filtering criteria
303
- func branchMatchesCriteria (branch string ) bool {
304
- // If no branch filters are specified, all branches pass this check
305
- if branchPrefix == "" && branchSuffix == "" && branchRegex == "" {
306
- return true
307
- }
308
-
309
- // Apply branch prefix filter if specified
310
- if branchPrefix != "" && ! strings .HasPrefix (branch , branchPrefix ) {
311
- return false
312
- }
313
-
314
- // Apply branch suffix filter if specified
315
- if branchSuffix != "" && ! strings .HasSuffix (branch , branchSuffix ) {
316
- return false
317
- }
318
-
319
- // Apply branch regex filter if specified
320
- if branchRegex != "" {
321
- regex , err := regexp .Compile (branchRegex )
322
- if err != nil {
323
- Logger .Warn ("Invalid regex pattern" , "pattern" , branchRegex , "error" , err )
324
- return false
325
- }
326
-
327
- if ! regex .MatchString (branch ) {
328
- return false
329
- }
330
- }
331
-
332
- return true
333
- }
334
-
335
- // labelsMatchCriteria checks if PR labels match the label filtering criteria
336
- func labelsMatchCriteria (prLabels []struct { Name string }) bool {
337
- // If no label filters are specified, all PRs pass this check
338
- if ignoreLabel == "" && len (ignoreLabels ) == 0 &&
339
- selectLabel == "" && len (selectLabels ) == 0 {
340
- return true
341
- }
342
-
343
- // Check for ignore label (singular)
344
- if ignoreLabel != "" {
345
- for _ , label := range prLabels {
346
- if label .Name == ignoreLabel {
347
- return false
348
- }
349
- }
350
- }
351
-
352
- // Check for ignore labels (plural)
353
- if len (ignoreLabels ) > 0 {
354
- for _ , ignoreL := range ignoreLabels {
355
- for _ , prLabel := range prLabels {
356
- if prLabel .Name == ignoreL {
357
- return false
358
- }
359
- }
360
- }
361
- }
362
-
363
- // Check for select label (singular)
364
- if selectLabel != "" {
365
- found := false
366
- for _ , label := range prLabels {
367
- if label .Name == selectLabel {
368
- found = true
369
- break
370
- }
371
- }
372
- if ! found {
373
- return false
374
- }
375
- }
376
-
377
- // Check for select labels (plural)
378
- if len (selectLabels ) > 0 {
379
- for _ , requiredLabel := range selectLabels {
380
- found := false
381
- for _ , prLabel := range prLabels {
382
- if prLabel .Name == requiredLabel {
383
- found = true
384
- break
385
- }
386
- }
387
- if ! found {
388
- return false
389
- }
390
- }
391
- }
392
-
393
- return true
394
- }
0 commit comments