fix(gitlab): api pagination
This commit is contained in:
parent
06d8d28482
commit
9aec397a60
|
@ -23,6 +23,13 @@ class PlatformType {
|
|||
static const gitlab = 'gitlab';
|
||||
}
|
||||
|
||||
class DataWithPage<T> {
|
||||
T data;
|
||||
int cursor;
|
||||
bool hasMore;
|
||||
DataWithPage(this.data, this.cursor, this.hasMore);
|
||||
}
|
||||
|
||||
class AuthModel with ChangeNotifier {
|
||||
static const _apiPrefix = 'https://api.github.com';
|
||||
|
||||
|
@ -139,12 +146,21 @@ class AuthModel with ChangeNotifier {
|
|||
}
|
||||
|
||||
Future fetchGitlab(String p) async {
|
||||
final res = await http.get(activeAccount.domain + '/api/v4' + p,
|
||||
final res = await http.get('${activeAccount.domain}/api/v4$p',
|
||||
headers: {'Private-Token': token});
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
return info;
|
||||
}
|
||||
|
||||
Future<DataWithPage> fetchGitlabWithPage(String p) async {
|
||||
final res = await http.get('${activeAccount.domain}/api/v4$p',
|
||||
headers: {'Private-Token': token});
|
||||
final next = int.tryParse(
|
||||
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '');
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
return DataWithPage(info, next, next != null);
|
||||
}
|
||||
|
||||
Future fetchGitea(String p) async {
|
||||
final res = await http.get('https://try.gitea.io' + '/api/v1' + p,
|
||||
headers: {'Authorization': ''});
|
||||
|
|
|
@ -20,12 +20,12 @@ class GitlabCommitsScreen extends StatelessWidget {
|
|||
Future<ListPayload<GitlabCommit, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res =
|
||||
await auth.fetchGitlab('/projects/$id/repository/commits?page=$page');
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects/$id/repository/commits?page=$page');
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
hasMore: true, // TODO:
|
||||
items: (res as List).map((v) => GitlabCommit.fromJson(v)).toList(),
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: (res.data as List).map((v) => GitlabCommit.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ class GitlabIssuesScreen extends StatelessWidget {
|
|||
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final res = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$id/issues?page=$page');
|
||||
.fetchGitlabWithPage('/projects/$id/issues?state=opened&page=$page');
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
hasMore: true, // TODO:
|
||||
items: (res as List).map((v) => GitlabIssue.fromJson(v)).toList(),
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: (res.data as List).map((v) => GitlabIssue.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ class GitlabMergeRequestsScreen extends StatelessWidget {
|
|||
|
||||
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final res = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$id/merge_requests?page=$page');
|
||||
final res = await Provider.of<AuthModel>(context).fetchGitlabWithPage(
|
||||
'/projects/$id/merge_requests?state=opened&page=$page');
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
hasMore: true, // TODO:
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: (res as List).map((v) => GitlabIssue.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue