Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add function for creating repos
Tomas Valentaa21baa7a3bf1
diff --git a/components/Repos.tsx b/components/Repos.tsxindex de98c996e..ed515d283 100644--- a/components/Repos.tsx+++ b/components/Repos.tsx@@ -14,7 +14,7 @@ import TitleButton from 'components/TitleButton'import Input from 'components/Input'import SpinnerIcon from 'components/Spinner'import { useLocalStorage } from 'hooks/useLocalStorage'-import { parseRepoName } from 'github/repo'+import { createRepo, parseRepoName } from 'github/repo'export interface PostProjectBody {repositoryID: number@@ -44,6 +44,20 @@ function Repos({ onRepoSelection }: Props) {const { repos, refetch } = useRepositories(gitHub)const [query, setQuery] = useState<string>()++ async function createEmptyRepository(name: string) {+ if (!gitHub) return++ await createRepo({ client: gitHub, name })+ // When we refresh the list of repos now the new repo will be there+ // if we gave the GH App permissions to access all the personal repos or repos for the org++ refetch()+ }++++const searchEngine = useMemo(() => repos ?new Fuse(repos, {keys: ['full_name'],@@ -190,6 +204,10 @@ function Repos({ onRepoSelection }: Props) {</div>}</div>+ {<Button+ onClick={() => createEmptyRepository('new-repo-name')}+ text="Create Empty Repository"+ />}{accessToken &&<div className="flex justify-between"><TitleButtondiff --git a/github/repo.ts b/github/repo.tsindex d45a5a352..0a8928b2b 100644--- a/github/repo.ts+++ b/github/repo.ts@@ -1,4 +1,37 @@+import { GitHubClient } from './client'+export function parseRepoName(fullName: string) {const [owner, repo] = fullName.split('/')return { owner, repo }}++export async function createRepo({ client, name, org, isPrivate }: {+ client: GitHubClient,+ name: string,+ /**+ * If specifified the repo will be created in the org+ */+ org?: string,+ /**+ * If true the repo will be private+ */+ isPrivate?: boolean,+}) {+ if (org) {+ const { data } = await client.repos.createInOrg({+ org,+ name,+ private: isPrivate,+ auto_init: true,+ })+ return { repositoryID: data.id }+ }++ const { data } = await client.repos.createForAuthenticatedUser({+ name,+ private: isPrivate,+ auto_init: true,+ })++ return { repositoryID: data.id }+}