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-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-07-31 21:46:27 +02:00
|
|
|
var latestRelease = await github.repositories
|
|
|
|
.getLatestRelease(RepositorySlug(org, repoName));
|
2022-08-06 15:04:18 +02:00
|
|
|
var dlurl = latestRelease.assets
|
|
|
|
?.firstWhere((asset) =>
|
|
|
|
asset.name != null &&
|
2022-08-07 00:01:05 +02:00
|
|
|
(asset.name!.endsWith('.dex') || asset.name!.endsWith('.apk')) &&
|
2022-08-06 15:04:18 +02:00
|
|
|
!asset.name!.contains('-sources') &&
|
|
|
|
!asset.name!.contains('-javadoc'))
|
|
|
|
.browserDownloadUrl;
|
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
|
|
|
|
|
|
|
Future latestCommitTime(String org, repoName) async {
|
2022-08-01 20:12:38 +02:00
|
|
|
var repo =
|
2022-08-01 20:06:27 +02:00
|
|
|
await github.repositories.getRepository(RepositorySlug(org, repoName));
|
2022-08-01 20:12:38 +02:00
|
|
|
|
|
|
|
var commitTime = repo.pushedAt?.difference(
|
2022-08-01 20:06:27 +02:00
|
|
|
DateTime.now().toLocal(),
|
|
|
|
);
|
|
|
|
|
|
|
|
final hours = commitTime!.inHours.abs();
|
|
|
|
|
|
|
|
if (hours > 24) {
|
|
|
|
var days = (commitTime.inDays).abs().toString();
|
|
|
|
return "$days days";
|
|
|
|
} else if (hours > 1 && hours < 24) {
|
|
|
|
var hours = (commitTime.inHours).abs().toString();
|
|
|
|
return "$hours hours";
|
|
|
|
} else {
|
|
|
|
var minutes = (commitTime.inMinutes).abs().toString();
|
|
|
|
return "$minutes mins";
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 20:12:38 +02:00
|
|
|
|
|
|
|
Future contributors(String org, repoName) async {
|
|
|
|
var contributors =
|
|
|
|
github.repositories.listContributors(RepositorySlug(org, repoName));
|
2022-08-06 14:13:28 +02:00
|
|
|
contributors.forEach((contributor) {});
|
2022-08-01 20:12:38 +02:00
|
|
|
return contributors;
|
|
|
|
}
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|