diff --git a/config.json b/config.json new file mode 100644 index 00000000..c259c3d3 --- /dev/null +++ b/config.json @@ -0,0 +1,9 @@ +{ + "github_token": "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", + "notification_settings": { + "email": "your_email@example.com", + "slack_webhook_url": "your_slack_webhook_url" + }, + "subscriptions_file": "subscriptions.json", + "update_interval": 86400 +} diff --git a/src/github_client.py b/src/github_client.py index a1782474..cc155180 100644 --- a/src/github_client.py +++ b/src/github_client.py @@ -10,7 +10,7 @@ def fetch_updates(self, subscriptions): } updates = {} for repo in subscriptions: - response = requests.get(f'https://api.github.com/repos/{repo}/events', headers=headers) + response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest', headers=headers) if response.status_code == 200: updates[repo] = response.json() return updates diff --git a/src/main.py b/src/main.py index 8aa62eb5..2705b4ab 100644 --- a/src/main.py +++ b/src/main.py @@ -1,9 +1,51 @@ +import argparse 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 +import threading +import shlex + +def run_scheduler(scheduler): + scheduler.start() + +def add_subscription(args, subscription_manager): + subscription_manager.add_subscription(args.repo) + print(f"Added subscription: {args.repo}") + +def remove_subscription(args, subscription_manager): + subscription_manager.remove_subscription(args.repo) + print(f"Removed subscription: {args.repo}") + +def list_subscriptions(subscription_manager): + subscriptions = subscription_manager.get_subscriptions() + print("Current subscriptions:") + for sub in subscriptions: + print(f"- {sub}") + +def fetch_updates(github_client, subscription_manager, report_generator): + subscriptions = subscription_manager.get_subscriptions() + updates = github_client.fetch_updates(subscriptions) + report = report_generator.generate(updates) + print("Updates fetched:") + print(report) + +def print_help(): + help_text = """ +GitHub Sentinel Command Line Interface + +Available commands: + add Add a subscription (e.g., owner/repo) + remove Remove a subscription (e.g., owner/repo) + list List all subscriptions + fetch Fetch updates immediately + help Show this help message + exit Exit the tool + quit Exit the tool +""" + print(help_text) def main(): config = Config() @@ -20,7 +62,46 @@ def main(): interval=config.update_interval ) - scheduler.start() + scheduler_thread = threading.Thread(target=run_scheduler, args=(scheduler,)) + scheduler_thread.daemon = True + scheduler_thread.start() + + parser = argparse.ArgumentParser(description='GitHub Sentinel Command Line Interface') + subparsers = parser.add_subparsers(title='Commands', dest='command') + + parser_add = subparsers.add_parser('add', help='Add a subscription') + parser_add.add_argument('repo', type=str, help='The repository to subscribe to (e.g., owner/repo)') + parser_add.set_defaults(func=lambda args: add_subscription(args, subscription_manager)) + + parser_remove = subparsers.add_parser('remove', help='Remove a subscription') + parser_remove.add_argument('repo', type=str, help='The repository to unsubscribe from (e.g., owner/repo)') + parser_remove.set_defaults(func=lambda args: remove_subscription(args, subscription_manager)) + + parser_list = subparsers.add_parser('list', help='List all subscriptions') + parser_list.set_defaults(func=lambda args: list_subscriptions(subscription_manager)) + + parser_fetch = subparsers.add_parser('fetch', help='Fetch updates immediately') + parser_fetch.set_defaults(func=lambda args: fetch_updates(github_client, subscription_manager, report_generator)) + + parser_help = subparsers.add_parser('help', help='Show this help message') + parser_help.set_defaults(func=lambda args: print_help()) + + # Print help on startup + print_help() + + while True: + try: + user_input = input("GitHub Sentinel> ") + if user_input in ["exit", "quit"]: + print("Exiting GitHub Sentinel...") + break + args = parser.parse_args(shlex.split(user_input)) + if args.command is not None: + args.func(args) + else: + parser.print_help() + except Exception as e: + print(f"Error: {e}") if __name__ == "__main__": main() diff --git a/src/report_generator.py b/src/report_generator.py index aac9eda1..a9922d14 100644 --- a/src/report_generator.py +++ b/src/report_generator.py @@ -1,9 +1,11 @@ class ReportGenerator: def generate(self, updates): - # Implement report generation logic - report = "" - for repo, events in updates.items(): + report = "Latest Release Information:\n\n" + for repo, release in updates.items(): report += f"Repository: {repo}\n" - for event in events: - report += f"- {event['type']} at {event['created_at']}\n" + report += f"Latest Version: {release['tag_name']}\n" + report += f"Release Name: {release['name']}\n" + report += f"Published at: {release['published_at']}\n" + report += f"Release Notes:\n{release['body']}\n" + report += "-" * 40 + "\n" return report diff --git a/src/subscription_manager.py b/src/subscription_manager.py index a8baba9c..8ff5aec3 100644 --- a/src/subscription_manager.py +++ b/src/subscription_manager.py @@ -3,7 +3,25 @@ class SubscriptionManager: def __init__(self, subscriptions_file): self.subscriptions_file = subscriptions_file + self.subscriptions = self.load_subscriptions() - def get_subscriptions(self): + def load_subscriptions(self): with open(self.subscriptions_file, 'r') as f: return json.load(f) + + def save_subscriptions(self): + with open(self.subscriptions_file, 'w') as f: + json.dump(self.subscriptions, f, indent=4) + + def get_subscriptions(self): + return self.subscriptions + + def add_subscription(self, repo): + if repo not in self.subscriptions: + self.subscriptions.append(repo) + self.save_subscriptions() + + def remove_subscription(self, repo): + if repo in self.subscriptions: + self.subscriptions.remove(repo) + self.save_subscriptions() diff --git a/subscriptions.json b/subscriptions.json new file mode 100644 index 00000000..174479d6 --- /dev/null +++ b/subscriptions.json @@ -0,0 +1,3 @@ +[ + "langchain-ai/langchain" +]