Skip to content

Commit

Permalink
init GitHubSentinel agent
Browse files Browse the repository at this point in the history
  • Loading branch information
DjangoPeng committed Aug 14, 2024
1 parent cfdf1e8 commit 781b8eb
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Agent Hub 是一个 AI Agent 解决方案中心平台。本仓库包含三个不同的项目,旨在彻底改变企业工作流程,增强个性化语言学习体验,以及丰富多模态交互:

- **GitHub Sentinel**:一个工具类 AI Agent,旨在无缝管理项目和自动更新 GitHub 仓库,以促进更有效的协作和项目跟踪。
- **[GitHub Sentinel](./github_sentinel/README.md)**:一个工具类 AI Agent,旨在无缝管理项目和自动更新 GitHub 仓库,以促进更有效的协作和项目跟踪。
- **LanguageMentor**:一个对话类 AI Agent,利用如 LLaMA 3 等先进的语言模型为全球超过 100 种语言的个性化学习提供支持,特别适用于全球旅行和生活场景。
- **ChatPPT**:一个多模态 AI Agent,整合语音、图像和文本输入,以 AI 驱动的洞察和 PowerPoint 自动化,优化企业办公场景。

Expand Down
23 changes: 23 additions & 0 deletions github_sentinel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

## GitHub Sentinel Agent

GitHub Sentinel 是一个工具类 AI Agent,专为开发者和项目经理设计,自动从订阅的 GitHub 仓库中定期(每日/每周)检索和汇总更新。该工具通过订阅管理、更新检索、通知系统和报告生成等功能,提高团队协作效率和项目管理便利性。

### 版本历史

