Skip to content

Commit

Permalink
feat: github login (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai authored Aug 18, 2024
2 parents c5f4fd7 + d950c45 commit 64d18f9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/aws-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on:
push:
branches: ["main"]
paths:
- "server/**"
- server/**
pull_request:
branches: [ "main" ]
paths:
- server/**
- petercat_utils/**
- subscriber/**

env:
AWS_REGION: ap-northeast-1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"client:server": "concurrently \"yarn run server\" \"yarn run client\"",
"lui:server": "concurrently \"yarn run server\" \"yarn run lui\"",
"build:docker": "docker build -t petercat .",
"build:pip": "rm -rf dist && python3 -m build",
"build:pypi": "rm -rf dist && python3 -m build",
"publish:test": "python3 -m twine upload --repository petercat-utils dist/* ",
"publish:pypi": "python3 -m twine upload --repository pypi dist/* "
},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "petercat_utils"
version = "0.1.21"
version = "0.1.22"
description = ""
authors = ["raoha.rh <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 2 additions & 0 deletions server/auth/get_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async def getAnonymousUserInfoByToken(token: str):
return rows.data[0] if (len(rows.data) > 0) else None

async def get_user_access_token(petercat_user_token: Annotated[str | None, Cookie()] = None):
if petercat_user_token is None:
return None
user_info = await getUserInfoByToken(petercat_user_token)
access_token = await getUserAccessToken(user_id=user_info['id'])
print(f"get_user_access_token: user_info={user_info}, access_token={access_token}")
Expand Down
6 changes: 6 additions & 0 deletions server/tools/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import json

def need_github_login():
return json.dumps({
"error_info": "你必须先使用 GitHub 登录 petercat 才能使用此功能。 [登录地址](https://api.petercat.chat/api/auth/login)"
})
21 changes: 14 additions & 7 deletions server/tools/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
from github import Auth, Github
from langchain.tools import tool

DEFAULT_REPO_NAME = "ant-design/ant-design"

from tools.helper import need_github_login

def factory(access_token: str):
print(f"issue_factory: {access_token}")
auth = Auth.Token(token=access_token)
g = Github(auth=auth)
DEFAULT_REPO_NAME = "ant-design/ant-design"

def factory(access_token: Optional[str]):
@tool
def create_issue(repo_name, title, body):
"""
Create an issue in the specified GitHub repository.
Create an issue in the specified GitHub repository.If an error occurs during processing,
If user not login, it will return error mesesage and login url
Please invite user to login if got error
:param repo_name: The name of the repository, e.g., "ant-design/ant-design"
:param title: The title of the issue to be created
:param body: The content of the issue to be created
"""

if access_token is None:
return need_github_login()
auth = Auth.Token(token=access_token)
g = Github(auth=auth)
try:
# Get the repository object
repo = g.get_repo(repo_name)
Expand Down Expand Up @@ -49,6 +53,7 @@ def get_issues(
:param sort: The sorting method, e.g: created, updated, comments
:param order: The order of the sorting, e.g: asc, desc
"""
g = Github()
try:
# Obtain the repository object
repo = g.get_repo(repo_name)
Expand Down Expand Up @@ -86,6 +91,7 @@ def search_issues(
:param order: The order of the sorting, e.g: asc, desc
:param state: The state of the issue, e.g: open, closed, all
"""
g = Github()
try:
search_query = f"{keyword} in:title,body,comments repo:{repo_name}"
# Retrieve a list of open issues from the repository
Expand All @@ -103,6 +109,7 @@ def search_issues(
except Exception as e:
print(f"An error occurred: {e}")
return json.dumps([])

return {
"create_issue": create_issue,
"get_issues": get_issues,
Expand Down

0 comments on commit 64d18f9

Please sign in to comment.