mirror of
https://git.juggalol.com/agatha/gitmon.git
synced 2024-11-22 15:36:43 +00:00
40 lines
880 B
Python
40 lines
880 B
Python
"""GitMon"""
|
|
import time
|
|
from loguru import logger
|
|
from gitmon.api import GitHubApi
|
|
from gitmon.logger import setup_logger
|
|
|
|
try:
|
|
from config import token
|
|
except ModuleNotFoundError:
|
|
token = None
|
|
|
|
|
|
def log_event(event):
|
|
event_type = event.get('type')
|
|
repo = event.get('repo')
|
|
actor = event.get('actor')
|
|
|
|
if event_type == 'DeleteEvent':
|
|
logger.error(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
|
else:
|
|
logger.info(f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
|
|
|
|
|
def main():
|
|
"""Main entry point."""
|
|
setup_logger()
|
|
api = GitHubApi(token)
|
|
|
|
while True:
|
|
events = api.get_events()
|
|
for event in events:
|
|
if event['type'] in ['CreateEvent', 'DeleteEvent']:
|
|
log_event(event)
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|