| 版本号 | 主要特性 | 发布链接 |
|--------|----------------------------------------------------------------------------------------|-----------------------------------------------|
| v0.0.1 | - 初始版本测试发布<br>- 基本功能框架搭建 | [访问 v0.0.1](https://github.com/DjangoPeng/GitHubSentinel/tree/v0.0.1) |
| v0.1 | - 新增交互式命令行界面 (REPL)<br>- 实现添加、删除和列出订阅的命令<br>- 实现即时更新获取命令<br>- 新增帮助命令显示使用说明<br>- 优化命令行参数解析逻辑<br>- 启动时显示帮助信息<br>- 修复与命令执行和错误处理相关的问题 | [访问 v0.1](https://github.com/DjangoPeng/GitHubSentinel/tree/v0.1) |
| v0.2 | - 新增每日进度模块以抓取问题、拉取请求和提交<br>- 集成 OpenAI Python SDK 用于 GPT-4 API 调用<br>- 增强报告生成模块,使用 GPT-4 从 Markdown 文件创建日常项目报告<br>- 优化命令行界面,改进命令处理和帮助显示<br>- 修复多个小问题,提升稳定性 | [访问 v0.2](https://github.com/DjangoPeng/GitHubSentinel/tree/v0.2) |

### 项目初始化

我与 ChatGPT 的多轮对话完成了 GitHub Sentinel 项目的早期版本(v0.0.1->v0.2),详细的对话过程链接:https://chatgpt.com/share/d9b4c3f3-2594-4541-a4a6-e13b3d505ffa

运行 GPT-4 生成的脚本 [setup_github_sentinel.sh](./setup_github_sentinel.sh) 即可生成 v0.0.1 版本完整代码。


### 探索更多

期待更多开发者扩展和探索更多功能,参与到项目的持续改进中来。请通过 [GitHubSentinel项目页](https://github.com/DjangoPeng/GitHubSentinel) 提交你的反馈和建议。
244 changes: 244 additions & 0 deletions github_sentinel/setup_github_sentinel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#!/bin/bash

# 创建 GitHubSentinel 目录及其子目录
mkdir -p GitHubSentinel/src GitHubSentinel/tests

# 在 src 目录下创建文件并写入初始内容
cat <<EOL > GitHubSentinel/src/main.py
from config import Config
from scheduler import Scheduler
from github_client import GitHubClient
from notifier import Notifier
from report_generator import ReportGenerator
from subscription_manager import SubscriptionManager
def main():
config = Config()
github_client = GitHubClient(config.github_token)
notifier = Notifier(config.notification_settings)
report_generator = ReportGenerator()
subscription_manager = SubscriptionManager(config.subscriptions_file)
scheduler = Scheduler(
github_client=github_client,
notifier=notifier,
report_generator=report_generator,
subscription_manager=subscription_manager,
interval=config.update_interval
)
scheduler.start()
if __name__ == "__main__":
main()
EOL

cat <<EOL > GitHubSentinel/src/config.py
import json
class Config:
def __init__(self):
self.load_config()
def load_config(self):
with open('config.json', 'r') as f:
config = json.load(f)
self.github_token = config.get('github_token')
self.notification_settings = config.get('notification_settings')
self.subscriptions_file = config.get('subscriptions_file')
self.update_interval = config.get('update_interval', 24 * 60 * 60) # Default to 24 hours
EOL

cat <<EOL > GitHubSentinel/src/scheduler.py
import time
import threading
class Scheduler:
def __init__(self, github_client, notifier, report_generator, subscription_manager, interval):
self.github_client = github_client
self.notifier = notifier
self.report_generator = report_generator
self.subscription_manager = subscription_manager
self.interval = interval
def start(self):
while True:
self.run()
time.sleep(self.interval)
def run(self):
subscriptions = self.subscription_manager.get_subscriptions()
updates = self.github_client.fetch_updates(subscriptions)
report = self.report_generator.generate(updates)
self.notifier.notify(report)
EOL

cat <<EOL > GitHubSentinel/src/github_client.py
import requests
class GitHubClient:
def __init__(self, token):
self.token = token
def fetch_updates(self, subscriptions):
headers = {
'Authorization': f'token {self.token}'
}
updates = {}
for repo in subscriptions:
response = requests.get(f'https://api.github.com/repos/{repo}/events', headers=headers)
if response.status_code == 200:
updates[repo] = response.json()
return updates
EOL

cat <<EOL > GitHubSentinel/src/notifier.py
class Notifier:
def __init__(self, settings):
self.settings = settings
def notify(self, report):
# Implement notification logic, e.g., send email or Slack message
pass
EOL

cat <<EOL > GitHubSentinel/src/report_generator.py
class ReportGenerator:
def generate(self, updates):
# Implement report generation logic
report = ""
for repo, events in updates.items():
report += f"Repository: {repo}\n"
for event in events:
report += f"- {event['type']} at {event['created_at']}\n"
return report
EOL

cat <<EOL > GitHubSentinel/src/subscription_manager.py
import json
class SubscriptionManager:
def __init__(self, subscriptions_file):
self.subscriptions_file = subscriptions_file
def get_subscriptions(self):
with open(self.subscriptions_file, 'r') as f:
return json.load(f)
EOL

cat <<EOL > GitHubSentinel/src/utils.py
# Add utility functions as needed
EOL

# 在 tests 目录下创建文件并写入初始内容
cat <<EOL > GitHubSentinel/tests/test_github_client.py
import unittest
from src.github_client import GitHubClient
class TestGitHubClient(unittest.TestCase):
def test_fetch_updates(self):
# Add test cases for GitHubClient
pass
if __name__ == '__main__':
unittest.main()
EOL

cat <<EOL > GitHubSentinel/tests/test_notifier.py
import unittest
from src.notifier import Notifier
class TestNotifier(unittest.TestCase):
def test_notify(self):
# Add test cases for Notifier
pass
if __name__ == '__main__':
unittest.main()
EOL

cat <<EOL > GitHubSentinel/tests/test_report_generator.py
import unittest
from src.report_generator import ReportGenerator
class TestReportGenerator(unittest.TestCase):
def test_generate(self):
# Add test cases for ReportGenerator
pass
if __name__ == '__main__':
unittest.main()
EOL

cat <<EOL > GitHubSentinel/tests/test_subscription_manager.py
import unittest
from src.subscription_manager import SubscriptionManager
class TestSubscriptionManager(unittest.TestCase):
def test_get_subscriptions(self):
# Add test cases for SubscriptionManager
pass
if __name__ == '__main__':
unittest.main()
EOL

cat <<EOL > GitHubSentinel/tests/test_utils.py
import unittest
# Add imports for utility functions to test
class TestUtils(unittest.TestCase):
# Add test cases for utility functions
pass
if __name__ == '__main__':
unittest.main()
EOL

# 创建 requirements.txt
cat <<EOL > GitHubSentinel/requirements.txt
requests
EOL

# 创建 README.md
cat <<EOL > GitHubSentinel/README.md
# GitHub Sentinel
GitHub Sentinel is an open-source tool AI Agent designed for developers and project managers. It automatically retrieves and aggregates updates from subscribed GitHub repositories on a regular basis (daily/weekly). Key features include subscription management, update retrieval, notification system, and report generation.
## Features
- Subscription management
- Update retrieval
- Notification system
- Report generation
## Getting Started
1. Install dependencies:
\`\`\`sh
pip install -r requirements.txt
\`\`\`
2. Configure the application by editing \`config.json\`.
3. Run the application:
\`\`\`sh
python src/main.py
\`\`\`
## Configuration
The configuration file \`config.json\` should contain the following settings:
\`\`\`json
{
"github_token": "your_github_token",
"notification_settings": {
"email": "[email protected]",
"slack_webhook_url": "your_slack_webhook_url"
},
"subscriptions_file": "subscriptions.json",
"update_interval": 86400
}
\`\`\`
EOL

# 提示脚本执行完成
echo "Project GitHubSentinel setup completed."

0 comments on commit 781b8eb

Please sign in to comment.