Check if repo with same name already exists when creating project #18
@ -2,7 +2,7 @@ import { ReactNode } from 'react';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { SiweMessage, generateNonce } from 'siwe';
|
import { SiweMessage, generateNonce } from 'siwe';
|
||||||
import { WagmiProvider } from 'wagmi';
|
import { WagmiProvider } from 'wagmi';
|
||||||
import { arbitrum, mainnet } from 'wagmi/chains';
|
import { mainnet } from 'wagmi/chains';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import { createWeb3Modal } from '@web3modal/wagmi/react';
|
import { createWeb3Modal } from '@web3modal/wagmi/react';
|
||||||
@ -36,7 +36,7 @@ const metadata = {
|
|||||||
url: window.location.origin,
|
url: window.location.origin,
|
||||||
icons: ['https://avatars.githubusercontent.com/u/37784886'],
|
icons: ['https://avatars.githubusercontent.com/u/37784886'],
|
||||||
};
|
};
|
||||||
const chains = [mainnet, arbitrum] as const;
|
const chains = [mainnet] as const;
|
||||||
const config = defaultWagmiConfig({
|
const config = defaultWagmiConfig({
|
||||||
chains,
|
chains,
|
||||||
projectId: VITE_WALLET_CONNECT_ID,
|
projectId: VITE_WALLET_CONNECT_ID,
|
||||||
|
@ -41,6 +41,17 @@ const CreateRepo = () => {
|
|||||||
const [gitAccounts, setGitAccounts] = useState<string[]>([]);
|
const [gitAccounts, setGitAccounts] = useState<string[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const checkRepoExists = async (account: string, repoName: string) => {
|
||||||
|
try {
|
||||||
|
await octokit.rest.repos.get({ owner: account, repo: repoName });
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
// Error handled by octokit error hook interceptor in Octokit context
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const submitRepoHandler: SubmitHandler<SubmitRepoValues> = useCallback(
|
const submitRepoHandler: SubmitHandler<SubmitRepoValues> = useCallback(
|
||||||
async (data) => {
|
async (data) => {
|
||||||
assert(data.account);
|
assert(data.account);
|
||||||
@ -50,6 +61,18 @@ const CreateRepo = () => {
|
|||||||
assert(template.repoFullName, 'Template URL not provided');
|
assert(template.repoFullName, 'Template URL not provided');
|
||||||
const [owner, repo] = template.repoFullName.split('/');
|
const [owner, repo] = template.repoFullName.split('/');
|
||||||
|
|
||||||
|
const repoExists = await checkRepoExists(data.account, data.repoName);
|
||||||
|
if (repoExists) {
|
||||||
|
toast({
|
||||||
|
id: 'repo-exist-error',
|
||||||
|
title: 'Repository already exists with this name',
|
||||||
|
variant: 'warning',
|
||||||
|
onDismiss: dismiss,
|
||||||
|
});
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
navigate(
|
navigate(
|
||||||
@ -81,7 +104,7 @@ const CreateRepo = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[octokit],
|
[octokit, toast],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user