Merge branch 'hotfix-release-script' into 'master'

release.py: Replace default user agent by that of curl

See merge request s3lph/spaceapi-server!2
This commit is contained in:
s3lph 2020-06-21 03:15:33 +00:00
commit a3eb452786

View file

@ -10,6 +10,9 @@ import http.client
from urllib.error import HTTPError from urllib.error import HTTPError
USER_AGENT = 'curl/7.70.0'
def parse_changelog(tag: str) -> Optional[str]: def parse_changelog(tag: str) -> Optional[str]:
release_changelog: str = '' release_changelog: str = ''
with open('CHANGELOG.md', 'r') as f: with open('CHANGELOG.md', 'r') as f:
@ -32,7 +35,8 @@ def parse_changelog(tag: str) -> Optional[str]:
def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str, str]: def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str, str]:
url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs' url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs'
headers: Dict[str, str] = { headers: Dict[str, str] = {
'Private-Token': api_token 'Private-Token': api_token,
'User-Agent': USER_AGENT
} }
req = urllib.request.Request(url, headers=headers) req = urllib.request.Request(url, headers=headers)
try: try:
@ -52,7 +56,10 @@ def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str
def fetch_single_shafile(url: str) -> str: def fetch_single_shafile(url: str) -> str:
req = urllib.request.Request(url) headers: Dict[str, str] = {
'User-Agent': USER_AGENT
}
req = urllib.request.Request(url, headers=headers)
try: try:
resp: http.client.HTTPResponse = urllib.request.urlopen(req) resp: http.client.HTTPResponse = urllib.request.urlopen(req)
except HTTPError as e: except HTTPError as e:
@ -137,7 +144,8 @@ def main():
f'https://gitlab.com/api/v4/projects/{project_id}/repository/tags/{release_tag}/release' f'https://gitlab.com/api/v4/projects/{project_id}/repository/tags/{release_tag}/release'
headers: Dict[str, str] = { headers: Dict[str, str] = {
'Private-Token': api_token, 'Private-Token': api_token,
'Content-Type': 'application/json; charset=utf-8' 'Content-Type': 'application/json; charset=utf-8',
'User-Agent': USER_AGENT
} }
request = urllib.request.Request( request = urllib.request.Request(