revanced-manager/lib/services/github_api.dart

69 lines
1.8 KiB
Dart
Raw Normal View History

2022-08-18 16:33:33 +02:00
import 'dart:io';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:github/github.dart';
import 'package:timeago/timeago.dart';
class GithubAPI {
2022-08-18 16:33:33 +02:00
final GitHub _github = GitHub();
2022-08-18 18:32:58 +02:00
Future<String?> latestReleaseVersion(String org, repoName) async {
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,
repoName,
) async {
try {
2022-08-18 16:33:33 +02:00
var latestRelease = await _github.repositories.getLatestRelease(
RepositorySlug(org, repoName),
);
2022-08-18 16:33:33 +02:00
String? url = latestRelease.assets
?.firstWhere((asset) =>
asset.name != null &&
2022-08-19 20:13:43 +02:00
asset.name!.endsWith(extension) &&
!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);
}
} on Exception {
2022-08-18 16:33:33 +02:00
return null;
}
2022-08-18 16:33:33 +02:00
return null;
}
Future<String> latestCommitTime(String org, repoName) async {
try {
2022-08-18 16:33:33 +02:00
var repo = await _github.repositories.getRepository(
RepositorySlug(org, repoName),
);
2022-08-17 18:07:00 +02:00
return repo.pushedAt != null
? format(repo.pushedAt!, locale: 'en_short')
: '';
} on Exception {
2022-08-17 18:07:00 +02:00
return '';
}
}
2022-08-12 20:07:16 +02:00
Future<List<Contributor>> getContributors(String org, repoName) async {
try {
2022-08-18 16:33:33 +02:00
var contributors = _github.repositories.listContributors(
2022-08-12 20:07:16 +02:00
RepositorySlug(org, repoName),
);
return contributors.toList();
} on Exception {
return List.empty();
2022-08-12 20:07:16 +02:00
}
}
}