-
Notifications
You must be signed in to change notification settings - Fork 1
Emable to trigger GitAuto by checking the checkbox #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { invoke } from "@forge/bridge"; | ||
import ForgeReconciler, { Select, Text, useProductContext } from "@forge/react"; | ||
import ForgeReconciler, { Select, Text, useProductContext, Checkbox, Stack } from "@forge/react"; | ||
|
||
const App = () => { | ||
// Get Jira cloud ID (== workspace ID) | ||
|
@@ -75,8 +75,26 @@ const App = () => { | |
} | ||
}; | ||
|
||
// Handle checkbox | ||
const [isChecked, setIsChecked] = useState(false); | ||
const [isTriggering, setIsTriggering] = useState(false); | ||
const handleCheckboxChange = async (event) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
const checked = event.target.checked; | ||
setIsChecked(checked); | ||
if (!checked || !selectedRepo) return; | ||
setIsTriggering(true); | ||
try { | ||
await invoke("triggerGitAuto", { cloudId, projectId, issueId, selectedRepo }); | ||
} catch (error) { | ||
console.error("Error triggering GitAuto:", error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>
)} |
||
} finally { | ||
setIsTriggering(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
// https://developer.atlassian.com/platform/forge/ui-kit-2/stack/ | ||
<Stack space="space.075"> | ||
<Text>Target GitHub Repository:</Text> | ||
<Select | ||
value={selectedRepo} | ||
|
@@ -85,7 +103,14 @@ const App = () => { | |
isDisabled={isLoading} | ||
placeholder="Select a repository" | ||
/> | ||
</> | ||
<Checkbox | ||
label="Trigger GitAuto to open a pull request" | ||
onChange={handleCheckboxChange} | ||
value={isChecked} | ||
isDisabled={!selectedRepo || isTriggering} | ||
/> | ||
{isTriggering && <Text>Triggering GitAuto...</Text>} | ||
</Stack> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -51,4 +51,26 @@ resolver.define("storeRepo", async ({ payload }) => { | |||||||||||||||||||||||
return await storage.set(key, value); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
resolver.define("triggerGitAuto", async ({ payload }) => { | ||||||||||||||||||||||||
const { cloudId, projectId, issueId, selectedRepo } = payload; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Determine the API endpoint based on environment | ||||||||||||||||||||||||
const endpoint = process.env.GITAUTO_URL + "/webhook"; | ||||||||||||||||||||||||
console.log("Endpoint", endpoint); | ||||||||||||||||||||||||
const response = await forge.fetch(endpoint, { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||||||||
method: "POST", | ||||||||||||||||||||||||
headers: { "Content-Type": "application/json" }, | ||||||||||||||||||||||||
body: JSON.stringify({ | ||||||||||||||||||||||||
cloudId, | ||||||||||||||||||||||||
projectId, | ||||||||||||||||||||||||
issueId, | ||||||||||||||||||||||||
repository: selectedRepo, | ||||||||||||||||||||||||
}), | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (!response.ok) throw new Error(`Failed to trigger GitAuto: ${response.status}`); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return await response.json(); | ||||||||||||||||||||||||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export const handler = resolver.getDefinitions(); |
There was a problem hiding this comment.
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.