Skip to content

Commit

Permalink
fix: get the GitHub avatar from the api instead of the cache (#561)
Browse files Browse the repository at this point in the history
* feat: add the api to get the github avatar

* fix: close the issue #554
  • Loading branch information
xingwanying authored Dec 4, 2024
1 parent 9deebc1 commit e4ec98f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 3 additions & 2 deletions client/app/factory/edit/components/BotCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import InputList from './InputList';
import BulbIcon from '@/public/icons/BulbIcon';
import GitHubIcon from '@/public/icons/GitHubIcon';
import { random } from 'lodash';
import { useBotDelete } from '@/app/hooks/useBot';
import { useBotDelete, useGetGitAvatar } from '@/app/hooks/useBot';
import { ToastContainer, toast } from 'react-toastify';
import { useBot } from '@/app/contexts/BotContext';

Expand All @@ -37,6 +37,7 @@ import CreateButton from '@/app/user/tokens/components/CreateButton';

const BotCreateFrom = () => {
const { botProfile, setBotProfile } = useBot();
const { data: gitAvatar } = useGetGitAvatar(botProfile?.repoName);
const router = useRouter();
const { isOpen, onOpen, onOpenChange, onClose } = useDisclosure();
const { data: availableLLMs = [] } = useAvailableLLMs();
Expand Down Expand Up @@ -128,7 +129,7 @@ const BotCreateFrom = () => {
aria-label={I18N.components.BotCreateFrom.gITHU}
onClick={() => {
setBotProfile((draft: BotProfile) => {
draft.avatar = botProfile?.gitAvatar;
draft.avatar = gitAvatar;
});
}}
>
Expand Down
12 changes: 11 additions & 1 deletion client/app/hooks/useBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getBotInfoByRepoName,
getBotList,
getChunkList,
getGitAvatarByRepoName,
getRagTask,
getUserPeterCatAppRepos,
publicBot,
Expand Down Expand Up @@ -191,7 +192,16 @@ export const useGetUserPeterCatAppRepos = (enabled: boolean = true) => {
queryKey: ['github.user.app.repos'],
queryFn: async () => getUserPeterCatAppRepos(),
select: (data) => data.data,
enabled
enabled,
});
};

export const useGetGitAvatar = (repoName?: string) => {
return useQuery({
queryKey: ['github.repo.name', repoName],
queryFn: async () => getGitAvatarByRepoName(repoName!),
select: (data) => data.data.data,
enabled: !!repoName,
});
};

Expand Down
4 changes: 4 additions & 0 deletions client/app/services/BotsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export async function getBotInfoByRepoName(params: {
return axios.post(`${apiDomain}/api/bot/config/generator`, params);
}

export async function getGitAvatarByRepoName(repo_name: string) {
return axios.get(`${apiDomain}/api/bot/git/avatar?repo_name=${repo_name}`);
}

export async function getChunkList(
repo_name: string,
page_size: number,
Expand Down
16 changes: 16 additions & 0 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ async def bot_generator(
content={"success": False, "errorMessage": str(e)}, status_code=500
)

@router.get("/git/avatar", status_code=200)
async def get_git_avatar(
repo_name: str,
):
try:
g = Github()
repo = g.get_repo(repo_name)
avatar = repo.organization.avatar_url if repo.organization else None
return JSONResponse(content={"success": True, "data": avatar})
except Exception as e:
return JSONResponse(
content={"success": False, "errorMessage": str(e)}, status_code=500
)




@router.put("/update/{id}", status_code=200)
def update_bot(
Expand Down

0 comments on commit e4ec98f

Please sign in to comment.