Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emable to trigger GitAuto by checking the checkbox #22

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Conversation

hiroshinishio
Copy link
Contributor

No description provided.

@hiroshinishio hiroshinishio merged commit b88e496 into main Dec 9, 2024
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch December 9, 2024 05:20
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @hiroshinishio - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding user-visible error handling instead of just console.error() when the GitAuto trigger fails
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

try {
await invoke("triggerGitAuto", { cloudId, projectId, issueId, selectedRepo });
} catch (error) {
console.error("Error triggering GitAuto:", error);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add user-visible error feedback instead of just logging to console

Consider adding an error state and displaying a message to the user when the operation fails

Suggested implementation:

  const [isChecked, setIsChecked] = useState(false);
  const [isTriggering, setIsTriggering] = useState(false);
  const [error, setError] = useState(null);
    setIsTriggering(true);
    setError(null);
    } catch (error) {
      console.error("Error triggering GitAuto:", error);
      setError("Failed to trigger GitAuto. Please try again or contact support if the problem persists.");
    <Stack space="space.075">
      {error && (
        <Text appearance="danger">
          {error}
        </Text>
      )}

// Determine the API endpoint based on environment
const endpoint = process.env.GITAUTO_URL + "/webhook";
console.log("Endpoint", endpoint);
const response = await forge.fetch(endpoint, {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider adding a timeout to the external API call

External API calls should have a reasonable timeout to prevent hanging operations

Suggested implementation:

  const response = await forge.fetch(endpoint, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    timeout: 10000, // 10 second timeout
=======

Note: If the forge.fetch implementation doesn't support the timeout option directly, you may need to implement the timeout using Promise.race() with a timeout promise. Let me know if you need that alternative implementation.

Comment on lines +71 to +73
if (!response.ok) throw new Error(`Failed to trigger GitAuto: ${response.status}`);

return await response.json();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Enhance error message with more context from the response

Include response body or more specific error details to help with debugging

Suggested change
if (!response.ok) throw new Error(`Failed to trigger GitAuto: ${response.status}`);
return await response.json();
if (!response.ok) {
const errorBody = await response.text();
throw new Error(
`Failed to trigger GitAuto: ${response.status} - ${response.statusText}\nResponse: ${errorBody}`
);
}
return await response.json();

forge variables set --encrypt SUPABASE_URL <value>
forge variables set --encrypt SUPABASE_API_KEY <value>
forge variables set --environment development --encrypt SUPABASE_URL <value>
forge variables set --environment development --encrypt SUPABASE_API_KEY <value>
```

For production, you have to do the following:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding the explicit commands for production environment variables

For consistency with the development section, consider adding the explicit commands for setting production variables using --environment production. This would make the documentation more complete and prevent any potential confusion.

// Handle checkbox
const [isChecked, setIsChecked] = useState(false);
const [isTriggering, setIsTriggering] = useState(false);
const handleCheckboxChange = async (event) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider flattening the control flow in the checkbox handler to improve code readability

The checkbox handling logic can be simplified by flattening the control flow while maintaining the same functionality. Here's a suggested refactor:

const handleCheckboxChange = async (event) => {
  const checked = event.target.checked;
  setIsChecked(checked);

  if (!checked || !selectedRepo) {
    setIsTriggering(false);
    return;
  }

  setIsTriggering(true);
  try {
    await invoke("triggerGitAuto", { 
      cloudId, 
      projectId, 
      issueId, 
      selectedRepo 
    });
  } catch (error) {
    console.error("Error triggering GitAuto:", error);
  }
  setIsTriggering(false);
};

This version:

  • Uses a single guard clause at the top
  • Removes the need for finally block by setting isTriggering directly
  • Maintains the same functionality with clearer flow control
  • Keeps necessary state management for UI feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant