Skip to content

Commit

Permalink
feat(deploy): 支持显示部署issue地址 & 获取审批情况时检查 issue 状态并同步数据表
Browse files Browse the repository at this point in the history
  • Loading branch information
ch-liuzhide committed Nov 26, 2024
1 parent 4d38f26 commit 4de16c2
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 14 deletions.
41 changes: 36 additions & 5 deletions client/app/factory/edit/components/DeployBotModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
} = useBindBotToRepo();
const {
publicBot,
data: publicBotResult,
isLoading: isPublicBotLoading,
isSuccess: isPublicBotSuccess,
} = usePublicBot();
Expand All @@ -51,6 +52,7 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
} = useUnPublicBot();
const {
deployWebsite,
data: deployWebsiteResult,
isLoading: isDeployWebsiteLoading,
isSuccess: isDeployWebsiteSuccess,
} = useDeployWebsite();
Expand All @@ -75,10 +77,11 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
checked: !!botProfile.domain_whitelist[0],
targetUrl: botProfile.domain_whitelist[0],
},
appInstalledRepo: peterCatBotRepos?.map((item: any) => ({
repo_id: item.repo_id,
checked: item.robot_id === botProfile.id,
}))??[],
appInstalledRepo:
peterCatBotRepos?.map((item: any) => ({
repo_id: item.repo_id,
checked: item.robot_id === botProfile.id,
})) ?? [],
};
}, [botProfile, peterCatBotRepos]);

Expand Down Expand Up @@ -148,6 +151,24 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
isDeployWebsiteSuccess ||
isBindBotSuccess;

const renderResultPath = (result: { approval_path: any }, text: string) => {
return (
<>
{result?.approval_path ? (
<div className="w-full flex flex-col gap-1 justify-center items-center">
<span>
{text}
{I18N.DeployBotModal.DeployContent.shenHeZhong}
</span>
<a href={result.approval_path} target="_blank" className="block max-w-full break-words">
{result.approval_path}
</a>
</div>
) : null}
</>
);
};

return (
<>
<Modal
Expand All @@ -169,6 +190,16 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
<span>{I18N.DeployBotModal.index.buShuChengGong}</span>
</div>
</ModalHeader>
<ModalBody className="py-[0px] flex flex-col gap-2 justify-center items-center">
{renderResultPath(
publicBotResult,
I18N.DeployBotModal.DeployContent.gongKaiDaoPE,
)}
{renderResultPath(
deployWebsiteResult,
I18N.DeployBotModal.DeployContent.buShuDaoWoDe,
)}
</ModalBody>
<ModalFooter className="flex justify-center items-center">
<Button
className="border-[1.5px] border-[#3F3F46] rounded-[46px] bg-[#3F3F46] text-white"
Expand Down Expand Up @@ -196,7 +227,7 @@ const MyBotDeployModal: React.FC<IModalProps> = ({ isOpen, onClose }) => {
deployInfo={deployInfo}
websiteApproval={websiteApproval}
marketApproval={marketApproval}
peterCatBotRepos={peterCatBotRepos??[]}
peterCatBotRepos={peterCatBotRepos ?? []}
onChange={handleDeployChange}
/>
</Spinner>
Expand Down
4 changes: 2 additions & 2 deletions client/app/hooks/useBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function usePublicBot() {
mutationFn: publicBot,
});
return {
data: mutation.data,
data: mutation.data?.data,
publicBot: mutation.mutate,
isLoading: mutation.isPending,
error: mutation.error,
Expand All @@ -178,7 +178,7 @@ export function useDeployWebsite() {
mutationFn: deployWebsite,
});
return {
data: mutation.data,
data: mutation.data?.data,
deployWebsite: mutation.mutate,
isLoading: mutation.isPending,
error: mutation.error,
Expand Down
2 changes: 0 additions & 2 deletions client/app/market/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import FullPageSkeleton from '@/components/FullPageSkeleton';
import { useGlobal } from '@/app/contexts/GlobalContext';
import { Assistant } from '@petercatai/assistant';
import { useFingerprint } from '../hooks/useFingerprint';
import PublishBotEntity from '@/components/PublishBotEntity';
import Crash from '@/components/Crash';

declare type Bot = Tables<'bots'>;
Expand Down Expand Up @@ -67,7 +66,6 @@ export default function Market() {
return (
<div>
<div className="grid grid-flow-row-dense gap-8 justify-items-center px-[40px] grid-cols-2 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
{/* <PublishBotEntity area="list" /> */}
{!isEmpty(bots) &&
map(bots, (bot: Bot) => (
<BotCard key={bot.id} bot={bot} handleCardClick={handleCardClick} />
Expand Down
21 changes: 19 additions & 2 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,32 @@ def get_bot_approval_config(
status: Optional[ApprovalStatus] = Query(
None, description="approval status ,open or closed"
),
user: Annotated[User | None, Depends(get_user)] = None,
):
try:
bot_approval_dao = BotApprovalDAO()
(success, data) = bot_approval_dao.query_by_bot_id(bot_id)
(success, data) = bot_approval_dao.query(bot_id, status.value)
if not success:
raise ValueError(data)
# filter data by status
if status:
data = list(filter(lambda x: x["approval_status"] == status.value, data))
auth = Auth.Token(token=user.access_token)
g = Github(auth=auth)
repo = g.get_repo(OFFICIAL_REPO)
for item in data:
if not item["approval_path"]:
continue
issue_num = int(item["approval_path"].split("/")[-1])
issue = repo.get_issue(issue_num)
if issue.state == "closed":
item["approval_status"] = ApprovalStatus.CLOSED
# update approval status to closed
bot_approval_dao.update_approval_status(
item["id"], ApprovalStatus.CLOSED.value
)
# filter again
data = list(filter(lambda x: x["approval_status"] == status.value, data))
# check data item issue is closed
return {"data": data, "status": 200}
except Exception as e:
return JSONResponse(content={"success": False, "errorMessage": e})
19 changes: 18 additions & 1 deletion server/core/dao/botApprovalDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def create(self, data: BotApproval):
print("Error: ", e)
return False, {"message": "approval creation failed"}

def query_by_bot_id(self, bot_id: str):
def query(self, bot_id: str, status: str):
try:
bot_approval = (
self.client.table("bot_approval")
.select("*")
.eq("bot_id", bot_id)
.eq("approval_status", status)
.execute()
)
if bot_approval:
Expand All @@ -42,3 +43,19 @@ def query_by_bot_id(self, bot_id: str):
except Exception as e:
print("Error: ", e)
return False, {"message": "approval query failed"}

def update_approval_status(self, id: str, status: str):
try:
bot_approval = (
self.client.table("bot_approval")
.update({"approval_status": status})
.eq("id", id)
.execute()
)
if bot_approval:
return True, {"message": "approval updated successfully"}
else:
return False, {"message": "approval update failed"}
except Exception as e:
print("Error: ", e)
return False, {"message": "approval update failed"}
3 changes: 2 additions & 1 deletion server/github_app/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
get_installation_repositories,
get_jwt,
get_private_key,
get_user_orgs,
)

from petercat_utils import get_env_variable
Expand Down Expand Up @@ -145,7 +146,7 @@ def get_user_repos_installed_app_(
auth = Auth.Token(token=user.access_token)
g = Github(auth=auth)
github_user = g.get_user()
orgs = github_user.get_orgs()
orgs = get_user_orgs(github_user.login, auth.token)
repository_config_dao = RepositoryConfigDAO()
installations = repository_config_dao.query_by_owners(
[org.id for org in orgs] + [github_user.id]
Expand Down
13 changes: 13 additions & 0 deletions server/github_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ 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()
2 changes: 1 addition & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ langserve
langchain_community>=0.2.11
langchain>=0.2.12
langchain_google_genai
PyGithub==2.3.0
PyGithub
GitPython
python-multipart
httpx[socks]
Expand Down

0 comments on commit 4de16c2

Please sign in to comment.