open-swe/apps/web/src/hooks/useGitHubApp.ts
Brace Sproul 887fc030a4
feat(agent-generated): Add github oauth (#63)
* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* Apply patch

* format and lint

* fix ui

* Apply patch (#68)

Co-authored-by: Harrison Chase <11986836+hwchase17@users.noreply.github.com>

* fix: Github auth

* update readme

* cr

* cr

* cr

* cr

---------

Co-authored-by: Harrison Chase <11986836+hwchase17@users.noreply.github.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
2025-06-02 01:30:29 +00:00

61 lines
1.5 KiB
TypeScript

import { useState, useEffect } from "react";
import { Repository } from "@/utils/github";
interface UseGitHubAppReturn {
isInstalled: boolean | null;
isLoading: boolean;
error: string | null;
repositories: Repository[];
refreshRepositories: () => Promise<void>;
}
export function useGitHubApp(): UseGitHubAppReturn {
const [isInstalled, setIsInstalled] = useState<boolean | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [repositories, setRepositories] = useState<Repository[]>([]);
const checkInstallation = async () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch("/api/github/repositories");
if (response.ok) {
const data = await response.json();
setRepositories(data.repositories || []);
setIsInstalled(true);
} else {
const errorData = await response.json();
if (errorData.error.includes("installation")) {
setIsInstalled(false);
} else {
setError(errorData.error);
setIsInstalled(false);
}
}
} catch (err) {
setError("Failed to check GitHub App installation status");
setIsInstalled(false);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
checkInstallation();
}, []);
const refreshRepositories = async () => {
await checkInstallation();
};
return {
isInstalled,
isLoading,
error,
repositories,
refreshRepositories,
};
}