-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
287 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# GitHub Sentinel | ||
|
||
<p align="center"> | ||
<br> English | <a href="README.md">中文</a> | ||
</p> | ||
|
||
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 | ||
|
||
First, install the required dependencies: | ||
|
||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### 2. Configure the Application | ||
|
||
Edit the `config.json` file to set up your GitHub token, notification settings, subscription file, and update interval: | ||
|
||
```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 | ||
} | ||
``` | ||
|
||
### 3. How to Run | ||
|
||
GitHub Sentinel supports three different ways to run the application: | ||
|
||
#### A. Run as a Command-Line Tool | ||
|
||
You can run the application interactively from the command line: | ||
|
||
```sh | ||
python src/command_tool.py | ||
``` | ||
|
||
In this mode, you can manually input commands to manage subscriptions, retrieve updates, and generate reports. | ||
|
||
#### B. Run as a Daemon Process with Scheduler | ||
|
||
To run the application as a background service (daemon) that regularly checks for updates: | ||
|
||
1. Ensure you have the `python-daemon` package installed: | ||
|
||
```sh | ||
pip install python-daemon | ||
``` | ||
|
||
2. Launch the daemon process: | ||
|
||
```sh | ||
nohup python3 src/daemon_process.py > logs/daemon_process.log 2>&1 & | ||
``` | ||
|
||
- This will start the scheduler in the background, checking for updates at the interval specified in your `config.json`. | ||
- Logs will be saved to the `logs/daemon_process.log` file. | ||
|
||
#### C. Run as a Gradio Server | ||
|
||
To run the application with a Gradio interface, allowing users to interact with the tool via a web interface: | ||
|
||
```sh | ||
python src/gradio_server.py | ||
``` | ||
|
||
- This will start a web server on your machine, allowing you to manage subscriptions and generate reports through a user-friendly interface. | ||
- By default, the Gradio server will be accessible at `http://localhost:7860`, but you can share it publicly if needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
requests | ||
openai | ||
gradio | ||
logoru | ||
loguru | ||
python-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import shlex | ||
|
||
from config import Config | ||
from github_client import GitHubClient | ||
from notifier import Notifier | ||
from report_generator import ReportGenerator | ||
from llm import LLM | ||
from subscription_manager import SubscriptionManager | ||
from command_handler import CommandHandler | ||
from logger import LOG | ||
|
||
def main(): | ||
config = Config() | ||
github_client = GitHubClient(config.github_token) | ||
notifier = Notifier(config.notification_settings) | ||
llm = LLM() | ||
report_generator = ReportGenerator(llm) | ||
subscription_manager = SubscriptionManager(config.subscriptions_file) | ||
command_handler = CommandHandler(github_client, subscription_manager, report_generator) | ||
|
||
parser = command_handler.parser | ||
command_handler.print_help() | ||
|
||
while True: | ||
try: | ||
user_input = input("GitHub Sentinel> ") | ||
if user_input in ['exit', 'quit']: | ||
break | ||
try: | ||
args = parser.parse_args(shlex.split(user_input)) | ||
if args.command is None: | ||
continue | ||
args.func(args) | ||
except SystemExit as e: | ||
LOG.error("Invalid command. Type 'help' to see the list of available commands.") | ||
except Exception as e: | ||
LOG.error(f"Unexpected error: {e}") | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import daemon | ||
import threading | ||
import time | ||
|
||
|
||
from config import Config | ||
from github_client import GitHubClient | ||
from notifier import Notifier | ||
from report_generator import ReportGenerator | ||
from llm import LLM | ||
from subscription_manager import SubscriptionManager | ||
from scheduler import Scheduler | ||
from logger import LOG | ||
|
||
def run_scheduler(scheduler): | ||
scheduler.start() | ||
|
||
def main(): | ||
config = Config() | ||
github_client = GitHubClient(config.github_token) | ||
notifier = Notifier(config.notification_settings) | ||
llm = LLM() | ||
report_generator = ReportGenerator(llm) | ||
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_thread = threading.Thread(target=run_scheduler, args=(scheduler,)) | ||
scheduler_thread.daemon = True | ||
scheduler_thread.start() | ||
|
||
LOG.info("Scheduler thread started.") | ||
|
||
# Use python-daemon to properly daemonize the process | ||
with daemon.DaemonContext(): | ||
try: | ||
while True: | ||
time.sleep(config.update_interval) | ||
except KeyboardInterrupt: | ||
LOG.info("Daemon process stopped.") | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
# nohup python3 src/daemon_process.py > logs/daemon_process.log 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import gradio as gr | ||
|
||
from config import Config | ||
from github_client import GitHubClient | ||
from report_generator import ReportGenerator | ||
from llm import LLM | ||
from subscription_manager import SubscriptionManager | ||
from logger import LOG | ||
|
||
config = Config() | ||
github_client = GitHubClient(config.github_token) | ||
llm = LLM() | ||
report_generator = ReportGenerator(llm) | ||
subscription_manager = SubscriptionManager(config.subscriptions_file) | ||
|
||
|
||
def export_progress_by_date_range(repo, days): | ||
raw_file_path = github_client.export_progress_by_date_range(repo, days) | ||
report, report_file_path = report_generator.generate_report_by_date_range(raw_file_path, days) | ||
|
||
return report, report_file_path | ||
|
||
demo = gr.Interface( | ||
fn=export_progress_by_date_range, | ||
title="GitHubSentinel", | ||
inputs=[ | ||
gr.Dropdown( | ||
subscription_manager.list_subscriptions(), label="订阅列表", info="已订阅GitHub项目" | ||
), | ||
gr.Slider(value=2, minimum=1, maximum=7, step=1, label="报告周期", info="生成项目过去一段时间进展,单位:天"), | ||
|
||
], | ||
outputs=[gr.Markdown(), gr.File(label="下载报告")], | ||
) | ||
|
||
if __name__ == "__main__": | ||
demo.launch(share=True, server_name="0.0.0.0") | ||
# demo.launch(share=True, server_name="0.0.0.0", auth=("django", "1234")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters