uploadToGitlab static method
Implementation
static Future<String?> uploadToGitlab(String filePath) async {
final config = FlutterReleaseXConfig().config;
final gitlabConfig = config.uploadOptions.gitlab;
if (!gitlabConfig.enabled) {
return null;
}
final token = gitlabConfig.token;
final projectId = gitlabConfig.projectId;
final tag = gitlabConfig.tag;
final host = gitlabConfig.host ?? 'https://gitlab.com';
final ref = gitlabConfig.ref ?? 'main';
if (token == null || token.isEmpty) {
print('❌ GitLab token not found. Please check your config yaml file.');
return null;
}
if (projectId == null || projectId.isEmpty) {
print(
'❌ GitLab Project ID not found. Please check your config yaml file.');
return null;
}
try {
final file = File(filePath);
if (!file.existsSync()) {
print('❌ File not found: $filePath');
return null;
}
final fileName = path.basename(filePath);
final apiBaseUrl = '$host/api/v4';
// Check if release exists for the tag
final existingRelease = await _findReleaseByTag(
apiBaseUrl, projectId, tag ?? 'v0.0.1', token);
if (existingRelease != null) {
// Delete existing release
await _deleteRelease(apiBaseUrl, projectId, tag ?? 'v0.0.1', token);
}
// Create new release
final release = await _createRelease(
apiBaseUrl, projectId, tag ?? 'v0.0.1', fileName, token, ref);
if (release == null) {
print('❌ Failed to create GitLab release');
return null;
}
// Upload file as release asset
final downloadUrl = await _uploadReleaseAsset(
apiBaseUrl, projectId, tag ?? 'v0.0.1', filePath, fileName, token);
if (downloadUrl != null) {
FlutterReleaseXIndividualUploadService.updateUrlLinkState(downloadUrl);
return downloadUrl;
}
return null;
} catch (e) {
print('❌ Error uploading to GitLab: $e');
return null;
}
}