Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/petercat-ai/petercat into f…
Browse files Browse the repository at this point in the history
…ixlogin
  • Loading branch information
ch-liuzhide committed Jan 21, 2025
2 parents b650403 + 2c53b08 commit 4f8f5bf
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 19 deletions.
1 change: 1 addition & 0 deletions assistant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"lint-staged": "^13.0.3",
"postcss": "^8.4.49",
"postcss-cli": "^11.0.0",
"postcss-nested": "^7.0.2",
"postcss-prefix-selector": "^2.1.0",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion assistant/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer')
require('autoprefixer'),
require("postcss-nested"),
]
};
2 changes: 1 addition & 1 deletion assistant/src/Assistant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Assistant = (props: AssistantProps) => {
);

return (
<div className="petercat-assitant fixed" style={{ zIndex: 9999 }}>
<div className="petercat-assistant fixed" style={{ zIndex: 9999 }}>
<div
className={cls}
style={{
Expand Down
2 changes: 1 addition & 1 deletion assistant/src/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ const Chat: FC<ChatProps> = memo(
// ============================ Render ============================
return (
<div
className="petercat-assitant bg-[#FCFCFC] pt-2"
className="petercat-assistant bg-[#FCFCFC] pt-2"
style={{
...style,
minWidth: drawerWidth,
Expand Down
2 changes: 1 addition & 1 deletion assistant/src/GitInsight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const GitInsight = (props: GitInsightProps) => {
}, []);

return (
<div className="petercat-assitant">
<div className="petercat-assistant">
<div className="flex justify-start items-center">
<div className="opacity-0 transform transition-opacity duration-500 delay-200 animate-fade-in">
<MemoizedCountCard type="star" count={starCount} />
Expand Down
2 changes: 1 addition & 1 deletion assistant/src/StarterList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IProps {

const StarterList: FC<IProps> = ({ starters, onClick, style, className }) => {
return (
<div className="petercat-assitant">
<div className="petercat-assistant">
<div
className={`flex flex-col flex-wrap gap-2 items-start ${className}`}
style={style}
Expand Down
2 changes: 1 addition & 1 deletion assistant/src/ThoughtChain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const ThoughtChain: React.FC<ThoughtChainProps> = (params) => {
}, []);

return (
<div className="petercat-assitant">
<div className="petercat-assistant">
<Collapse
size="small"
items={items}
Expand Down
28 changes: 15 additions & 13 deletions assistant/tailwind.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@tailwind utilities;
.petercat-assistant {
@tailwind utilities;
}

/* animations.css */

Expand Down Expand Up @@ -79,59 +81,59 @@
}

/* Shake Animation Class */
.petercat-assitant .animate-shake {
.petercat-assistant .animate-shake {
animation: shake 15s infinite;
}

/* Fade In Class */
.petercat-assitant .animate-fade-in {
.petercat-assistant .animate-fade-in {
animation: fadeIn 0.5s ease-in forwards;
}

/* Fade In Left Class */
.petercat-assitant .animate-fade-in-left {
.petercat-assistant .animate-fade-in-left {
animation: fadeInLeft 0.5s ease-out forwards;
}

.petercat-assitant .lui-input-area #question {
.petercat-assistant .lui-input-area #question {
box-shadow: none;
}

.petercat-assitant .chat_item_container {
.petercat-assistant .chat_item_container {
position: relative;
width: 100%;
max-width: 100vw;
padding: 16px;
content-visibility: auto;
contain-intrinsic-size: 100px;
}
.petercat-assitant .petercat-avatar {
.petercat-assistant .petercat-avatar {
flex: 0 0 40px;
}
.petercat-assitant .petercat-avatar .ant-avatar {
.petercat-assistant .petercat-avatar .ant-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
}
.petercat-assitant .petercat-header {
.petercat-assistant .petercat-header {
font-size: 12px !important;
line-height: 1 !important;
color: rgba(0, 0, 0, 0.45) !important;
}

.petercat-assitant .petercat-content-start {
.petercat-assistant .petercat-content-start {
padding: 8px 16px 8px 16px !important;
border-radius: 16px !important;
background: rgba(241, 241, 241, 1) !important;
}

.petercat-assitant .petercat-content-end {
.petercat-assistant .petercat-content-end {
padding: 8px 16px 8px 16px !important;
border-radius: 16px !important;
background: rgba(250, 228, 203, 1) !important;
}

.petercat-assitant .ant-bubble-content {
.petercat-assistant .ant-bubble-content {
min-height: 0 !important;
}

Expand All @@ -141,7 +143,7 @@
line-height: 2;

p {
margin: 0;
margin: 0 !important;
}


Expand Down
7 changes: 7 additions & 0 deletions assistant/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12165,6 +12165,13 @@ postcss-nested@^6.2.0:
dependencies:
postcss-selector-parser "^6.1.1"

postcss-nested@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/postcss-nested/-/postcss-nested-7.0.2.tgz#863d83a6b5df0a2894560394be93d5383ea37a65"
integrity sha512-5osppouFc0VR9/VYzYxO03VaDa3e8F23Kfd6/9qcZTUI8P58GIYlArOET2Wq0ywSl2o2PjELhYOFI4W7l5QHKw==
dependencies:
postcss-selector-parser "^7.0.0"

postcss-nesting@^10.1.4:
version "10.2.0"
resolved "https://registry.yarnpkg.com/postcss-nesting/-/postcss-nesting-10.2.0.tgz#0b12ce0db8edfd2d8ae0aaf86427370b898890be"
Expand Down
65 changes: 65 additions & 0 deletions server/insight/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import json
from fastapi import APIRouter
from insight.service.activity import get_activity_data
from insight.service.issue import get_issue_data
from insight.service.pr import get_code_changes, get_pr_data


# ref: https://open-digger.cn/en/docs/user_docs/metrics/metrics_usage_guide
router = APIRouter(
prefix="/api/insight",
tags=["insight"],
responses={404: {"description": "Not found"}},
)


@router.get("/issue")
def get_issue_insight(repo_name: str):
try:
result = get_issue_data(repo_name)
return {
"success": True,
"data": result,
}

except Exception as e:
return json.dumps({"success": False, "message": str(e)})


@router.get("/pr")
def get_pr_insight(repo_name: str):
try:
result = get_pr_data(repo_name)
return {
"success": True,
"data": result,
}

except Exception as e:
return json.dumps({"success": False, "message": str(e)})


@router.get("/code_change")
def get_code_change_insight(repo_name: str):
try:
result = get_code_changes(repo_name)
return {
"success": True,
"data": result,
}

except Exception as e:
return json.dumps({"success": False, "message": str(e)})


@router.get("/activity")
def get_activity_insight(repo_name: str):
try:
result = get_activity_data(repo_name)
return {
"success": True,
"data": result,
}

except Exception as e:
return json.dumps({"success": False, "message": str(e)})
28 changes: 28 additions & 0 deletions server/insight/service/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import datetime

Check failure on line 1 in server/insight/service/activity.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

insight/service/activity.py:1:8: F401 `datetime` imported but unused
import requests
from typing import List, Dict


def get_activity_data(repo_name: str) -> List[Dict[str, int]]:
url = f"https://oss.open-digger.cn/github/{repo_name}/activity_details.json"

try:
response = requests.get(url)
data = response.json()
if not data:
return []

# Filter out only the monthly data (excluding quarters)
monthly_data = {k: v for k, v in data.items() if "-" in k}

# Get the most recent month
most_recent_month_key = max(monthly_data.keys())

# Return the data for the most recent month
return [
{"user": user, "value": value}
for user, value in monthly_data[most_recent_month_key]
]
except Exception as e:
print(e)
return []
11 changes: 11 additions & 0 deletions server/insight/service/issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from utils.insight import get_data


def get_issue_data(repo_name):
metrics_mapping = {
"issues_new": "open",
"issues_closed": "close",
"issue_comments": "comment",
}
issue_data = get_data(repo_name, metrics_mapping)
return issue_data
18 changes: 18 additions & 0 deletions server/insight/service/pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from utils.insight import get_data


def get_pr_data(repo_name):
metrics_mapping = {
"change_requests": "open",
"change_requests_accepted": "merge",
"change_requests_reviews": "reviews",
}
return get_data(repo_name, metrics_mapping)


def get_code_changes(repo_name):
metrics_mapping = {
"code_change_lines_add": "add",
"code_change_lines_remove": "remove",
}
return get_data(repo_name, metrics_mapping)
2 changes: 2 additions & 0 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from rag import router as rag_router
from task import router as task_router
from user import router as user_router
from insight import router as insight_router

AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")
API_AUDIENCE = get_env_variable("API_IDENTIFIER")
Expand Down Expand Up @@ -67,6 +68,7 @@
app.include_router(github_app_router.router)
app.include_router(aws_router.router)
app.include_router(user_router.router)
app.include_router(insight_router.router)


@app.get("/")
Expand Down
45 changes: 45 additions & 0 deletions server/tests/insight/test_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
from unittest.mock import patch, MagicMock
from insight.service.activity import get_activity_data


class TestGetActivityData(unittest.TestCase):

@patch("insight.service.activity.requests.get")
def test_get_activity_data(self, mock_get):
mock_response = MagicMock()
mock_response.json.return_value = {
"2023-12": [("user1", 10), ("user2", 5)],
"2024-01": [("user3", 20)],
"2024-02": [("user4", 25)],
"2024-03": [("user5", 30)],
}
mock_get.return_value = mock_response
repo_name = "petercat-ai/petercat"
expected_result = [{"user": "user5", "value": 30}]

result = get_activity_data(repo_name)

self.assertIsInstance(result, list)
self.assertEqual(result, expected_result)

@patch("insight.service.activity.requests.get")
def test_get_activity_data_empty(self, mock_get):
mock_response = MagicMock()
mock_response.json.return_value = {}
mock_get.return_value = mock_response
repo_name = "petercat-ai/petercat"
result = get_activity_data(repo_name)

self.assertEqual(result, [])

@patch("insight.service.activity.requests.get")
def test_get_activity_data_invalid_json(self, mock_get):

mock_response = MagicMock()
mock_response.json.side_effect = ValueError("Invalid JSON")
mock_get.return_value = mock_response

repo_name = "petercat-ai/petercat"
with self.assertRaises(ValueError):
get_activity_data(repo_name)
Loading

0 comments on commit 4f8f5bf

Please sign in to comment.