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-30 03:07:28 +02:00
|
|
|
final Map<String, String> repoAppPath = {
|
|
|
|
'com.google.android.youtube': 'youtube',
|
|
|
|
'com.google.android.apps.youtube.music': 'music',
|
|
|
|
'com.twitter.android': 'twitter',
|
|
|
|
'com.reddit.frontpage': 'reddit',
|
|
|
|
'com.zhiliaoapp.musically': 'tiktok',
|
|
|
|
'de.dwd.warnapp': 'warnwetter',
|
|
|
|
'com.garzotto.pflotsh.ecmwf_a': 'ecmwf',
|
|
|
|
};
|
|
|
|
|
2022-09-07 03:41:02 +02:00
|
|
|
Future<String?> latestReleaseVersion(String repoName) async {
|
2022-08-18 18:32:58 +02:00
|
|
|
try {
|
|
|
|
var latestRelease = await _github.repositories.getLatestRelease(
|
2022-09-07 03:41:02 +02:00
|
|
|
RepositorySlug.full(repoName),
|
2022-08-18 18:32:58 +02:00
|
|
|
);
|
|
|
|
return latestRelease.tagName;
|
|
|
|
} on Exception {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-07 03:41:02 +02:00
|
|
|
Future<File?> latestReleaseFile(String extension, String repoName) 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-09-07 03:41:02 +02:00
|
|
|
RepositorySlug.full(repoName),
|
2022-08-09 02:16:33 +02:00
|
|
|
);
|
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-09-07 03:41:02 +02:00
|
|
|
Future<String> latestCommitTime(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-09-07 03:41:02 +02:00
|
|
|
RepositorySlug.full(repoName),
|
2022-08-09 02:16:33 +02:00
|
|
|
);
|
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-09-07 03:41:02 +02:00
|
|
|
Future<List<Contributor>> getContributors(String repoName) async {
|
2022-08-26 03:01:53 +02:00
|
|
|
return await (_github.repositories.listContributors(
|
2022-09-07 03:41:02 +02:00
|
|
|
RepositorySlug.full(repoName),
|
2022-08-26 03:01:53 +02:00
|
|
|
)).toList();
|
|
|
|
}
|
|
|
|
|
2022-08-30 03:07:28 +02:00
|
|
|
Future<List<RepositoryCommit>> getCommits(
|
|
|
|
String packageName,
|
|
|
|
String repoName,
|
|
|
|
) async {
|
|
|
|
String path =
|
|
|
|
'src/main/kotlin/app/revanced/patches/${repoAppPath[packageName]}';
|
|
|
|
return await (PaginationHelper(_github)
|
|
|
|
.objects<Map<String, dynamic>, RepositoryCommit>(
|
|
|
|
'GET',
|
2022-09-07 03:41:02 +02:00
|
|
|
'/repos/$repoName/commits',
|
2022-08-30 03:07:28 +02:00
|
|
|
(i) => RepositoryCommit.fromJson(i),
|
|
|
|
params: <String, dynamic>{'path': path},
|
2022-08-26 03:01:53 +02:00
|
|
|
)).toList();
|
2022-08-12 20:07:16 +02:00
|
|
|
}
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|