@@ -124,24 +124,13 @@ export function PullRequestMergeControls(props: {
124124 pending . current = true ;
125125 setBusy ( true ) ;
126126 return await ( async ( ) => {
127- const response = await runAction ( {
128- ...target ,
129- input : {
130- ...target . input ,
131- action,
127+ const response = await runAction ( {
128+ ...target ,
129+ input : {
130+ ...target . input ,
131+ action,
132132 ...( adminOverride ? { adminOverride : true , mergeMethod : method } : { } ) ,
133- ...( action === "merge" && method && stack . stack && scope
134- ? {
135- resolveMergeMethod : ( fresh ) => {
136- if (
137- ! canPerformPullRequestAction ( fresh , "merge" ) ||
138- ! allowedMergeMethods ( fresh ) . includes ( method )
139- )
140- throw new Error ( "The pull request changed. Refresh before merging." ) ;
141- return method ;
142- } ,
143- }
144- : action === "merge" && method && ! adminOverride
133+ ...( action === "merge" && method && stack . stack && scope
145134 ? {
146135 resolveMergeMethod : ( fresh ) => {
147136 if (
@@ -152,28 +141,39 @@ export function PullRequestMergeControls(props: {
152141 return method ;
153142 } ,
154143 }
155- : action === "enable-auto-merge" && method
156- ? { mergeMethod : method }
157- : { } ) ,
158- } ,
159- } ) ;
144+ : action === "merge" && method && ! adminOverride
145+ ? {
146+ resolveMergeMethod : ( fresh ) => {
147+ if (
148+ ! canPerformPullRequestAction ( fresh , "merge" ) ||
149+ ! allowedMergeMethods ( fresh ) . includes ( method )
150+ )
151+ throw new Error ( "The pull request changed. Refresh before merging." ) ;
152+ return method ;
153+ } ,
154+ }
155+ : action === "enable-auto-merge" && method
156+ ? { mergeMethod : method }
157+ : { } ) ,
158+ } ,
159+ } ) ;
160160 if ( response . _tag === "Failure" ) throw squashAtomCommandFailure ( response ) ;
161161 return true ;
162162 } ) ( )
163163 . catch ( async ( cause : unknown ) => {
164- Dialog . alert (
165- "Couldn't complete the merge action" ,
166- cause instanceof Error ? cause . message : "Try again." ,
167- ) ;
168- return false ;
164+ Dialog . alert (
165+ "Couldn't complete the merge action" ,
166+ cause instanceof Error ? cause . message : "Try again." ,
167+ ) ;
168+ return false ;
169169 } )
170170 . finally ( async ( ) => {
171- // A stack can partly merge before the provider reports a failure.
172- refreshDetail ( ) ;
173- refreshActivity ( ) ;
174- stack . refresh ( ) ;
175- pending . current = false ;
176- setBusy ( false ) ;
171+ // A stack can partly merge before the provider reports a failure.
172+ refreshDetail ( ) ;
173+ refreshActivity ( ) ;
174+ stack . refresh ( ) ;
175+ pending . current = false ;
176+ setBusy ( false ) ;
177177 } ) ;
178178 } ;
179179 const confirm = ( action : "merge" | "enable-auto-merge" | "disable-auto-merge" ) => {
@@ -375,10 +375,13 @@ export function PullRequestMergeControls(props: {
375375 : "Confirm merge"
376376 }
377377 tone = { bypass ? "danger" : "primary" }
378- disabled = { busy || ( ! bypass && ! canConfirmAutoMerge ) }
378+ disabled = { busy || ( ! bypass && ! canMerge && ! canConfirmAutoMerge ) }
379379 loading = { busy }
380380 onPress = { async ( ) => {
381- const completed = await perform ( bypass ? "merge" : "enable-auto-merge" , bypass ) ;
381+ const completed = await perform (
382+ bypass || ! canConfirmAutoMerge ? "merge" : "enable-auto-merge" ,
383+ bypass ,
384+ ) ;
382385 if ( completed ) setConfirmation ( null ) ;
383386 } }
384387 />
0 commit comments