MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / useCommitChanges

Function useCommitChanges

src/hooks/query/use-commit-changes.ts:13–60  ·  view source on GitHub ↗
(
  sha: string,
  config: UseCommitChangesConfig,
)

Source from the content-addressed store, hash-verified

11};
12
13export const useCommitChanges = (
14 sha: string,
15 config: UseCommitChangesConfig,
16) => {
17 const { conversationId } = useConversationId();
18 const { data: conversation } = useActiveConversation();
19 const runtimeIsReady = useRuntimeIsReady();
20
21 const conversationUrl = conversation?.conversation_url;
22 const sessionApiKey = conversation?.session_api_key;
23 const selectedRepository = conversation?.selected_repository;
24 const workingDir = conversation?.workspace?.working_dir?.trim();
25
26 const gitPath = React.useMemo(
27 () => getGitPath(selectedRepository, workingDir),
28 [selectedRepository, workingDir],
29 );
30
31 return useQuery({
32 queryKey: [
33 "commit_changes",
34 conversationId,
35 conversationUrl,
36 sessionApiKey,
37 gitPath,
38 sha,
39 ],
40 queryFn: async () => {
41 if (!conversationId) throw new Error("No conversation ID");
42
43 return AgentServerGitService.getCommitChanges(
44 conversationUrl,
45 sessionApiKey,
46 gitPath,
47 sha,
48 );
49 },
50 // A commit's change list is sha-addressed and immutable — never stale,
51 // and deliberately not invalidated by the bash-observation refresh.
52 staleTime: Infinity,
53 gcTime: 1000 * 60 * 15, // 15 minutes
54 retry: false,
55 enabled: config.enabled && runtimeIsReady && !!conversationId,
56 meta: {
57 disableToast: true,
58 },
59 });
60};

Callers 1

CommitRowFunction · 0.90

Calls 5

useConversationIdFunction · 0.90
useActiveConversationFunction · 0.90
useRuntimeIsReadyFunction · 0.90
getGitPathFunction · 0.90
getCommitChangesMethod · 0.80

Tested by

no test coverage detected