@@ -17,36 +17,36 @@ func CombinePRs(ctx context.Context, graphQlClient *api.GraphQLClient, restClien
17
17
workingBranchName := combineBranchName + workingBranchSuffix
18
18
19
19
// Get the default branch of the repository
20
- repoDefaultBranch , err := getDefaultBranch (ctx , restClient , repo . Owner , repo . Repo )
20
+ repoDefaultBranch , err := getDefaultBranch (ctx , restClient , repo )
21
21
if err != nil {
22
22
return fmt .Errorf ("failed to get default branch: %w" , err )
23
23
}
24
24
25
- baseBranchSHA , err := getBranchSHA (ctx , restClient , repo . Owner , repo . Repo , repoDefaultBranch )
25
+ baseBranchSHA , err := getBranchSHA (ctx , restClient , repo , repoDefaultBranch )
26
26
if err != nil {
27
27
return fmt .Errorf ("failed to get SHA of main branch: %w" , err )
28
28
}
29
29
30
30
// Delete any pre-existing working branch
31
- err = deleteBranch (ctx , restClient , repo . Owner , repo . Repo , workingBranchName )
31
+ err = deleteBranch (ctx , restClient , repo , workingBranchName )
32
32
if err != nil {
33
33
Logger .Debug ("Working branch not found, continuing" , "branch" , workingBranchName )
34
34
}
35
35
36
36
// Delete any pre-existing combined branch
37
- err = deleteBranch (ctx , restClient , repo . Owner , repo . Repo , combineBranchName )
37
+ err = deleteBranch (ctx , restClient , repo , combineBranchName )
38
38
if err != nil {
39
39
Logger .Debug ("Combined branch not found, continuing" , "branch" , combineBranchName )
40
40
}
41
41
42
42
// Create the combined branch
43
- err = createBranch (ctx , restClient , repo . Owner , repo . Repo , combineBranchName , baseBranchSHA )
43
+ err = createBranch (ctx , restClient , repo , combineBranchName , baseBranchSHA )
44
44
if err != nil {
45
45
return fmt .Errorf ("failed to create combined branch: %w" , err )
46
46
}
47
47
48
48
// Create the working branch
49
- err = createBranch (ctx , restClient , repo . Owner , repo . Repo , workingBranchName , baseBranchSHA )
49
+ err = createBranch (ctx , restClient , repo , workingBranchName , baseBranchSHA )
50
50
if err != nil {
51
51
return fmt .Errorf ("failed to create working branch: %w" , err )
52
52
}
@@ -55,7 +55,7 @@ func CombinePRs(ctx context.Context, graphQlClient *api.GraphQLClient, restClien
55
55
var combinedPRs []string
56
56
var mergeFailedPRs []string
57
57
for _ , pr := range pulls {
58
- err := mergeBranch (ctx , restClient , repo . Owner , repo . Repo , workingBranchName , pr .Head .Ref )
58
+ err := mergeBranch (ctx , restClient , repo , workingBranchName , pr .Head .Ref )
59
59
if err != nil {
60
60
// Check if the error is a 409 merge conflict
61
61
if isMergeConflictError (err ) {
@@ -73,21 +73,21 @@ func CombinePRs(ctx context.Context, graphQlClient *api.GraphQLClient, restClien
73
73
}
74
74
75
75
// Update the combined branch to the latest commit of the working branch
76
- err = updateRef (ctx , restClient , repo . Owner , repo . Repo , combineBranchName , workingBranchName )
76
+ err = updateRef (ctx , restClient , repo , combineBranchName , workingBranchName )
77
77
if err != nil {
78
78
return fmt .Errorf ("failed to update combined branch: %w" , err )
79
79
}
80
80
81
81
// Delete the temporary working branch
82
- err = deleteBranch (ctx , restClient , repo . Owner , repo . Repo , workingBranchName )
82
+ err = deleteBranch (ctx , restClient , repo , workingBranchName )
83
83
if err != nil {
84
84
Logger .Warn ("Failed to delete working branch" , "branch" , workingBranchName , "error" , err )
85
85
}
86
86
87
87
// Create the combined PR
88
88
prBody := generatePRBody (combinedPRs , mergeFailedPRs )
89
89
prTitle := "Combined PRs"
90
- err = createPullRequest (ctx , restClient , repo . Owner , repo . Repo , prTitle , combineBranchName , repoDefaultBranch , prBody )
90
+ err = createPullRequest (ctx , restClient , repo , prTitle , combineBranchName , repoDefaultBranch , prBody )
91
91
if err != nil {
92
92
return fmt .Errorf ("failed to create combined PR: %w" , err )
93
93
}
@@ -102,11 +102,11 @@ func isMergeConflictError(err error) bool {
102
102
}
103
103
104
104
// Find the default branch of a repository
105
- func getDefaultBranch (ctx context.Context , client * api.RESTClient , owner , repo string ) (string , error ) {
105
+ func getDefaultBranch (ctx context.Context , client * api.RESTClient , repo github. Repo ) (string , error ) {
106
106
var repoInfo struct {
107
107
DefaultBranch string `json:"default_branch"`
108
108
}
109
- endpoint := fmt .Sprintf ("repos/%s/%s" , owner , repo )
109
+ endpoint := fmt .Sprintf ("repos/%s/%s" , repo . Owner , repo . Repo )
110
110
err := client .Get (endpoint , & repoInfo )
111
111
if err != nil {
112
112
return "" , fmt .Errorf ("failed to get default branch: %w" , err )
@@ -115,13 +115,13 @@ func getDefaultBranch(ctx context.Context, client *api.RESTClient, owner, repo s
115
115
}
116
116
117
117
// Get the SHA of a given branch
118
- func getBranchSHA (ctx context.Context , client * api.RESTClient , owner , repo , branch string ) (string , error ) {
118
+ func getBranchSHA (ctx context.Context , client * api.RESTClient , repo github. Repo , branch string ) (string , error ) {
119
119
var ref struct {
120
120
Object struct {
121
121
SHA string `json:"sha"`
122
122
} `json:"object"`
123
123
}
124
- endpoint := fmt .Sprintf ("repos/%s/%s/git/ref/heads/%s" , owner , repo , branch )
124
+ endpoint := fmt .Sprintf ("repos/%s/%s/git/ref/heads/%s" , repo . Owner , repo . Repo , branch )
125
125
err := client .Get (endpoint , & ref )
126
126
if err != nil {
127
127
return "" , fmt .Errorf ("failed to get SHA of branch %s: %w" , branch , err )
@@ -148,14 +148,14 @@ func generatePRBody(combinedPRs, mergeFailedPRs []string) string {
148
148
}
149
149
150
150
// deleteBranch deletes a branch in the repository
151
- func deleteBranch (ctx context.Context , client * api.RESTClient , owner , repo , branch string ) error {
152
- endpoint := fmt .Sprintf ("repos/%s/%s/git/refs/heads/%s" , owner , repo , branch )
151
+ func deleteBranch (ctx context.Context , client * api.RESTClient , repo github. Repo , branch string ) error {
152
+ endpoint := fmt .Sprintf ("repos/%s/%s/git/refs/heads/%s" , repo . Owner , repo . Repo , branch )
153
153
return client .Delete (endpoint , nil )
154
154
}
155
155
156
156
// createBranch creates a new branch in the repository
157
- func createBranch (ctx context.Context , client * api.RESTClient , owner , repo , branch , sha string ) error {
158
- endpoint := fmt .Sprintf ("repos/%s/%s/git/refs" , owner , repo )
157
+ func createBranch (ctx context.Context , client * api.RESTClient , repo github. Repo , branch , sha string ) error {
158
+ endpoint := fmt .Sprintf ("repos/%s/%s/git/refs" , repo . Owner , repo . Repo )
159
159
payload := map [string ]string {
160
160
"ref" : "refs/heads/" + branch ,
161
161
"sha" : sha ,
@@ -168,8 +168,8 @@ func createBranch(ctx context.Context, client *api.RESTClient, owner, repo, bran
168
168
}
169
169
170
170
// mergeBranch merges a branch into the base branch
171
- func mergeBranch (ctx context.Context , client * api.RESTClient , owner , repo , base , head string ) error {
172
- endpoint := fmt .Sprintf ("repos/%s/%s/merges" , owner , repo )
171
+ func mergeBranch (ctx context.Context , client * api.RESTClient , repo github. Repo , base , head string ) error {
172
+ endpoint := fmt .Sprintf ("repos/%s/%s/merges" , repo . Owner , repo . Repo )
173
173
payload := map [string ]string {
174
174
"base" : base ,
175
175
"head" : head ,
@@ -182,21 +182,21 @@ func mergeBranch(ctx context.Context, client *api.RESTClient, owner, repo, base,
182
182
}
183
183
184
184
// updateRef updates a branch to point to the latest commit of another branch
185
- func updateRef (ctx context.Context , client * api.RESTClient , owner , repo , branch , sourceBranch string ) error {
185
+ func updateRef (ctx context.Context , client * api.RESTClient , repo github. Repo , branch , sourceBranch string ) error {
186
186
// Get the SHA of the source branch
187
187
var ref struct {
188
188
Object struct {
189
189
SHA string `json:"sha"`
190
190
} `json:"object"`
191
191
}
192
- endpoint := fmt .Sprintf ("repos/%s/%s/git/ref/heads/%s" , owner , repo , sourceBranch )
192
+ endpoint := fmt .Sprintf ("repos/%s/%s/git/ref/heads/%s" , repo . Owner , repo . Repo , sourceBranch )
193
193
err := client .Get (endpoint , & ref )
194
194
if err != nil {
195
195
return fmt .Errorf ("failed to get SHA of source branch: %w" , err )
196
196
}
197
197
198
198
// Update the branch to point to the new SHA
199
- endpoint = fmt .Sprintf ("repos/%s/%s/git/refs/heads/%s" , owner , repo , branch )
199
+ endpoint = fmt .Sprintf ("repos/%s/%s/git/refs/heads/%s" , repo . Owner , repo . Repo , branch )
200
200
payload := map [string ]interface {}{
201
201
"sha" : ref .Object .SHA ,
202
202
"force" : true ,
@@ -209,8 +209,8 @@ func updateRef(ctx context.Context, client *api.RESTClient, owner, repo, branch,
209
209
}
210
210
211
211
// createPullRequest creates a new pull request
212
- func createPullRequest (ctx context.Context , client * api.RESTClient , owner , repo , title , head , base , body string ) error {
213
- endpoint := fmt .Sprintf ("repos/%s/%s/pulls" , owner , repo )
212
+ func createPullRequest (ctx context.Context , client * api.RESTClient , repo github. Repo , title , head , base , body string ) error {
213
+ endpoint := fmt .Sprintf ("repos/%s/%s/pulls" , repo . Owner , repo . Repo )
214
214
payload := map [string ]string {
215
215
"title" : title ,
216
216
"head" : head ,
0 commit comments