def generate_jwt(user_uuid): """ Generate token dict :param user_uuid: UUID - String :return: dict(access_token, refresh_token) """ user_uuid = str(user_uuid) access_token = get_jwt(user_uuid, settings.JWT_ACCESS_TOKEN_TIME_OUT) refresh_token = get_jwt(user_uuid, settings.JWT_REFRESH_TOKEN_TIME_OUT) return dict(access_token=access_token, refresh_token=refresh_token)
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) await close('pr', PRList, gh, user, repo) await close('issue', issueList, gh, user, repo)
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"]) markCIObject = MarkTimeoutCI(user, repo, gh) await markCIObject.markCIFailed()
async def main(user, repo, repoMessage): 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_info = '' issue_info = '' for CloseType in repoMessage['CloseType']: if CloseType == 'issues': issues_url = 'https://api.github.com/repos/%s/%s/issues?per_page=100&page=1&direction=asc&q=addClass' % ( user, repo) issueList = await overdueList('issues', issues_url, gh, repoMessage['CloseDay']) logger.info('issueList: %s' % issueList) issue_info = await close('issue', issueList, gh, user, repo) elif CloseType == 'pr': pr_url = 'https://api.github.com/repos/%s/%s/pulls?per_page=100&page=1&direction=asc&q=addClass' % ( user, repo) PRList = await overdueList('pr', pr_url, gh, repoMessage['CloseDay']) logger.info('PRList: %s' % PRList) pr_info = await close('pr', PRList, gh, user, repo) if pr_info or issue_info: mail_content = "<html><body><p>Hi, ALL:</p> <p>以下issue/pr超过1年未更新,将关闭</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 mail_content = mail_content + task_info + "</table></body></html>" sendCloseMail(mail_content, repo, repoMessage['receivers'], repoMessage['CloseDay']) logger.info("Mail sent success! ") else: logger.info("PR/issue without timeout")
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 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)