2022-07-31 21:46:27 +02:00
|
|
|
import 'package:github/github.dart';
|
2022-08-06 14:13:28 +02:00
|
|
|
import 'package:injectable/injectable.dart';
|
2022-08-08 00:40:31 +02:00
|
|
|
import 'package:timeago/timeago.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
|
2022-08-06 14:13:28 +02:00
|
|
|
@lazySingleton
|
2022-07-31 21:46:27 +02:00
|
|
|
class GithubAPI {
|
|
|
|
var github = GitHub();
|
|
|
|
|
2022-08-02 09:55:01 +02:00
|
|
|
Future<String?> latestRelease(String org, repoName) async {
|
2022-08-09 02:16:33 +02:00
|
|
|
String? dlurl = '';
|
|
|
|
try {
|
|
|
|
var latestRelease = await github.repositories.getLatestRelease(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
|
|
|
dlurl = latestRelease.assets
|
|
|
|
?.firstWhere((asset) =>
|
|
|
|
asset.name != null &&
|
|
|
|
(asset.name!.endsWith('.dex') || asset.name!.endsWith('.apk')) &&
|
|
|
|
!asset.name!.contains('-sources') &&
|
|
|
|
!asset.name!.contains('-javadoc'))
|
|
|
|
.browserDownloadUrl;
|
|
|
|
} on Exception {
|
|
|
|
dlurl = '';
|
|
|
|
}
|
2022-08-02 09:55:01 +02:00
|
|
|
return dlurl;
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|
2022-08-01 20:06:27 +02:00
|
|
|
|
2022-08-08 00:40:31 +02:00
|
|
|
Future<String> latestCommitTime(String org, repoName) async {
|
2022-08-09 02:16:33 +02:00
|
|
|
String pushedAt = '';
|
|
|
|
try {
|
|
|
|
var repo = await github.repositories.getRepository(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
|
|
|
pushedAt = repo.pushedAt != null ? format(repo.pushedAt!) : '';
|
|
|
|
} on Exception {
|
|
|
|
pushedAt = '';
|
|
|
|
}
|
|
|
|
return pushedAt;
|
2022-08-01 20:12:38 +02:00
|
|
|
}
|
2022-08-12 20:07:16 +02:00
|
|
|
|
|
|
|
Future<List<Contributor>> getContributors(String org, repoName) async {
|
|
|
|
try {
|
|
|
|
var contributors = await github.repositories.listContributors(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
|
|
|
return contributors.toList();
|
|
|
|
} on Exception {
|
|
|
|
print(Exception);
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|