@@ -20,7 +20,13 @@ func CombinePRs(ctx context.Context, graphQlClient *api.GraphQLClient, restClien
20
20
// Define the combined branch name
21
21
workingBranchName := combineBranchName + workingBranchSuffix
22
22
23
- baseBranchSHA , err := getBranchSHA (ctx , restClient , owner , repo , baseBranch )
23
+ // Get the default branch of the repository
24
+ repoDefaultBranch , err := getDefaultBranch (ctx , restClient , owner , repo )
25
+ if err != nil {
26
+ return fmt .Errorf ("failed to get default branch: %w" , err )
27
+ }
28
+
29
+ baseBranchSHA , err := getBranchSHA (ctx , restClient , owner , repo , repoDefaultBranch )
24
30
if err != nil {
25
31
return fmt .Errorf ("failed to get SHA of main branch: %w" , err )
26
32
}
@@ -78,14 +84,27 @@ func CombinePRs(ctx context.Context, graphQlClient *api.GraphQLClient, restClien
78
84
// Create the combined PR
79
85
prBody := generatePRBody (combinedPRs , mergeFailedPRs )
80
86
prTitle := "Combined PRs"
81
- err = createPullRequest (ctx , restClient , owner , repo , prTitle , combineBranchName , baseBranch , prBody )
87
+ err = createPullRequest (ctx , restClient , owner , repo , prTitle , combineBranchName , repoDefaultBranch , prBody )
82
88
if err != nil {
83
89
return fmt .Errorf ("failed to create combined PR: %w" , err )
84
90
}
85
91
86
92
return nil
87
93
}
88
94
95
+ // Find the default branch of a repository
96
+ func getDefaultBranch (ctx context.Context , client * api.RESTClient , owner , repo string ) (string , error ) {
97
+ var repoInfo struct {
98
+ DefaultBranch string `json:"default_branch"`
99
+ }
100
+ endpoint := fmt .Sprintf ("repos/%s/%s" , owner , repo )
101
+ err := client .Get (endpoint , & repoInfo )
102
+ if err != nil {
103
+ return "" , fmt .Errorf ("failed to get default branch: %w" , err )
104
+ }
105
+ return repoInfo .DefaultBranch , nil
106
+ }
107
+
89
108
// Get the SHA of a given branch
90
109
func getBranchSHA (ctx context.Context , client * api.RESTClient , owner , repo , branch string ) (string , error ) {
91
110
var ref struct {
0 commit comments