revanced-manager/lib/services/github_api.dart

66 lines
1.9 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';
2022-08-17 18:07:00 +02:00
import 'package:revanced_manager/models/patched_application.dart';
import 'package:timeago/timeago.dart';
class GithubAPI {
2022-08-18 16:33:33 +02:00
final GitHub _github = GitHub();
2022-08-18 16:33:33 +02:00
Future<File?> latestRelease(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 &&
(asset.name!.endsWith('.dex') || asset.name!.endsWith('.apk')) &&
!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
}
}
2022-08-17 18:07:00 +02:00
Future<bool> hasUpdates(PatchedApplication app, String org, repoName) async {
// TODO: get status based on last update time on the folder of this app?
return true;
}
Future<String> getChangelog(
PatchedApplication app, String org, repoName) async {
// TODO: get changelog based on last commits on the folder of this app?
return 'fix: incorrect fingerprint version';
}
}