def callback(chat_hash): """ GET payload from Github webhook and send it to handler :param chat_hash unique chat id """ payload = request.json try: repository_id = int(payload['repository']['id']) repository_name = payload['repository']['name'] logging.debug('Repository id: %s, chat hash: %s' % (repository_id, chat_hash)) handler = Notifications(payload) chat_id = handler.get_chat_id_by_hash(chat_hash) if request.headers['X-GitHub-Event'] == "ping": print("add repository {%s} to connected" % repository_name) if not get_repository(repository_id): gh_repository = Github_repositories.create(chat_id=chat_id, repository_id=repository_id, repository_name=repository_name) gh_repository.save() send_to_chat("Репозиторий %s был подключен" % repository_name, chat_id) gh_repository.close() else: handler.process() handler.send_to_chat(chat_hash) except Exception as e: logging.error("Github callback exception {%s}: [%s]" % (chat_hash, e)) print(bcolors.error("Github callback exception {%s}: [%s]" % (chat_hash, e))) return "{False}" return "{True}"