Skip to content
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

feat: enable collaboration for the same git org #585

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/app/hooks/useBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const useBotDetail = (id: string) => {
});
};

export const useGetBotBoundRepos =(id:string)=>{
export const useGetBotBoundRepos = (id: string) => {
return useQuery({
queryKey: [`bot.boundRepos.${id}`, id],
queryFn: async () => getBotBoundRepos(id),
select: (data) => data,
enabled: !!id,
retry: false,
});
}
};

export const useBotConfig = (id: string, enabled: boolean) => {
return useQuery({
Expand Down Expand Up @@ -153,7 +153,7 @@ export const useGetBotRagTask = (
queryKey: [`rag.task`, repoName],
queryFn: async () => getRagTask(repoName),
select: (data) => data,
enabled:!!repoName,
enabled: !!repoName,
retry: true,
refetchInterval: refetchInterval ? 3 * 1000 : undefined,
});
Expand Down
1 change: 0 additions & 1 deletion server/auth/router.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from github import Github

Check failure on line 1 in server/auth/router.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

auth/router.py:1:8: F401 `json` imported but unused
from core.dao.profilesDAO import ProfilesDAO
from fastapi import APIRouter, Request, HTTPException, status, Depends
from fastapi.responses import RedirectResponse, JSONResponse
Expand Down
50 changes: 34 additions & 16 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,50 @@ def get_bot_list(
None, description="Filter bots by personal category"
),
name: Optional[str] = Query(None, description="Filter bots by name"),
user_id: Annotated[str | None, Depends(get_user_id)] = None,
user: Annotated[User | None, Depends(get_user)] = None,
):
try:
supabase = get_client()
query = supabase.table("bots").select(
"id, created_at, updated_at, avatar, description, name, public, starters, uid, repo_name"
)
if personal == "true":
if not user_id:
if not user or not user.access_token:
return {"data": [], "personal": personal}
query = query.eq("uid", user_id).order("updated_at", desc=True)
if name:
user_id = user.id
auth = Auth.Token(token=user.access_token)
g = Github(auth=auth)
github_user = g.get_user()
orgs = github_user.get_orgs()
repository_config_dao = RepositoryConfigDAO()
bots = repository_config_dao.query_bot_id_by_owners(
[org.id for org in orgs] + [github_user.id]
)
bot_ids = [bot["robot_id"] for bot in bots if bot["robot_id"]]
bot_ids_str = ",".join(map(str, bot_ids)) # 将 bots ID 列表转换为字符串

or_clause = (
f"uid.eq.{user_id},id.in.({bot_ids_str})"
if bot_ids_str
else f"uid.eq.{user_id}"
)

# 添加过滤条件
query = (
supabase.table("bots")
.select(
"id, created_at, updated_at, avatar, description, name, public, starters, uid, repo_name"
)
query.or_(or_clause).order("updated_at", desc=True)
if not name
else query.or_(or_clause)
.filter("name", "like", f"%{name}%")
.order("updated_at", desc=True)
)
else:
query = (
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
query.eq("public", True).order("updated_at", desc=True)
if not name
else query.eq("public", True)
.filter("name", "like", f"%{name}%")
.order("updated_at", desc=True)
)

query = (
query.eq("public", True).order("updated_at", desc=True)
if not personal or personal != "true"
else query
)

data = query.execute()
if not data or not data.data:
Expand Down Expand Up @@ -186,6 +205,7 @@ 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,
Expand All @@ -201,8 +221,6 @@ async def get_git_avatar(
)




@router.put("/update/{id}", status_code=200)
def update_bot(
id: str,
Expand Down
Empty file removed server/bot/util.ts
Empty file.
13 changes: 13 additions & 0 deletions server/core/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def query_by_owners(self, orgs: List[str]):
print(f"Error: {e}")
return None

def query_bot_id_by_owners(self, orgs: List[str]):
try:
response = (
self.client.table("github_repo_config")
.select("robot_id")
.filter("owner_id", "in", f"({','.join(map(str, orgs))})")
.execute()
)
return response.data
except Exception as e:
print(f"Error: {e}")
return None

def update_bot_to_repos(self, repos: List[RepoBindBotConfigVO]) -> bool:
try:
for repo in repos:
Expand Down
13 changes: 0 additions & 13 deletions server/github_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,3 @@ def get_installation_repositories(access_token: str):
},
)
return resp.json()


def get_user_orgs(username, access_token: str):
url = f"https://api.github.com/users/{username}/orgs"
resp = requests.get(
url,
headers={
"X-GitHub-Api-Version": "2022-11-28",
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {access_token}",
},
)
return resp.json()
Loading