2022-08-18 16:33:33 +02:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
import 'package:github/github.dart';
|
2022-08-08 00:40:31 +02:00
|
|
|
import 'package:timeago/timeago.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
|
|
|
|
class GithubAPI {
|
2022-08-18 16:33:33 +02:00
|
|
|
final GitHub _github = GitHub();
|
2022-07-31 21:46:27 +02:00
|
|
|
|
2022-08-29 18:44:45 +02:00
|
|
|
Future<String?> latestReleaseVersion(String org, String repoName) async {
|
2022-08-18 18:32:58 +02:00
|
|
|
try {
|
|
|
|
var latestRelease = await _github.repositories.getLatestRelease(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
|
|
|
return latestRelease.tagName;
|
|
|
|
} on Exception {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:13:43 +02:00
|
|
|
Future<File?> latestReleaseFile(
|
|
|
|
String extension,
|
|
|
|
String org,
|
2022-08-29 18:44:45 +02:00
|
|
|
String repoName,
|
2022-08-19 20:13:43 +02:00
|
|
|
) async {
|
2022-08-09 02:16:33 +02:00
|
|
|
try {
|
2022-08-18 16:33:33 +02:00
|
|
|
var latestRelease = await _github.repositories.getLatestRelease(
|
2022-08-09 02:16:33 +02:00
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
2022-08-18 16:33:33 +02:00
|
|
|
String? url = latestRelease.assets
|
2022-08-09 02:16:33 +02:00
|
|
|
?.firstWhere((asset) =>
|
|
|
|
asset.name != null &&
|
2022-08-19 20:13:43 +02:00
|
|
|
asset.name!.endsWith(extension) &&
|
2022-08-09 02:16:33 +02:00
|
|
|
!asset.name!.contains('-sources') &&
|
|
|
|
!asset.name!.contains('-javadoc'))
|
|
|
|
.browserDownloadUrl;
|
2022-08-18 16:33:33 +02:00
|
|
|
if (url != null) {
|
|
|
|
return await DefaultCacheManager().getSingleFile(url);
|
|
|
|
}
|
2022-08-09 02:16:33 +02:00
|
|
|
} on Exception {
|
2022-08-18 16:33:33 +02:00
|
|
|
return null;
|
2022-08-09 02:16:33 +02:00
|
|
|
}
|
2022-08-18 16:33:33 +02:00
|
|
|
return null;
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|
2022-08-01 20:06:27 +02:00
|
|
|
|
2022-08-29 18:44:45 +02:00
|
|
|
Future<String> latestCommitTime(String org, String repoName) async {
|
2022-08-09 02:16:33 +02:00
|
|
|
try {
|
2022-08-18 16:33:33 +02:00
|
|
|
var repo = await _github.repositories.getRepository(
|
2022-08-09 02:16:33 +02:00
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
2022-08-17 18:07:00 +02:00
|
|
|
return repo.pushedAt != null
|
2022-08-16 19:49:46 +02:00
|
|
|
? format(repo.pushedAt!, locale: 'en_short')
|
|
|
|
: '';
|
2022-08-09 02:16:33 +02:00
|
|
|
} on Exception {
|
2022-08-17 18:07:00 +02:00
|
|
|
return '';
|
2022-08-09 02:16:33 +02:00
|
|
|
}
|
2022-08-01 20:12:38 +02:00
|
|
|
}
|
2022-08-12 20:07:16 +02:00
|
|
|
|
2022-08-29 18:44:45 +02:00
|
|
|
Future<List<Contributor>> getContributors(String org, String repoName) async {
|
2022-08-26 03:01:53 +02:00
|
|
|
return await (_github.repositories.listContributors(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
)).toList();
|
|
|
|
}
|
|
|
|
|
2022-08-29 18:44:45 +02:00
|
|
|
Future<List<RepositoryCommit>> getCommits(String org, String repoName) async {
|
2022-08-26 03:01:53 +02:00
|
|
|
return await (_github.repositories.listCommits(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
)).toList();
|
2022-08-12 20:07:16 +02:00
|
|
|
}
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|