async def on_startup(app): app['gh_client_session'] = aiohttp.ClientSession( timeout=aiohttp.ClientTimeout(total=5)) app['github_client'] = gh_aiohttp.GitHubAPI(app['gh_client_session'], 'ci', oauth_token=oauth_token) app['batch_client'] = BatchClient('ci') app['dbpool'] = await create_database_pool() app['task_manager'] = aiotools.BackgroundTaskManager() app['task_manager'].ensure_future(update_loop(app))
async def main(request): body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "krnick", oauth_token=oauth_token) await router.dispatch(event, gh) return web.Response(status=200)
async def on_startup(app): session = aiohttp.ClientSession(raise_for_status=True, timeout=aiohttp.ClientTimeout(total=60)) app['client_session'] = session app['github_client'] = gh_aiohttp.GitHubAPI( aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=60)), 'ci', oauth_token=oauth_token) app['batch_client'] = await BatchClient('ci', session=session) app['dbpool'] = await create_database_pool() asyncio.ensure_future(update_loop(app))
async def on_startup(app): app['client_session'] = httpx.client_session() app['github_client'] = gh_aiohttp.GitHubAPI(app['client_session'], 'ci', oauth_token=oauth_token) app['batch_client'] = await BatchClient.create('ci') app['db'] = Database() await app['db'].async_init() app['task_manager'] = aiotools.BackgroundTaskManager() app['task_manager'].ensure_future(update_loop(app))
async def main(user, repo): async with aiohttp.ClientSession() as session: app_id = os.getenv("GH_APP_ID") jwt = get_jwt(app_id) gh = gh_aiohttp.GitHubAPI(session, user) try: installation = await get_installation(gh, jwt, user) except ValueError as ve: print(ve) else: access_token = await get_installation_access_token( gh, jwt=jwt, installation_id=installation["id"] ) # treat access_token as if a personal access token gh = gh_aiohttp.GitHubAPI(session, user, oauth_token=access_token["token"]) pr_url = 'https://api.github.com/repos/%s/%s/pulls?per_page=100&page=1&direction=asc&q=addClass' %(user, repo) issues_url = 'https://api.github.com/repos/%s/%s/issues?per_page=100&page=1&direction=asc&q=addClass' %(user, repo) PRList = await overdueList('pr', pr_url, gh) issueList = await overdueList('issues', issues_url, gh) await close('pr', PRList, gh, user, repo) await close('issue', issueList, gh, user, repo)
async def main(request): body = await request.read() user = json.loads(body.decode('utf8'))['repository']['owner']['login'] repo = json.loads(body.decode('utf8'))['repository']['full_name'] secret = os.environ.get("GH_SECRET") event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: app_id = os.getenv("GH_APP_ID") jwt = get_jwt(app_id) gh = gh_aiohttp.GitHubAPI(session, user) try: installation = await get_installation(gh, jwt, user) except ValueError as ve: print(ve) else: access_token = await get_installation_access_token( gh, jwt=jwt, installation_id=installation["id"]) # treat access_token as if a personal access token gh = gh_aiohttp.GitHubAPI(session, user, oauth_token=access_token["token"]) await router.dispatch(event, gh, repo) return web.Response(status=200)
async def main(request): body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "rohanj-02", oauth_token=oauth_token) # Enter your username above in <USERNAME> field await router.dispatch(event, gh) return web.Response(status=200)
async def main(request): body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI( session, "baboosh", # Replace the second parameter with your own username oauth_token=oauth_token) await router.dispatch(event, gh) return web.Response(status=200)
async def rerun_handler(self, request): """ rerun get server """ user = request.match_info['user'] repo = request.match_info['repo'] PR = request.match_info['PR'] commit = request.match_info['commit'] async with aiohttp.ClientSession() as session: app_id = os.getenv("GH_APP_ID") jwt = get_jwt(app_id) gh = gh_aiohttp.GitHubAPI(session, user) try: installation = await get_installation(gh, jwt, user) except ValueError as ve: print(ve) else: access_token = await get_installation_access_token( gh, jwt=jwt, installation_id=installation["id"]) # treat access_token as if a personal access token gh = gh_aiohttp.GitHubAPI(session, user, oauth_token=access_token["token"]) await self.getCIList(user, repo, PR, commit, gh)
async def main(user, repo): async with aiohttp.ClientSession() as session: app_id = os.getenv("GH_APP_ID") jwt = get_jwt(app_id) gh = gh_aiohttp.GitHubAPI(session, user) try: installation = await get_installation(gh, jwt, user) except ValueError as ve: print(ve) else: access_token = await get_installation_access_token( gh, jwt=jwt, installation_id=installation["id"]) # treat access_token as if a personal access token gh = gh_aiohttp.GitHubAPI(session, user, oauth_token=access_token["token"]) pr_url = 'https://api.github.com/repos/%s/%s/pulls?per_page=100&page=1&direction=asc&q=addClass' % ( user, repo) issues_url = 'https://api.github.com/repos/%s/%s/issues?per_page=100&page=1&direction=asc&q=addClass' % ( user, repo) PRList = await overdueList('pr', pr_url, gh) logger.info("PRList: %s" % PRList) issueList = await overdueList('issues', issues_url, gh) logger.info("issueList: %s" % issueList) pr_info = await close('pr', PRList, gh, user, repo) issue_info = await close('issue', issueList, gh, user, repo) if pr_info or issue_info: mail_content = "<html><body><p>Hi, ALL:</p> <p>以下issue/pr超过1年未更新,Paddle-bot将其关闭。请PM留意。</p> <table border='1' align=center> <caption><font size='3'></font></caption>" mail_content = mail_content + "<tr align=center><td bgcolor='#d0d0d0'>类型</td><td bgcolor='#d0d0d0'>issue/pr号</td></tr>" task_info = pr_info + issue_info end_content = "<p>如有疑问,请@张春乐。谢谢</p>" mail_content = mail_content + task_info + end_content + "</table></body></html>" sendCloseMail(mail_content) logger.info("Mail sent success! message: %s" % (mail_content)) else: logger.info("PR/issue without timeout")
async def main(request): body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") event = sansio.Event.from_http(request.headers, body, secret=secret) print("GH delivery ID", event.delivery_id, file=sys.stderr) print("event data:") pp = pprint.PrettyPrinter(indent=4) pp.pprint(event.data) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "mariatta", oauth_token=oauth_token) await router.dispatch(event, gh) return web.Response(status=200)
async def deferred_commands(event): """Defer handling of commands in comments.""" async with sem: async with aiohttp.ClientSession() as session: token = os.environ.get("GH_AUTH") bot = os.environ.get("GH_BOT") gh = gh_aiohttp.GitHubAPI(session, bot, oauth_token=token, cache=cache) await asyncio.sleep(1) async for cmd in commands.run(event, gh, bot): if cmd.pending is not None: await cmd.pending(cmd.event, gh) await get_scheduler_from_app(app).spawn( deferred_task(cmd.command, cmd.event, live=cmd.live, kwargs=cmd.kwargs) )
async def main(request): # read the GitHub webhook payload body = await request.read() # our authentication token and secret secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") # a representation of GitHub webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, 'mohantyk', oauth_token=oauth_token) await router.dispatch(event, gh) return web.Response(status=200)
async def main(request): # Read the GitHub webhook payload body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") # A representation of a GitHub webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "williln", oauth_token=oauth_token) # Call the appropriate callback for the event await router.dispatch(event, gh) # Return a "Success" return web.Response(status=200)
async def main(req: func.HttpRequest) -> func.HttpResponse: global CLIENT_SESSION try: if CLIENT_SESSION is None: CLIENT_SESSION = aiohttp.ClientSession() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") body = req.get_body() gh = gh_aiohttp.GitHubAPI( CLIENT_SESSION, "Microsoft/pvscbot", oauth_token=oauth_token ) await server.serve(gh, router, req.headers, body, secret=secret, logger=logging) return func.HttpResponse(status_code=200) except Exception: logging.exception("Unhandled exception") return func.HttpResponse(status_code=500)
async def webhook(request): """This is the main webhook dispatcher Handlers are declared with the @router.register decorator. See https://gidgethub.readthedocs.io/en/latest/routing.html """ body = await request.read() event = gh_sansio.Event.from_http( request.headers, body, secret=config.GITHUB_SECRET ) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI( session, config.GITHUB_LOGIN, oauth_token=config.GITHUB_TOKEN ) await router.dispatch(event, gh) return web.Response(status=200)
async def main(request): try: body = await request.read() secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "Microsoft/pvscbot", oauth_token=oauth_token) await server.serve(gh, router, request.headers, body, secret=secret, logger=logging) return web.Response(status=200) except Exception: logging.exception("Unhandled exception") return web.Response(status=500)
async def deferred_task(function, event, kwargs=None): """Defer the event work.""" if kwargs is None: kwargs = {} async with sem: async with aiohttp.ClientSession() as session: token = os.environ.get("GH_AUTH") bot = os.environ.get("GH_BOT") gh = gh_aiohttp.GitHubAPI(session, bot, oauth_token=token, cache=cache) # If we need to make sure the task is working with live issue labels, turn off quick labels. await asyncio.sleep(1) config = await event.get_config(gh) await function(event, gh, config, **kwargs)
async def main(request): # read the GitHub webhook payload body = await request.read() # parse the event event = sansio.Event.from_http(request.headers, body, secret=WEBHOOK_SECRET) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, BOT_NAME, oauth_token=GH_OAUTH_TOKEN) # call the appropriate callback for the event await router.dispatch(event, gh) # HTTP success return web.Response(status=200)
async def main(request): # read the GitHub webhook payload body = await request.read() # our authentication token and secret secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") # a representation of GitHub webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) # instead of mariatta, use your own username async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "small-yellow-duck", oauth_token=oauth_token) # call the appropriate callback for the event await router.dispatch(event, gh) return web.Response(status=200)
async def on_startup(app): app['client_session'] = aiohttp.ClientSession( raise_for_status=True, timeout=aiohttp.ClientTimeout(total=60)) app['github_client'] = gh_aiohttp.GitHubAPI(app['client_session'], 'ci', oauth_token=oauth_token) app['batch_client'] = BatchClient(app['client_session'], url=os.environ.get('BATCH_SERVER_URL')) with open('/ci-user-secret/sql-config.json', 'r') as f: config = json.loads(f.read().strip()) app['dbpool'] = await aiomysql.create_pool(host=config['host'], port=config['port'], db=config['db'], user=config['user'], password=config['password'], charset='utf8', cursorclass=aiomysql.cursors.DictCursor, autocommit=True) asyncio.ensure_future(update_loop(app))
async def webhook(request): try: body = await request.read() secret = os.environ.get("GH_SECRET") event = sansio.Event.from_http(request.headers, body, secret=secret) if event.event == "ping": return web.Response(status=200) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "demo", cache=cache) await asyncio.sleep(1) await router.dispatch(event, gh) try: print("GH requests remaining:", gh.rate_limit.remaining) except AttributeError: pass return web.Response(status=200) except Exception as exc: traceback.print_exc(file=sys.stderr) return web.Response(status=500)
async def main(request): # read the GitHub webhook payload body = await request.read() # our authentication token and secret gh_secret = get_secret("GH_SECRET") oauth_token = get_secret("GH_AUTH") # a representation of GitHub webhook event event = sansio.Event.from_http(request.headers, body, secret=gh_secret) # create the client context so we get a release on the session and then # grab then listen on the session for posts from the webhook async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "ascbot", oauth_token=oauth_token) # call the appropriate callback for the event await router.dispatch(event, gh) # return a "Success" return web.Response(status=200)
async def main(request): try: body = await request.read() secret = os.environ.get("GH_SECRET") event = sansio.Event.from_http(request.headers, body, secret=secret) print('GH delivery ID', event.delivery_id, file=sys.stderr) if event.event == "ping": return web.Response(status=200) oauth_token = os.environ.get("GH_AUTH") with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "python/bedevere", oauth_token=oauth_token, cache=cache) # Give GitHub some time to reach internal consistency. await asyncio.sleep(1) await router.dispatch(event, gh) return web.Response(status=200) except Exception as exc: traceback.print_exc(file=sys.stderr) return web.Response(status=500)
async def main(request): # read the GitHub webhook payload body = await request.read() #our authentication token and secret secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") # a representation of Github webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, config_manager.bot_name(), oauth_token=oauth_token) # call for the appropriate callback for the event await router.dispatch(event, gh) # return a "Success" return web.Response(status=200)
async def main(request): # read the GitHub webhook payload body = await request.read() # our authentication token and secret cfg = configparser.ConfigParser() cfg.read("app/vault_secrets.ini") secret = cfg.get("vault_secrets", "WEBHOOK_SECRET") oauth_token = cfg.get("vault_secrets", "GH_AUTH_TOKEN") # a representation of GitHub webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "r-ash", oauth_token=oauth_token) # call the appropriate callback for the event await router.dispatch(event, gh) # return a "Success" return web.Response(status=200)
async def main(request): # read the GitHub webhook payload body = await request.read() # add authentication token and webhook secret secret = os.environ.get("GH_SECRET") oauth_token = os.environ.get("GH_AUTH") # a representation of github webhook event event = sansio.Event.from_http(request.headers, body, secret=secret) # pay attention to the username used async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "storymode7", oauth_token=oauth_token) # call appropriate callback for the event await router.dispatch(event, gh) # return "Success" response return web.Response(status=200)
async def webhook(request): """Work with webhooks and start the bot""" # try to start the bot try: body = await request.read() secret = SECRET event = sansio.Event.from_http(request.headers, body, secret=secret) if event.event == 'ping': return web.Response(status=200) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, 'demo', cache=cache) await asyncio.sleep(1) await router.dispatch(event, gh) try: print('GH requests remaining:', gh.rate_limit.remaining) except AttributeError as exc: print(exc) return web.Response(status=200) except Exception as exc: traceback.print_exc(file=sys.stderr) print(exc) return web.Response(status=500)
async def main(request: web.Request) -> web.Response: try: body = await request.read() secret = os.environ.get("GITHUB_SECRET") event = sansio.Event.from_http(request.headers, body, secret=secret) if event.event == "ping": return web.Response(status=200) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI(session, "algorithms-bot", cache=cache) # Give GitHub some time to reach internal consistency. await asyncio.sleep(1) await router.dispatch(event, gh) try: print( f"GH requests remaining: {gh.rate_limit.remaining}\n" f"Reset time: {gh.rate_limit.reset_datetime:%b-%d-%Y %H:%M:%S %Z}\n" f"GH delivery ID: {event.delivery_id}") except AttributeError: pass return web.Response(status=200) except Exception: traceback.print_exc(file=sys.stderr) return web.Response(status=500)
async def main(request): try: body = await request.read() event = sansio.Event.from_http(request.headers, body, secret=GH_SECRET) print("GH delivery ID", event.delivery_id, file=sys.stderr) if event.event == "ping": return web.Response(status=200) async with aiohttp.ClientSession() as session: gh = gh_aiohttp.GitHubAPI( session, GH_USERNAME, oauth_token=GH_AUTH, cache=cache, ) # Give GitHub some time to reach internal consistency. await router.dispatch(event, gh) try: print("GH requests remaining:", gh.rate_limit.remaining) except AttributeError: pass return web.Response(status=200) except BaseException as exc: traceback.print_exc(file=sys.stderr) return web.Response(status=500)