From 3824b386d7a51207fcb68114be85f2698e778d0f Mon Sep 17 00:00:00 2001 From: Achim Date: Sat, 9 Mar 2024 10:11:54 +0100 Subject: [PATCH] Regroup functions by their intention This may prepare for later refactorings and code simplification --- lib/app_sources/gitlab.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/app_sources/gitlab.dart b/lib/app_sources/gitlab.dart index dac4469..df200f7 100644 --- a/lib/app_sources/gitlab.dart +++ b/lib/app_sources/gitlab.dart @@ -109,17 +109,20 @@ class GitLab extends AppSource { String standardUrl, Map additionalSettings, ) async { - bool fallbackToOlderReleases = - additionalSettings['fallbackToOlderReleases'] == true; - String? PAT = await getPATIfAny(hostChanged ? additionalSettings : {}); - Iterable apkDetailsList = []; + // Prepare request params var names = GitHub().getAppNames(standardUrl); + String? PAT = await getPATIfAny(hostChanged ? additionalSettings : {}); + + // Request data from REST API Response res = await sourceRequest( 'https://${hosts[0]}/api/v4/projects/${names.author}%2F${names.name}/releases?private_token=$PAT', additionalSettings); if (res.statusCode != 200) { throw getObtainiumHttpError(res); } + + // Extract .apk details from received data + Iterable apkDetailsList = []; var json = jsonDecode(res.body) as List; apkDetailsList = json.map((e) { var apkUrlsFromAssets = (e['assets']?['links'] as List? ?? []) @@ -153,6 +156,10 @@ class GitLab extends AppSource { if (apkDetailsList.isEmpty) { throw NoReleasesError(note: tr('gitlabSourceNote')); } + + // Fallback procedure + bool fallbackToOlderReleases = + additionalSettings['fallbackToOlderReleases'] == true; if (fallbackToOlderReleases) { if (additionalSettings['trackOnly'] != true) { apkDetailsList = @@ -162,6 +169,7 @@ class GitLab extends AppSource { throw NoReleasesError(note: tr('gitlabSourceNote')); } } + return apkDetailsList.first; } }