feat: trigger git commit on approval in ChatScreen#108
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @jbdevprimary, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds functionality to trigger a real git commit when a user approves a 'commit' action in the chat screen. The implementation in handleApprovalResponse is a good start, but it contains a critical error handling issue with GitService calls and a high-severity issue regarding commit author information. I've provided a detailed comment with a code suggestion to address both problems, ensuring that git operations are handled robustly and commits have correct authorship. The other changes, including refactoring for activeThread, are well done.
| try { | ||
| // Find project path | ||
| const projectId = activeThread?.projectId; | ||
| const project = projectId ? projects.find((p) => p.id === projectId) : undefined; | ||
| const repoDir = project?.localPath; | ||
|
|
||
| if (!repoDir) { | ||
| Alert.alert('Error', 'No repository path found for project'); | ||
| return; | ||
| } | ||
|
|
||
| // Stage all changes | ||
| await GitService.stage({ dir: repoDir, filepath: '.' }); | ||
|
|
||
| // Commit | ||
| const author = { | ||
| name: userProfile?.name || userProfile?.login || 'User', | ||
| email: userProfile?.email || 'user@example.com', | ||
| }; | ||
|
|
||
| await GitService.commit({ | ||
| dir: repoDir, | ||
| message: approvalMsg.metadata.actionDescription || 'Commit from chat', | ||
| author, | ||
| }); | ||
|
|
||
| // Only mark as approved if commit succeeded | ||
| respondToApproval(messageId, activeThreadId, approved); | ||
| } catch (error) { | ||
| console.error('Failed to commit:', error); | ||
| Alert.alert('Commit Failed', error instanceof Error ? error.message : 'Unknown error'); | ||
| } |
There was a problem hiding this comment.
This block has a couple of significant issues:
-
Incorrect Error Handling (Critical):
GitServicemethods likestageandcommitdo not throw exceptions on failure. They return a result object like{ success: boolean, error?: string }. The currenttry...catchblock will not handle errors from these services, potentially leading to unexpected behavior where a failed stage or commit is treated as a success. -
Risky Commit Author (High): The code falls back to generic values like
'User'and'user@example.com'if the user's profile isn't fully loaded. This can lead to commits with incorrect or anonymous author information in the repository history, which is highly undesirable.
I've provided a suggestion that refactors this block to correctly handle GitService results and ensures a valid user profile exists before attempting to commit.
try {
// Find project path
const projectId = activeThread?.projectId;
const project = projectId ? projects.find((p) => p.id === projectId) : undefined;
const repoDir = project?.localPath;
if (!repoDir) {
Alert.alert('Error', 'No repository path found for project');
return;
}
if (!userProfile) {
Alert.alert('Error', 'User profile not loaded. Cannot create commit.');
return;
}
// Stage all changes
const stageResult = await GitService.stage({ dir: repoDir, filepath: '.' });
if (!stageResult.success) {
console.error('Failed to stage changes:', stageResult.error);
Alert.alert('Stage Failed', stageResult.error || 'An unknown error occurred.');
return;
}
// Commit
const author = {
name: userProfile.name || userProfile.login,
email: userProfile.email || `${userProfile.id}+${userProfile.login}@users.noreply.github.com`,
};
const commitResult = await GitService.commit({
dir: repoDir,
message: approvalMsg.metadata.actionDescription || 'Commit from chat',
author,
});
if (!commitResult.success) {
console.error('Failed to commit:', commitResult.error);
Alert.alert('Commit Failed', commitResult.error || 'An unknown error occurred.');
return;
}
// Only mark as approved if commit succeeded
respondToApproval(messageId, activeThreadId, approved);
} catch (error) {
console.error('An unexpected error occurred during commit process:', error);
Alert.alert('Error', error instanceof Error ? error.message : 'An unexpected error occurred.');
}
b772669 to
35d6634
Compare
- Replaced mocked 'Approve' action with `GitService` integration - Implemented `handleApprovalResponse` to handle commit approvals - Added staging and commit logic using `GitService` - Added error handling and user feedback via `Alert` - Updated imports to include `GitService` and `Alert` Co-authored-by: jbdevprimary <2650679+jbdevprimary@users.noreply.github.com>
35d6634 to
932df96
Compare
|


Implemented real git commit functionality in the ChatScreen approval flow. When a user approves a 'commit' action request, the application now stages all changes in the project's repository and creates a commit using the provided description and user profile. Added robust error handling and user feedback.
PR created automatically by Jules for task 12982100548334997176 started by @jbdevprimary