@@ -23,7 +23,6 @@ import {
2323import * as Cause from "effect/Cause" ;
2424import * as Option from "effect/Option" ;
2525import { AsyncResult } from "effect/reactivity" ;
26- import { useCallback } from "react" ;
2726
2827import { appAtomRegistry } from "../rpc/atomRegistry" ;
2928import { gitEnvironment } from "./git" ;
@@ -87,48 +86,45 @@ function useAction<
8786 const state = useAtomValue ( vcsActionManager . stateAtom ( input . scope ) ) ;
8887 const ownsState = state . operation === operation ;
8988
90- const resetError = useCallback ( ( ) => {
89+ const resetError = ( ) => {
9190 vcsActionManager . resetError ( appAtomRegistry , input . scope , operation ) ;
92- } , [ input . scope , operation ] ) ;
91+ } ;
9392
94- const run = useCallback (
95- async ( ...args : TArgs ) => {
96- if (
97- input . scope . environmentId === null ||
98- ! readEnvironmentScope ( input . scope . environmentId , AuthSourceControlWriteScope )
99- ) {
100- return AsyncResult . failure < never , EnvironmentAuthorizationError > (
101- Cause . fail (
102- new EnvironmentAuthorizationError ( {
103- requiredScope : AuthSourceControlWriteScope ,
104- message : "This connection cannot change source control." ,
105- } ) ,
106- ) ,
107- ) ;
93+ const run = async ( ...args : TArgs ) => {
94+ if (
95+ input . scope . environmentId === null ||
96+ ! readEnvironmentScope ( input . scope . environmentId , AuthSourceControlWriteScope )
97+ ) {
98+ return AsyncResult . failure < never , EnvironmentAuthorizationError > (
99+ Cause . fail (
100+ new EnvironmentAuthorizationError ( {
101+ requiredScope : AuthSourceControlWriteScope ,
102+ message : "This connection cannot change source control." ,
103+ } ) ,
104+ ) ,
105+ ) ;
106+ }
107+ const execute = async ( ) : Promise <
108+ AtomCommandResult < AtomCommandSuccess < R > , AtomCommandFailure < R > >
109+ > => {
110+ const result = await input . action ( ...args ) ;
111+ if ( AsyncResult . isSuccess ( result ) ) {
112+ input . onSuccess ?.( ) ;
108113 }
109- const execute = async ( ) : Promise <
110- AtomCommandResult < AtomCommandSuccess < R > , AtomCommandFailure < R > >
111- > => {
112- const result = await input . action ( ...args ) ;
113- if ( AsyncResult . isSuccess ( result ) ) {
114- input . onSuccess ?.( ) ;
115- }
116- return result as AtomCommandResult < AtomCommandSuccess < R > , AtomCommandFailure < R > > ;
117- } ;
118- return input . managedExternally === true
119- ? execute ( )
120- : vcsActionManager . track (
121- appAtomRegistry ,
122- input . scope ,
123- {
124- operation,
125- label : input . label ,
126- } ,
127- execute ,
128- ) ;
129- } ,
130- [ input . action , input . label , input . managedExternally , input . onSuccess , input . scope , operation ] ,
131- ) ;
114+ return result as AtomCommandResult < AtomCommandSuccess < R > , AtomCommandFailure < R > > ;
115+ } ;
116+ return input . managedExternally === true
117+ ? execute ( )
118+ : vcsActionManager . track (
119+ appAtomRegistry ,
120+ input . scope ,
121+ {
122+ operation,
123+ label : input . label ,
124+ } ,
125+ execute ,
126+ ) ;
127+ } ;
132128
133129 return {
134130 isAllowed,
@@ -163,7 +159,7 @@ export function useSourceControlActionRunning(
163159
164160export function useVcsInitAction ( scope : SourceControlActionScope ) {
165161 const init = useAtomCommand ( vcsEnvironment . init , { reportFailure : false } ) ;
166- const action = useCallback ( async ( ) => {
162+ const action = async ( ) => {
167163 const target = resolveScope ( scope ) ;
168164 if ( target === null ) {
169165 return AsyncResult . failure < never , VcsActionUnavailableError > (
@@ -180,7 +176,7 @@ export function useVcsInitAction(scope: SourceControlActionScope) {
180176 environmentId : target . environmentId ,
181177 input : { cwd : target . cwd } ,
182178 } ) ;
183- } , [ init , scope ] ) ;
179+ } ;
184180 return useAction ( { kind : "init" , label : "Initializing repository" , scope, action } ) ;
185181}
186182
@@ -194,7 +190,7 @@ export function useVcsPullAction(scope: SourceControlActionScope) {
194190 } )
195191 : null ,
196192 ) ;
197- const action = useCallback ( async ( ) => {
193+ const action = async ( ) => {
198194 const target = resolveScope ( scope ) ;
199195 if ( target === null ) {
200196 return AsyncResult . failure < never , VcsActionUnavailableError > (
@@ -211,7 +207,7 @@ export function useVcsPullAction(scope: SourceControlActionScope) {
211207 environmentId : target . environmentId ,
212208 input : { cwd : target . cwd } ,
213209 } ) ;
214- } , [ pull , scope ] ) ;
210+ } ;
215211 return useAction ( {
216212 kind : "pull" ,
217213 label : "Pulling latest changes..." ,
@@ -234,23 +230,20 @@ export function useGitStackedAction(scope: SourceControlActionScope) {
234230 : null ,
235231 ) ;
236232
237- const action = useCallback (
238- async ( input : RunVcsStackedActionInput ) => {
239- if ( resolveScope ( scope ) === null ) {
240- return AsyncResult . failure < never , VcsActionUnavailableError > (
241- Cause . fail (
242- new VcsActionUnavailableError ( {
243- operation : "run_change_request" ,
244- environmentId : scope . environmentId ,
245- cwd : scope . cwd ,
246- } ) ,
247- ) ,
248- ) ;
249- }
250- return runStackedAction ( input ) ;
251- } ,
252- [ runStackedAction , scope ] ,
253- ) ;
233+ const action = async ( input : RunVcsStackedActionInput ) => {
234+ if ( resolveScope ( scope ) === null ) {
235+ return AsyncResult . failure < never , VcsActionUnavailableError > (
236+ Cause . fail (
237+ new VcsActionUnavailableError ( {
238+ operation : "run_change_request" ,
239+ environmentId : scope . environmentId ,
240+ cwd : scope . cwd ,
241+ } ) ,
242+ ) ,
243+ ) ;
244+ }
245+ return runStackedAction ( input ) ;
246+ } ;
254247
255248 return useAction ( {
256249 kind : "runStackedAction" ,
@@ -274,36 +267,33 @@ export function useSourceControlPublishRepositoryAction(scope: SourceControlActi
274267 } )
275268 : null ,
276269 ) ;
277- const action = useCallback (
278- async ( input : {
279- provider : SourceControlProviderKind ;
280- repository : string ;
281- visibility : SourceControlRepositoryVisibility ;
282- remoteName : string ;
283- protocol : SourceControlCloneProtocol ;
284- } ) => {
285- const target = resolveScope ( scope ) ;
286- if ( target === null ) {
287- return AsyncResult . failure < never , VcsActionUnavailableError > (
288- Cause . fail (
289- new VcsActionUnavailableError ( {
290- operation : "publish_repository" ,
291- environmentId : scope . environmentId ,
292- cwd : scope . cwd ,
293- } ) ,
294- ) ,
295- ) ;
296- }
297- return publishRepository ( {
298- environmentId : target . environmentId ,
299- input : {
300- cwd : target . cwd ,
301- ...input ,
302- } ,
303- } ) ;
304- } ,
305- [ publishRepository , scope ] ,
306- ) ;
270+ const action = async ( input : {
271+ provider : SourceControlProviderKind ;
272+ repository : string ;
273+ visibility : SourceControlRepositoryVisibility ;
274+ remoteName : string ;
275+ protocol : SourceControlCloneProtocol ;
276+ } ) => {
277+ const target = resolveScope ( scope ) ;
278+ if ( target === null ) {
279+ return AsyncResult . failure < never , VcsActionUnavailableError > (
280+ Cause . fail (
281+ new VcsActionUnavailableError ( {
282+ operation : "publish_repository" ,
283+ environmentId : scope . environmentId ,
284+ cwd : scope . cwd ,
285+ } ) ,
286+ ) ,
287+ ) ;
288+ }
289+ return publishRepository ( {
290+ environmentId : target . environmentId ,
291+ input : {
292+ cwd : target . cwd ,
293+ ...input ,
294+ } ,
295+ } ) ;
296+ } ;
307297 return useAction ( {
308298 kind : "publishRepository" ,
309299 label : "Publishing repository" ,
@@ -317,46 +307,47 @@ export function usePreparePullRequestThreadAction(scope: SourceControlActionScop
317307 const preparePullRequestThread = useAtomCommand ( gitEnvironment . preparePullRequestThread , {
318308 reportFailure : false ,
319309 } ) ;
320- const action = useCallback (
321- async ( input : { reference : string ; mode : "local" | "worktree" ; threadId ?: ThreadId } ) => {
322- const target = resolveScope ( scope ) ;
323- if ( target === null ) {
324- return AsyncResult . failure < never , VcsActionUnavailableError > (
325- Cause . fail (
326- new VcsActionUnavailableError ( {
327- operation : "prepare_pull_request_thread" ,
328- environmentId : scope . environmentId ,
329- cwd : scope . cwd ,
330- } ) ,
331- ) ,
332- ) ;
333- }
334- if (
335- input . mode === "worktree" &&
336- input . threadId !== undefined &&
337- ! readEnvironmentScope ( target . environmentId , AuthOrchestrationOperateScope )
338- ) {
339- return AsyncResult . failure < never , EnvironmentAuthorizationError > (
340- Cause . fail (
341- new EnvironmentAuthorizationError ( {
342- requiredScope : AuthOrchestrationOperateScope ,
343- message : "This connection cannot change threads." ,
344- } ) ,
345- ) ,
346- ) ;
347- }
348- return preparePullRequestThread ( {
349- environmentId : target . environmentId ,
350- input : {
351- cwd : target . cwd ,
352- reference : input . reference ,
353- mode : input . mode ,
354- ...( input . threadId ? { threadId : input . threadId } : { } ) ,
355- } ,
356- } ) ;
357- } ,
358- [ preparePullRequestThread , scope ] ,
359- ) ;
310+ const action = async ( input : {
311+ reference : string ;
312+ mode : "local" | "worktree" ;
313+ threadId ?: ThreadId ;
314+ } ) => {
315+ const target = resolveScope ( scope ) ;
316+ if ( target === null ) {
317+ return AsyncResult . failure < never , VcsActionUnavailableError > (
318+ Cause . fail (
319+ new VcsActionUnavailableError ( {
320+ operation : "prepare_pull_request_thread" ,
321+ environmentId : scope . environmentId ,
322+ cwd : scope . cwd ,
323+ } ) ,
324+ ) ,
325+ ) ;
326+ }
327+ if (
328+ input . mode === "worktree" &&
329+ input . threadId !== undefined &&
330+ ! readEnvironmentScope ( target . environmentId , AuthOrchestrationOperateScope )
331+ ) {
332+ return AsyncResult . failure < never , EnvironmentAuthorizationError > (
333+ Cause . fail (
334+ new EnvironmentAuthorizationError ( {
335+ requiredScope : AuthOrchestrationOperateScope ,
336+ message : "This connection cannot change threads." ,
337+ } ) ,
338+ ) ,
339+ ) ;
340+ }
341+ return preparePullRequestThread ( {
342+ environmentId : target . environmentId ,
343+ input : {
344+ cwd : target . cwd ,
345+ reference : input . reference ,
346+ mode : input . mode ,
347+ ...( input . threadId ? { threadId : input . threadId } : { } ) ,
348+ } ,
349+ } ) ;
350+ } ;
360351 return useAction ( {
361352 kind : "preparePullRequestThread" ,
362353 label : "Preparing pull request thread" ,
0 commit comments