Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/bundle_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
if: startswith(github.repository, 'adafruit/')
steps:
- name: Set up Python 3.12
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Load contributor cache
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Versions
run: |
python3 --version
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/learn_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# default branches).
if: ${{ (github.repository_owner == 'adafruit') }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/Adafruit_Learning_System_Guides
token: ${{ secrets.ADABOT_GITHUB_ACCESS_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/reports_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ jobs:
BIGQUERY_PRIVATE_KEY: ${{ secrets.BIGQUERY_PRIVATE_KEY }}
BIGQUERY_CLIENT_EMAIL: ${{ secrets.BIGQUERY_CLIENT_EMAIL }}
steps:
- name: Set up Python 3.9
uses: actions/setup-python@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Versions
run: |
python3 --version
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install deps
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
if: startswith(github.repository, 'adafruit/')
steps:
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3
- name: Versions
run: |
python3 --version
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install deps
Expand Down
20 changes: 20 additions & 0 deletions adabot/github_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"""Wrapper for GitHub requests."""

import types
from base64 import b64encode
import datetime
import functools
Expand Down Expand Up @@ -57,6 +58,23 @@ def _fix_kwargs(kwargs):
return kwargs


def _safe_response_json(self):
"""
overridden response.json() function that will catch JSONDecodeError
log it but try to continue on afterward.
"""
try:
return self.original_json()
except requests.exceptions.JSONDecodeError:
exception_text = traceback.format_exc()
if "ADABOT_GITHUB_ACCESS_TOKEN" in os.environ:
exception_text = exception_text.replace(
os.environ["ADABOT_GITHUB_ACCESS_TOKEN"], "[secure]"
)
logging.warning("%s", exception_text)
return {}


def request(method, url, **kwargs):
"""Processes request for `url`."""
try:
Expand Down Expand Up @@ -107,6 +125,8 @@ def request(method, url, **kwargs):
logging.info("Sleeping %s seconds", reset_diff.seconds + 60)
time.sleep(reset_diff.seconds + 60)

response.original_json = response.json
response.json = types.MethodType(_safe_response_json, response)
return response


Expand Down