mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-18 02:39:30 +00:00
ci: authenticate with GitHub API token from the environment
These script now check if GITHUB_API_TOKEN is set in the environment, and use that for authenticating. There is no username needed when an API token is used, but it may not be empty, so it is set to "unused". Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
aa062513c0
commit
b27b2ee074
@ -12,11 +12,16 @@ Exit codes:
|
||||
0: success
|
||||
1: any unexpected failure
|
||||
2: --has-label=<label> was passed, <label> is not set on the PR
|
||||
|
||||
Environment:
|
||||
GITHUB_API_TOKEN: the GitHub "personal access token" to use
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import sys
|
||||
|
||||
LABEL_URL_FMT = 'https://api.github.com/repos/ceph/ceph-csi/issues/%s/labels'
|
||||
'''
|
||||
@ -32,7 +37,15 @@ def get_json_labels(gh_id):
|
||||
'''
|
||||
url = LABEL_URL_FMT % gh_id
|
||||
headers = {'Accept': 'application/vnd.github.v3+json'}
|
||||
res = requests.get(url, headers=headers)
|
||||
|
||||
auth = None
|
||||
if 'GITHUB_API_TOKEN' in os.environ:
|
||||
github_api_token = os.environ['GITHUB_API_TOKEN']
|
||||
if github_api_token != '':
|
||||
# the username "unused" is not relevant, needs to be non-empty
|
||||
auth = HTTPBasicAuth('unused', github_api_token)
|
||||
|
||||
res = requests.get(url, headers=headers, auth=auth)
|
||||
|
||||
# if "res.status_code != requests.codes.ok", raise an exception
|
||||
res.raise_for_status()
|
||||
|
@ -5,11 +5,16 @@ release for a major version.
|
||||
|
||||
Parameters:
|
||||
--version=<version>: the major version to find the latest patch release for, i.e. v1.19
|
||||
|
||||
Environment:
|
||||
GITHUB_API_TOKEN: the GitHub "personal access token" to use
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import sys
|
||||
|
||||
RELEASE_URL = 'https://api.github.com/repos/kubernetes/kubernetes/releases'
|
||||
'''
|
||||
@ -24,6 +29,14 @@ def get_json_releases():
|
||||
obtained.
|
||||
'''
|
||||
headers = {'Accept': 'application/vnd.github.v3+json'}
|
||||
|
||||
auth = None
|
||||
if 'GITHUB_API_TOKEN' in os.environ:
|
||||
github_api_token = os.environ['GITHUB_API_TOKEN']
|
||||
if github_api_token != '':
|
||||
# the username "unused" is not relevant, needs to be non-empty
|
||||
auth = HTTPBasicAuth('unused', github_api_token)
|
||||
|
||||
res = requests.get(RELEASE_URL, headers=headers)
|
||||
|
||||
# if "res.status_code != requests.codes.ok", raise an exception
|
||||
|
Loading…
Reference in New Issue
Block a user