-
Notifications
You must be signed in to change notification settings - Fork 1
Store and get selected repos on ticket to Atlassian storage #20
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
Conversation
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.
Hey @hiroshinishio - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
try { | ||
await invoke("storeRepo", { cloudId, projectId, issueId, value }); | ||
} catch (error) { | ||
console.error("Error saving repo:", error); |
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 user feedback for error cases
Silent failures can lead to confusion. Consider showing a notification or error message to the user when the save operation fails.
console.error("Error saving repo:", error);
toast.error("Failed to save repository. Please try again.");
@@ -28,8 +32,23 @@ resolver.define("getGithubRepos", async ({ payload }) => { | |||
if (!response.ok) throw new Error(`Failed to fetch repositories: ${response.status}`); |
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: Include response body in error message for better debugging
Consider including the response body in the error message to provide more context for debugging: const body = await response.text(); throw new Error(Failed to fetch repositories: ${response.status} - ${body}
);
if (!response.ok) throw new Error(`Failed to fetch repositories: ${response.status}`); | |
if (!response.ok) { | |
const body = await response.text(); | |
throw new Error(`Failed to fetch repositories: ${response.status} - ${body}`); | |
} |
import { invoke } from "@forge/bridge"; | ||
import ForgeReconciler, { Select, Text, useProductContext } from "@forge/react"; | ||
|
||
const App = () => { | ||
// Get Jira cloud ID (== workspace ID) | ||
const context = useProductContext(); |
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.
issue (complexity): Consider consolidating related state management and repository logic into dedicated custom hooks
The code can be simplified by combining related effects and extracting repository logic into a custom hook. Here's how:
- Combine context-related state management:
const useJiraContext = () => {
const context = useProductContext();
const [contextData, setContextData] = useState({
cloudId: null,
projectId: null,
issueId: null
});
useEffect(() => {
if (context) {
setContextData({
cloudId: context.cloudId,
projectId: context.extension.project.id,
issueId: context.extension.issue.id
});
}
}, [context]);
return contextData;
};
- Extract repository management into a custom hook:
const useRepositoryManagement = (cloudId, projectId, issueId) => {
const [githubRepos, setGithubRepos] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [selectedRepo, setSelectedRepo] = useState("");
useEffect(() => {
if (!cloudId || !projectId) return;
const loadData = async () => {
setIsLoading(true);
try {
const [repos, savedRepo] = await Promise.all([
invoke("getGithubRepos", { cloudId, projectId }),
invoke("getStoredRepo", { cloudId, projectId, issueId })
]);
setGithubRepos(repos.map(repo => `${repo.github_owner_name}/${repo.github_repo_name}`));
setSelectedRepo(savedRepo || "");
} catch (error) {
console.error("Error loading repository data:", error);
} finally {
setIsLoading(false);
}
};
loadData();
}, [cloudId, projectId, issueId]);
const handleRepoChange = async (value) => {
setSelectedRepo(value);
if (!cloudId || !projectId) return;
try {
await invoke("storeRepo", { cloudId, projectId, issueId, value });
} catch (error) {
console.error("Error saving repo:", error);
}
};
return { githubRepos, selectedRepo, isLoading, handleRepoChange };
};
This refactoring reduces complexity by:
- Combining related context effects into a single hook
- Centralizing repository management logic
- Reducing state management boilerplate
- Parallel loading of repository data
No description provided.