Use github token for version check (#4092)

* Use github token for version check

- Should prevent 403 errors

* Use github token when running version update in unit test
This commit is contained in:
Oliver 2022-12-21 23:00:23 +11:00 committed by GitHub
parent 17b0399d26
commit 4034349043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -9,6 +9,8 @@ jobs:
stable: stable:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3.1.0 uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3.1.0

View File

@ -2,6 +2,7 @@
import json import json
import logging import logging
import os
import re import re
import warnings import warnings
from dataclasses import dataclass from dataclasses import dataclass
@ -338,7 +339,16 @@ def check_for_updates():
logger.info("Could not perform 'check_for_updates' - App registry not ready") logger.info("Could not perform 'check_for_updates' - App registry not ready")
return return
response = requests.get('https://api.github.com/repos/inventree/inventree/releases/latest') headers = {}
# If running within github actions, use authentication token
if settings.TESTING:
token = os.getenv('GITHUB_TOKEN', None)
if token:
headers['Authorization'] = f"Bearer {token}"
response = requests.get('https://api.github.com/repos/inventree/inventree/releases/latest', headers=headers)
if response.status_code != 200: if response.status_code != 200:
raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}') # pragma: no cover raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}') # pragma: no cover

View File

@ -21,7 +21,16 @@ import requests
def get_existing_release_tags(): def get_existing_release_tags():
"""Request information on existing releases via the GitHub API""" """Request information on existing releases via the GitHub API"""
response = requests.get('https://api.github.com/repos/inventree/inventree/releases') # Check for github token
token = os.getenv('GITHUB_TOKEN', None)
headers = None
if token:
headers = {
"Authorization": f"Bearer {token}"
}
response = requests.get('https://api.github.com/repos/inventree/inventree/releases', headers=headers)
if response.status_code != 200: if response.status_code != 200:
raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}') raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}')