@@ -21,75 +21,90 @@ type RESTClientInterface interface {
21
21
}
22
22
23
23
// CombinePRsWithStats combines PRs and returns stats for summary output
24
- func CombinePRsWithStats (ctx context.Context , graphQlClient * api.GraphQLClient , restClient RESTClientInterface , repo github.Repo , pulls github.Pulls , command string ) (combined []string , mergeConflicts []string , combinedPRLink string , err error ) {
24
+ func CombinePRsWithStats (ctx context.Context , graphQlClient * api.GraphQLClient , restClient RESTClientInterface , repo github.Repo , pulls github.Pulls , command string , dryRun bool ) (combined []string , mergeConflicts []string , combinedPRLink string , err error ) {
25
+ // Move variable definitions outside the conditional blocks
25
26
workingBranchName := combineBranchName + workingBranchSuffix
27
+ repoDefaultBranch := "main" // Default branch assumed for simulation
26
28
27
- repoDefaultBranch , err := getDefaultBranch ( ctx , restClient , repo )
28
- if err != nil {
29
- return nil , nil , "" , fmt . Errorf ( "failed to get default branch: %w" , err )
29
+ if dryRun {
30
+ Logger . Debug ( "Dry-run mode enabled. No changes will be made." )
31
+ Logger . Debug ( "Simulating branch operations" , "workingBranch " , workingBranchName , "defaultBranch" , repoDefaultBranch )
30
32
}
31
33
32
- baseBranchSHA , err := getBranchSHA (ctx , restClient , repo , repoDefaultBranch )
33
- if err != nil {
34
- return nil , nil , "" , fmt .Errorf ("failed to get SHA of main branch: %w" , err )
35
- }
36
- // Delete any pre-existing working branch
34
+ // Skip branch creation and deletion if dry-run is enabled
35
+ if ! dryRun {
36
+ repoDefaultBranch , err = getDefaultBranch (ctx , restClient , repo )
37
+ if err != nil {
38
+ return nil , nil , "" , fmt .Errorf ("failed to get default branch: %w" , err )
39
+ }
37
40
38
- // Delete any pre-existing working branch
39
- err = deleteBranch ( ctx , restClient , repo , workingBranchName )
40
- if err != nil {
41
- Logger . Debug ( "Working branch not found, continuing" , "branch" , workingBranchName )
41
+ baseBranchSHA , err := getBranchSHA ( ctx , restClient , repo , repoDefaultBranch )
42
+ if err != nil {
43
+ return nil , nil , "" , fmt . Errorf ( "failed to get SHA of main branch: %w" , err )
44
+ }
42
45
43
- // Delete any pre-existing combined branch
44
- }
46
+ err = deleteBranch (ctx , restClient , repo , workingBranchName )
47
+ if err != nil {
48
+ Logger .Debug ("Working branch not found, continuing" , "branch" , workingBranchName )
49
+ }
45
50
46
- // Delete any pre-existing combined branch
47
- err = deleteBranch (ctx , restClient , repo , combineBranchName )
48
- if err != nil {
49
- Logger .Debug ("Combined branch not found, continuing" , "branch" , combineBranchName )
50
- }
51
+ err = deleteBranch (ctx , restClient , repo , combineBranchName )
52
+ if err != nil {
53
+ Logger .Debug ("Combined branch not found, continuing" , "branch" , combineBranchName )
54
+ }
51
55
52
- err = createBranch (ctx , restClient , repo , combineBranchName , baseBranchSHA )
53
- if err != nil {
54
- return nil , nil , "" , fmt .Errorf ("failed to create combined branch: %w" , err )
55
- }
56
- err = createBranch (ctx , restClient , repo , workingBranchName , baseBranchSHA )
57
- if err != nil {
58
- return nil , nil , "" , fmt .Errorf ("failed to create working branch: %w" , err )
56
+ err = createBranch (ctx , restClient , repo , combineBranchName , baseBranchSHA )
57
+ if err != nil {
58
+ return nil , nil , "" , fmt .Errorf ("failed to create combined branch: %w" , err )
59
+ }
60
+
61
+ err = createBranch (ctx , restClient , repo , workingBranchName , baseBranchSHA )
62
+ if err != nil {
63
+ return nil , nil , "" , fmt .Errorf ("failed to create working branch: %w" , err )
64
+ }
59
65
}
60
66
67
+ // Simulate merging PRs
61
68
for _ , pr := range pulls {
62
- err := mergeBranch (ctx , restClient , repo , workingBranchName , pr .Head .Ref )
63
- if err != nil {
64
- if isMergeConflictError (err ) {
65
- Logger .Debug ("Merge conflict" , "branch" , pr .Head .Ref , "error" , err )
69
+ if dryRun {
70
+ Logger .Debug ("Simulating merge of branch" , "branch" , pr .Head .Ref )
71
+ combined = append (combined , fmt .Sprintf ("#%d - %s" , pr .Number , pr .Title ))
72
+ } else {
73
+ err := mergeBranch (ctx , restClient , repo , workingBranchName , pr .Head .Ref )
74
+ if err != nil {
75
+ if isMergeConflictError (err ) {
76
+ Logger .Debug ("Merge conflict" , "branch" , pr .Head .Ref , "error" , err )
77
+ } else {
78
+ Logger .Warn ("Failed to merge branch" , "branch" , pr .Head .Ref , "error" , err )
79
+ }
80
+ mergeConflicts = append (mergeConflicts , fmt .Sprintf ("#%d" , pr .Number ))
66
81
} else {
67
- Logger .Warn ("Failed to merge branch" , "branch" , pr .Head .Ref , "error" , err )
82
+ Logger .Debug ("Merged branch" , "branch" , pr .Head .Ref )
83
+ combined = append (combined , fmt .Sprintf ("#%d - %s" , pr .Number , pr .Title ))
68
84
}
69
- mergeConflicts = append (mergeConflicts , fmt .Sprintf ("#%d" , pr .Number ))
70
- } else {
71
- Logger .Debug ("Merged branch" , "branch" , pr .Head .Ref )
72
- combined = append (combined , fmt .Sprintf ("#%d - %s" , pr .Number , pr .Title ))
73
85
}
74
86
}
75
87
76
- err = updateRef (ctx , restClient , repo , combineBranchName , workingBranchName )
77
- if err != nil {
78
- return combined , mergeConflicts , "" , fmt .Errorf ("failed to update combined branch: %w" , err )
79
- }
80
- err = deleteBranch (ctx , restClient , repo , workingBranchName )
81
- if err != nil {
82
- Logger .Warn ("Failed to delete working branch" , "branch" , workingBranchName , "error" , err )
83
- }
88
+ if ! dryRun {
89
+ err = updateRef (ctx , restClient , repo , combineBranchName , workingBranchName )
90
+ if err != nil {
91
+ return combined , mergeConflicts , "" , fmt .Errorf ("failed to update combined branch: %w" , err )
92
+ }
84
93
85
- prBody := generatePRBody (combined , mergeConflicts , command )
86
- prTitle := "Combined PRs"
87
- prNumber , prErr := createPullRequestWithNumber (ctx , restClient , repo , prTitle , combineBranchName , repoDefaultBranch , prBody , addLabels , addAssignees )
88
- if prErr != nil {
89
- return combined , mergeConflicts , "" , fmt .Errorf ("failed to create combined PR: %w" , prErr )
90
- }
91
- if prNumber > 0 {
92
- combinedPRLink = fmt .Sprintf ("https://github.com/%s/%s/pull/%d" , repo .Owner , repo .Repo , prNumber )
94
+ err = deleteBranch (ctx , restClient , repo , workingBranchName )
95
+ if err != nil {
96
+ Logger .Warn ("Failed to delete working branch" , "branch" , workingBranchName , "error" , err )
97
+ }
98
+
99
+ prBody := generatePRBody (combined , mergeConflicts , command )
100
+ prTitle := "Combined PRs"
101
+ prNumber , prErr := createPullRequestWithNumber (ctx , restClient , repo , prTitle , combineBranchName , repoDefaultBranch , prBody , addLabels , addAssignees )
102
+ if prErr != nil {
103
+ return combined , mergeConflicts , "" , fmt .Errorf ("failed to create combined PR: %w" , prErr )
104
+ }
105
+ if prNumber > 0 {
106
+ combinedPRLink = fmt .Sprintf ("https://github.com/%s/%s/pull/%d" , repo .Owner , repo .Repo , prNumber )
107
+ }
93
108
}
94
109
95
110
return combined , mergeConflicts , combinedPRLink , nil
0 commit comments