2022-08-18 15:33:33 +01:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
2022-08-01 01:16:27 +05:30
|
|
|
import 'package:github/github.dart';
|
2022-08-07 23:40:31 +01:00
|
|
|
import 'package:timeago/timeago.dart';
|
2022-08-01 01:16:27 +05:30
|
|
|
|
|
|
|
class GithubAPI {
|
2022-08-18 15:33:33 +01:00
|
|
|
final GitHub _github = GitHub();
|
2022-08-01 01:16:27 +05:30
|
|
|
|
2022-08-30 02:07:28 +01: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-08-29 17:44:45 +01:00
|
|
|
Future<String?> latestReleaseVersion(String org, String repoName) async {
|
2022-08-18 17:32:58 +01:00
|
|
|
try {
|
|
|
|
var latestRelease = await _github.repositories.getLatestRelease(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
|
|
|
return latestRelease.tagName;
|
|
|
|
} on Exception {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 19:13:43 +01:00
|
|
|
Future<File?> latestReleaseFile(
|
|
|
|
String extension,
|
|
|
|
String org,
|
2022-08-29 17:44:45 +01:00
|
|
|
String repoName,
|
2022-08-19 19:13:43 +01:00
|
|
|
) async {
|
2022-08-09 01:16:33 +01:00
|
|
|
try {
|
2022-08-18 15:33:33 +01:00
|
|
|
var latestRelease = await _github.repositories.getLatestRelease(
|
2022-08-09 01:16:33 +01:00
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
2022-08-18 15:33:33 +01:00
|
|
|
String? url = latestRelease.assets
|
2022-08-09 01:16:33 +01:00
|
|
|
?.firstWhere((asset) =>
|
|
|
|
asset.name != null &&
|
2022-08-19 19:13:43 +01:00
|
|
|
asset.name!.endsWith(extension) &&
|
2022-08-09 01:16:33 +01:00
|
|
|
!asset.name!.contains('-sources') &&
|
|
|
|
!asset.name!.contains('-javadoc'))
|
|
|
|
.browserDownloadUrl;
|
2022-08-18 15:33:33 +01:00
|
|
|
if (url != null) {
|
|
|
|
return await DefaultCacheManager().getSingleFile(url);
|
|
|
|
}
|
2022-08-09 01:16:33 +01:00
|
|
|
} on Exception {
|
2022-08-18 15:33:33 +01:00
|
|
|
return null;
|
2022-08-09 01:16:33 +01:00
|
|
|
}
|
2022-08-18 15:33:33 +01:00
|
|
|
return null;
|
2022-08-01 01:16:27 +05:30
|
|
|
}
|
2022-08-01 23:36:27 +05:30
|
|
|
|
2022-08-29 17:44:45 +01:00
|
|
|
Future<String> latestCommitTime(String org, String repoName) async {
|
2022-08-09 01:16:33 +01:00
|
|
|
try {
|
2022-08-18 15:33:33 +01:00
|
|
|
var repo = await _github.repositories.getRepository(
|
2022-08-09 01:16:33 +01:00
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
);
|
2022-08-17 17:07:00 +01:00
|
|
|
return repo.pushedAt != null
|
2022-08-16 23:19:46 +05:30
|
|
|
? format(repo.pushedAt!, locale: 'en_short')
|
|
|
|
: '';
|
2022-08-09 01:16:33 +01:00
|
|
|
} on Exception {
|
2022-08-17 17:07:00 +01:00
|
|
|
return '';
|
2022-08-09 01:16:33 +01:00
|
|
|
}
|
2022-08-01 23:42:38 +05:30
|
|
|
}
|
2022-08-12 23:37:16 +05:30
|
|
|
|
2022-08-29 17:44:45 +01:00
|
|
|
Future<List<Contributor>> getContributors(String org, String repoName) async {
|
2022-08-26 02:01:53 +01:00
|
|
|
return await (_github.repositories.listContributors(
|
|
|
|
RepositorySlug(org, repoName),
|
|
|
|
)).toList();
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:07:28 +01:00
|
|
|
Future<List<RepositoryCommit>> getCommits(
|
|
|
|
String packageName,
|
|
|
|
String org,
|
|
|
|
String repoName,
|
|
|
|
) async {
|
|
|
|
String path =
|
|
|
|
'src/main/kotlin/app/revanced/patches/${repoAppPath[packageName]}';
|
|
|
|
return await (PaginationHelper(_github)
|
|
|
|
.objects<Map<String, dynamic>, RepositoryCommit>(
|
|
|
|
'GET',
|
|
|
|
'/repos/$org/$repoName/commits',
|
|
|
|
(i) => RepositoryCommit.fromJson(i),
|
|
|
|
params: <String, dynamic>{'path': path},
|
2022-08-26 02:01:53 +01:00
|
|
|
)).toList();
|
2022-08-12 23:37:16 +05:30
|
|
|
}
|
2022-08-01 01:16:27 +05:30
|
|
|
}
|