Added descriptions to GitHub starred imports

This commit is contained in:
Imran Remtulla
2022-11-12 10:40:54 -05:00
parent 18951d6461
commit 3100a3a08c
3 changed files with 22 additions and 16 deletions

View File

@@ -12,14 +12,20 @@ class GitHubStars implements MassAppUrlSource {
@override
late List<String> requiredArgs = ['Username'];
Future<List<String>> getOnePageOfUserStarredUrls(
Future<Map<String, String>> getOnePageOfUserStarredUrlsWithDescriptions(
String username, int page) async {
Response res = await get(Uri.parse(
'https://${await GitHub().getCredentialPrefixIfAny()}api.github.com/users/$username/starred?per_page=100&page=$page'));
if (res.statusCode == 200) {
return (jsonDecode(res.body) as List<dynamic>)
.map((e) => e['html_url'] as String)
.toList();
Map<String, String> urlsWithDescriptions = {};
for (var e in (jsonDecode(res.body) as List<dynamic>)) {
urlsWithDescriptions.addAll({
e['html_url'] as String: e['description'] != null
? e['description'] as String
: 'No description'
});
}
return urlsWithDescriptions;
} else {
if (res.headers['x-ratelimit-remaining'] == '0') {
throw RateLimitError(
@@ -33,19 +39,20 @@ class GitHubStars implements MassAppUrlSource {
}
@override
Future<List<String>> getUrls(List<String> args) async {
Future<Map<String, String>> getUrlsWithDescriptions(List<String> args) async {
if (args.length != requiredArgs.length) {
throw ObtainiumError('Wrong number of arguments provided');
}
List<String> urls = [];
Map<String, String> urlsWithDescriptions = {};
var page = 1;
while (true) {
var pageUrls = await getOnePageOfUserStarredUrls(args[0], page++);
urls.addAll(pageUrls);
var pageUrls =
await getOnePageOfUserStarredUrlsWithDescriptions(args[0], page++);
urlsWithDescriptions.addAll(pageUrls);
if (pageUrls.length < 100) {
break;
}
}
return urls;
return urlsWithDescriptions;
}
}

View File

@@ -357,8 +357,10 @@ class _ImportExportPageState extends State<ImportExportPage> {
setState(() {
importInProgress = true;
});
var urls = await source
.getUrls(values);
var urlsWithDescriptions =
await source
.getUrlsWithDescriptions(
values);
var selectedUrls =
await showDialog<
List<String>?>(
@@ -368,10 +370,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
ctx) {
return UrlSelectionModal(
urlsWithDescriptions:
Map.fromIterable(
urls,
value: (item) =>
''));
urlsWithDescriptions);
});
if (selectedUrls != null) {
var errors =

View File

@@ -167,7 +167,7 @@ class AppSource {
abstract class MassAppUrlSource {
late String name;
late List<String> requiredArgs;
Future<List<String>> getUrls(List<String> args);
Future<Map<String, String>> getUrlsWithDescriptions(List<String> args);
}
class SourceProvider {