@@ -115,41 +115,15 @@ def lint_test(self) -> None:
115
115
self .logger .error ("Resolve errors and exit shell to continue" )
116
116
self .shell ()
117
117
118
- def find_existing_pr (self ) -> Optional [str ]:
119
- with contextlib .suppress (
120
- subprocess .CalledProcessError , json .JSONDecodeError , TypeError
121
- ):
122
- for pr in json .loads (
123
- self .run (
124
- [
125
- "gh" ,
126
- "pr" ,
127
- "list" ,
128
- "-H" ,
129
- self .branch ,
130
- "-B" ,
131
- "main" ,
132
- "--json" ,
133
- "," .join (("url" , "headRefName" , "baseRefName" )),
134
- ],
135
- capture_output = True ,
136
- check = True ,
137
- ).stdout .decode ()
138
- ):
139
- pr_url = str (pr .pop ("url" ))
140
- if pr == {"headRefName" : self .branch , "baseRefName" : "main" }:
141
- return pr_url
142
- return None
143
-
144
118
def close_existing_pr (self ) -> None :
145
119
# Locate existing PR
146
- pr_url = self .find_existing_pr ( )
147
- if pr_url :
120
+ pr = self .gh . find_pr ( self . repo , self . branch )
121
+ if pr :
148
122
if self .dry_run :
149
- self .logger .info (f"Would close existing PR { pr_url } " )
123
+ self .logger .info (f"Would close existing PR { pr . url } " )
150
124
else :
151
- self . run ([ "gh" , "pr" , "close" , pr_url ] )
152
- self .logger .info (f"Closed existing PR { pr_url } " )
125
+ pr . edit ( state = "closed" )
126
+ self .logger .info (f"Closed existing PR { pr . url } " )
153
127
if self .dry_run :
154
128
return
155
129
# Delete existing branch
@@ -168,21 +142,10 @@ def open_pr(self, message: str) -> None:
168
142
return
169
143
self .run (["git" , "push" , "origin" , self .branch ])
170
144
commit_title , _ , * commit_body = message .splitlines ()
171
- pr_url = self .run (
172
- [
173
- "gh" ,
174
- "pr" ,
175
- "create" ,
176
- "--title" ,
177
- commit_title .strip (),
178
- "--body-file" ,
179
- "-" ,
180
- "--base" ,
181
- "main" ,
182
- "--head" ,
183
- self .branch ,
184
- ],
185
- input = os .linesep .join (commit_body ).encode ("utf-8" ),
186
- capture_output = True ,
187
- ).stdout .decode ()
188
- self .logger .success (f"Opened PR { pr_url } " )
145
+ pr = self .repo .create_pull (
146
+ base = "main" ,
147
+ head = self .branch ,
148
+ title = commit_title .strip (),
149
+ body = os .linesep .join (commit_body ),
150
+ )
151
+ self .logger .success (f"Opened PR { pr .url } " )
0 commit comments