|
16 | 16 | import requests |
17 | 17 | from flask import (Blueprint, abort, flash, g, jsonify, redirect, request, |
18 | 18 | url_for) |
19 | | -from github import Commit, Github, GithubException, GithubObject, Repository |
| 19 | +from github import (Auth, Commit, Github, GithubException, GithubObject, |
| 20 | + Repository) |
20 | 21 | from google.oauth2 import service_account |
21 | 22 | from lxml import etree |
22 | 23 | from markdown2 import markdown |
@@ -146,7 +147,7 @@ def start_platforms(repository, delay=None, platform=None) -> None: |
146 | 147 |
|
147 | 148 | with app.app_context(): |
148 | 149 | from flask import current_app |
149 | | - app = current_app._get_current_object() |
| 150 | + app = current_app._get_current_object() # type: ignore[attr-defined] |
150 | 151 |
|
151 | 152 | # Create a database session |
152 | 153 | db = create_session(config.get('DATABASE_URI', '')) |
@@ -792,7 +793,7 @@ def schedule_test(gh_commit: Commit.Commit) -> None: |
792 | 793 |
|
793 | 794 |
|
794 | 795 | def update_status_on_github(gh_commit: Commit.Commit, state, description, context, |
795 | | - target_url=GithubObject.NotSet): # type: ignore |
| 796 | + target_url=GithubObject.NotSet): |
796 | 797 | """ |
797 | 798 | Update status on GitHub. |
798 | 799 |
|
@@ -1005,7 +1006,11 @@ def start_ci(): |
1005 | 1006 | g.log.warning(f'CI payload is empty') |
1006 | 1007 | abort(abort_code) |
1007 | 1008 |
|
1008 | | - gh = Github(g.github['bot_token']) |
| 1009 | + if not g.github['bot_token']: |
| 1010 | + g.log.error('GitHub token not configured, cannot process webhook') |
| 1011 | + return json.dumps({'msg': 'GitHub token not configured'}), 500 |
| 1012 | + |
| 1013 | + gh = Github(auth=Auth.Token(g.github['bot_token'])) |
1009 | 1014 | repository = gh.get_repo(f"{g.github['repository_owner']}/{g.github['repository']}") |
1010 | 1015 |
|
1011 | 1016 | if event == "push": |
@@ -1413,7 +1418,11 @@ def progress_type_request(log, test, test_id, request) -> bool: |
1413 | 1418 | g.db.add(progress) |
1414 | 1419 | g.db.commit() |
1415 | 1420 |
|
1416 | | - gh = Github(g.github['bot_token']) |
| 1421 | + if not g.github['bot_token']: |
| 1422 | + log.error('GitHub token not configured, cannot update status on GitHub') |
| 1423 | + return True |
| 1424 | + |
| 1425 | + gh = Github(auth=Auth.Token(g.github['bot_token'])) |
1417 | 1426 | repository = gh.get_repo(f"{g.github['repository_owner']}/{g.github['repository']}") |
1418 | 1427 | # Store the test commit for testing in case of commit |
1419 | 1428 | if status == TestStatus.completed and is_main_repo(test.fork.github): |
@@ -1786,8 +1795,11 @@ def comment_pr(test: Test) -> str: |
1786 | 1795 | template = app.jinja_env.get_or_select_template('ci/pr_comment.txt') |
1787 | 1796 | message = template.render(comment_info=comment_info, test_id=test_id, platform=platform) |
1788 | 1797 | log.debug(f"GitHub PR Comment Message Created for Test_id: {test_id}") |
| 1798 | + if not g.github['bot_token']: |
| 1799 | + log.error(f"GitHub token not configured, cannot post PR comment for Test_id: {test_id}") |
| 1800 | + return Status.FAILURE |
1789 | 1801 | try: |
1790 | | - gh = Github(g.github['bot_token']) |
| 1802 | + gh = Github(auth=Auth.Token(g.github['bot_token'])) |
1791 | 1803 | repository = gh.get_repo(f"{g.github['repository_owner']}/{g.github['repository']}") |
1792 | 1804 | # Pull requests are just issues with code, so GitHub considers PR comments in issues |
1793 | 1805 | pull_request = repository.get_pull(number=test.pr_nr) |
@@ -1858,9 +1870,13 @@ def blocked_users(): |
1858 | 1870 | g.db.commit() |
1859 | 1871 | flash('User blocked successfully.') |
1860 | 1872 |
|
| 1873 | + if not g.github['bot_token']: |
| 1874 | + g.log.error('GitHub token not configured, cannot check blocked user PRs') |
| 1875 | + return redirect(url_for('.blocked_users')) |
| 1876 | + |
1861 | 1877 | try: |
1862 | 1878 | # Remove any queued pull request from blocked user |
1863 | | - gh = Github(g.github['bot_token']) |
| 1879 | + gh = Github(auth=Auth.Token(g.github['bot_token'])) |
1864 | 1880 | repository = gh.get_repo(f"{g.github['repository_owner']}/{g.github['repository']}") |
1865 | 1881 | # Getting all pull requests by blocked user on the repo |
1866 | 1882 | pulls = repository.get_pulls(state='open') |
|
0 commit comments