-
Notifications
You must be signed in to change notification settings - Fork 3
/
artifacts.py
39 lines (29 loc) · 966 Bytes
/
artifacts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import os
from subprocess import call # nosec
import requests
CI_PROJECT_ID = os.environ.get('CI_PROJECT_ID')
CI_COMMIT_REF_NAME = os.environ.get('CI_COMMIT_REF_NAME')
PRIVATE_TOKEN = os.environ.get('PRIVATE_TOKEN')
PAYLOAD = {
'job': 'pages',
'scope': 'success'
}
HEADERS = {
'PRIVATE-TOKEN': PRIVATE_TOKEN
}
URL = f'https://gitlab.com/api/v4/projects/{CI_PROJECT_ID}/jobs'
RESPONSE = requests.request("GET", URL, headers=HEADERS, params=PAYLOAD)
LATEST_JOB_ID = RESPONSE.json()[0]['id']
logging.info(LATEST_JOB_ID)
URL = f'https://gitlab.com/api/v4/projects/{CI_PROJECT_ID}/jobs/' \
f'{LATEST_JOB_ID}/artifacts'
RESPONSE = requests.request("GET", URL, headers=HEADERS)
FILE_NAME = 'artifacts.zip'
ARTIFACTS = open(FILE_NAME, 'wb')
ARTIFACTS.write(RESPONSE.content)
ARTIFACTS.close()
PATH_TO_ZIP = FILE_NAME
PATH_TO_OUT = '.public'
UNZIP = ['unzip', '-o', PATH_TO_ZIP, '-d', PATH_TO_OUT]
call(UNZIP, shell=True) # nosec