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 14:13:28 +02:00
|
|
|
var dlurl = latestRelease.assets?.first.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
|
|
|
}
|