multi file upload
This commit is contained in:
parent
cb94e9e017
commit
c64effea3b
@ -14,7 +14,9 @@ parser.add_argument('--projectId', '-i',
|
|||||||
parser.add_argument('--projectUrl', '-u',
|
parser.add_argument('--projectUrl', '-u',
|
||||||
help='URL of the related project at Gitlab', required=True)
|
help='URL of the related project at Gitlab', required=True)
|
||||||
parser.add_argument('--file', '-f',
|
parser.add_argument('--file', '-f',
|
||||||
help='File to be released', required=True)
|
help='File to be released, can appear multiple times',
|
||||||
|
action='append',
|
||||||
|
required=True)
|
||||||
parser.add_argument('--releaseName', '-n',
|
parser.add_argument('--releaseName', '-n',
|
||||||
help='Name of the release', required=False,
|
help='Name of the release', required=False,
|
||||||
default='')
|
default='')
|
||||||
@ -55,7 +57,7 @@ args = parser.parse_args()
|
|||||||
privateToken = args.privateToken
|
privateToken = args.privateToken
|
||||||
projectId = args.projectId
|
projectId = args.projectId
|
||||||
projectUrl = args.projectUrl
|
projectUrl = args.projectUrl
|
||||||
fileToUpload = args.file
|
filesToUpload = args.file
|
||||||
releaseName = args.releaseName
|
releaseName = args.releaseName
|
||||||
releaseTag = args.releaseTag
|
releaseTag = args.releaseTag
|
||||||
releaseTagTarget = args.releaseTagTarget
|
releaseTagTarget = args.releaseTagTarget
|
||||||
@ -67,6 +69,8 @@ caBundle = args.caBundle
|
|||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
releaseInfo = {}
|
releaseInfo = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (releaseInfoFilename):
|
if (releaseInfoFilename):
|
||||||
with open(releaseInfoFilename, 'r') as releaseInfoFile:
|
with open(releaseInfoFilename, 'r') as releaseInfoFile:
|
||||||
releaseInfo = releaseInfoFile.read()
|
releaseInfo = releaseInfoFile.read()
|
||||||
@ -96,21 +100,25 @@ if releaseDescription == '':
|
|||||||
# --- upload the file
|
# --- upload the file
|
||||||
uploadUrl = "%s/api/v4/projects/%s/uploads" % (instanceUrl, projectId)
|
uploadUrl = "%s/api/v4/projects/%s/uploads" % (instanceUrl, projectId)
|
||||||
headers = {"PRIVATE-TOKEN": privateToken}
|
headers = {"PRIVATE-TOKEN": privateToken}
|
||||||
files = {"file": open(fileToUpload, 'rb')}
|
|
||||||
|
|
||||||
uploadResult = requests.post(uploadUrl, files=files, headers=headers, verify=caBundle)
|
assets = []
|
||||||
|
for f in filesToUpload:
|
||||||
|
files = {"file": open(f, 'rb')}
|
||||||
|
|
||||||
if uploadResult.status_code != 201:
|
uploadResult = requests.post(uploadUrl, files=files, headers=headers, verify=caBundle)
|
||||||
print(uploadResult)
|
|
||||||
print(uploadResult.text)
|
|
||||||
raise Exception('Unable to upload file to Gitlab')
|
|
||||||
|
|
||||||
if verbose:
|
if uploadResult.status_code != 201:
|
||||||
print(uploadResult)
|
print(uploadResult)
|
||||||
print(uploadResult.text)
|
print(uploadResult.text)
|
||||||
print('File successfully uploaded')
|
raise Exception('Unable to upload file to Gitlab')
|
||||||
|
|
||||||
uploadResultJson = json.loads(uploadResult.text)
|
if verbose:
|
||||||
|
print(uploadResult)
|
||||||
|
print(uploadResult.text)
|
||||||
|
print('File {} successfully uploaded'.format(f))
|
||||||
|
|
||||||
|
url = projectUrl + json.loads(uploadResult.text)['url']
|
||||||
|
assets.append({'name': f, 'url': url})
|
||||||
|
|
||||||
# --- create release tag
|
# --- create release tag
|
||||||
if createReleaseTag:
|
if createReleaseTag:
|
||||||
@ -145,19 +153,13 @@ if createReleaseTag:
|
|||||||
# --- create release
|
# --- create release
|
||||||
createReleaseUrl = "%s/api/v4/projects/%s/releases" % (instanceUrl, projectId)
|
createReleaseUrl = "%s/api/v4/projects/%s/releases" % (instanceUrl, projectId)
|
||||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||||
fullUrl = projectUrl + uploadResultJson['url']
|
|
||||||
|
|
||||||
payloadCreateRelease = {
|
payloadCreateRelease = {
|
||||||
"name": releaseName,
|
"name": releaseName,
|
||||||
"tag_name": releaseTag,
|
"tag_name": releaseTag,
|
||||||
"description": releaseDescription,
|
"description": releaseDescription,
|
||||||
"assets": {
|
"assets": {
|
||||||
"links": [
|
"links": assets
|
||||||
{
|
|
||||||
"name": fileToUpload,
|
|
||||||
"url": fullUrl
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user