def add_hook(): hook_data = { "name": "web", "active": True, "events": [ "push", "pull_request" ], "config": { "url": "http://commitandclose.me/hook", "content_type": "json" } } endpoint_data = { 'user': '******', 'repo': 'commitandclose.me', } try: result = github.post('repos/{user}/{repo}/hooks'.format(**endpoint_data), hook_data) db_hook = Hook(repo_id=21621642, username='******') db_hook.save() except: return str("failed") # result = github.get('repos/h4/commitandclose.me') return str(result)
def save_hook(data: dict): """ Records the received hook. """ hook = Hook() hook.body = json.dumps(data, ensure_ascii=False, indent=4) db.session.add(hook) db.session.commit()
def profile(): if session.get('access_token', None) is None: return redirect(url_for('.login')) orgs = github.get('user/orgs') repos = get_all_repos(github) hooks = Hook.objects(username='******') for repo in repos: repo['has_hook'] = any(x.repo_id == repo['id'] for x in hooks) return render_template('app/profile.html', repos=repos, orgs=orgs, hooks=hooks)