From ce733aa95f3587a09b97f3af431cf4220c8e445b Mon Sep 17 00:00:00 2001 From: DjangoPeng Date: Mon, 1 Jul 2024 06:54:44 +0000 Subject: [PATCH] auto generate project by ChatGPT4 --- README.md | 36 ++++++++++++++++++++++++++++++ requirements.txt | 1 + src/config.py | 13 +++++++++++ src/github_client.py | 16 +++++++++++++ src/main.py | 26 +++++++++++++++++++++ src/notifier.py | 7 ++++++ src/report_generator.py | 9 ++++++++ src/scheduler.py | 21 +++++++++++++++++ src/subscription_manager.py | 9 ++++++++ src/utils.py | 1 + tests/test_github_client.py | 10 +++++++++ tests/test_notifier.py | 10 +++++++++ tests/test_report_generator.py | 10 +++++++++ tests/test_subscription_manager.py | 10 +++++++++ tests/test_utils.py | 9 ++++++++ 15 files changed, 188 insertions(+) create mode 100644 README.md create mode 100644 requirements.txt create mode 100644 src/config.py create mode 100644 src/github_client.py create mode 100644 src/main.py create mode 100644 src/notifier.py create mode 100644 src/report_generator.py create mode 100644 src/scheduler.py create mode 100644 src/subscription_manager.py create mode 100644 src/utils.py create mode 100644 tests/test_github_client.py create mode 100644 tests/test_notifier.py create mode 100644 tests/test_report_generator.py create mode 100644 tests/test_subscription_manager.py create mode 100644 tests/test_utils.py diff --git a/README.md b/README.md new file mode 100644 index 00000000..62a5cc04 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# 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": "your_email@example.com", + "slack_webhook_url": "your_slack_webhook_url" + }, + "subscriptions_file": "subscriptions.json", + "update_interval": 86400 +} +``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..f2293605 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/src/config.py b/src/config.py new file mode 100644 index 00000000..9094ea8f --- /dev/null +++ b/src/config.py @@ -0,0 +1,13 @@ +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 diff --git a/src/github_client.py b/src/github_client.py new file mode 100644 index 00000000..a1782474 --- /dev/null +++ b/src/github_client.py @@ -0,0 +1,16 @@ +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 diff --git a/src/main.py b/src/main.py new file mode 100644 index 00000000..8aa62eb5 --- /dev/null +++ b/src/main.py @@ -0,0 +1,26 @@ +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() diff --git a/src/notifier.py b/src/notifier.py new file mode 100644 index 00000000..15c91a49 --- /dev/null +++ b/src/notifier.py @@ -0,0 +1,7 @@ +class Notifier: + def __init__(self, settings): + self.settings = settings + + def notify(self, report): + # Implement notification logic, e.g., send email or Slack message + pass diff --git a/src/report_generator.py b/src/report_generator.py new file mode 100644 index 00000000..aac9eda1 --- /dev/null +++ b/src/report_generator.py @@ -0,0 +1,9 @@ +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 diff --git a/src/scheduler.py b/src/scheduler.py new file mode 100644 index 00000000..43c50f3b --- /dev/null +++ b/src/scheduler.py @@ -0,0 +1,21 @@ +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) diff --git a/src/subscription_manager.py b/src/subscription_manager.py new file mode 100644 index 00000000..a8baba9c --- /dev/null +++ b/src/subscription_manager.py @@ -0,0 +1,9 @@ +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) diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 00000000..7e8252d8 --- /dev/null +++ b/src/utils.py @@ -0,0 +1 @@ +# Add utility functions as needed diff --git a/tests/test_github_client.py b/tests/test_github_client.py new file mode 100644 index 00000000..98b1b93d --- /dev/null +++ b/tests/test_github_client.py @@ -0,0 +1,10 @@ +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() diff --git a/tests/test_notifier.py b/tests/test_notifier.py new file mode 100644 index 00000000..95c273ea --- /dev/null +++ b/tests/test_notifier.py @@ -0,0 +1,10 @@ +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() diff --git a/tests/test_report_generator.py b/tests/test_report_generator.py new file mode 100644 index 00000000..be41f6d7 --- /dev/null +++ b/tests/test_report_generator.py @@ -0,0 +1,10 @@ +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() diff --git a/tests/test_subscription_manager.py b/tests/test_subscription_manager.py new file mode 100644 index 00000000..a176b76e --- /dev/null +++ b/tests/test_subscription_manager.py @@ -0,0 +1,10 @@ +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() diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 00000000..a4efe996 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,9 @@ +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()