Skip to content

Commit

Permalink
auto generate project by ChatGPT4
Browse files Browse the repository at this point in the history
  • Loading branch information
DjangoPeng committed Jul 1, 2024
1 parent 9709369 commit ce733aa
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"slack_webhook_url": "your_slack_webhook_url"
},
"subscriptions_file": "subscriptions.json",
"update_interval": 86400
}
```
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
13 changes: 13 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/github_client.py
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 7 additions & 0 deletions src/notifier.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/report_generator.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions src/scheduler.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions src/subscription_manager.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Add utility functions as needed
10 changes: 10 additions & 0 deletions tests/test_github_client.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions tests/test_notifier.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions tests/test_report_generator.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions tests/test_subscription_manager.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ce733aa

Please sign in to comment.