1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-12 16:38:36 +01:00

refactor: use gql data for org repos

This commit is contained in:
Rongjian Zhang 2022-09-18 15:44:25 +08:00
parent fac17a69ef
commit 66e14509de
4 changed files with 12 additions and 66 deletions

View File

@ -61,11 +61,11 @@ query Gists($login: String!, $after: String) {
# single gist
query Gist($login: String!, $name: String!) {
user(login:$login) {
user(login: $login) {
gist(name: $name) {
name
files {
name
name
language {
name
}
@ -148,7 +148,7 @@ fragment ReposRepoItem on Repository {
updatedAt
}
query Repos($login: String!, $after: String) {
user(login: $login) {
repositoryOwner(login: $login) {
repositories(
first: 30
after: $after
@ -1061,8 +1061,12 @@ query Issue($owner: String!, $name: String!, $number: Int!, $cursor: String) {
# Releases
query Releases($name: String!, $owner: String!, $cursor: String) {
repository(name: $name, owner: $owner) {
releases(first: 30, after: $cursor, orderBy: { field: CREATED_AT, direction:DESC }) {
repository(name: $name, owner: $owner) {
releases(
first: 30
after: $cursor
orderBy: { field: CREATED_AT, direction: DESC }
) {
pageInfo {
...PageInfoParts
}
@ -1086,4 +1090,4 @@ query Releases($name: String!, $owner: String!, $cursor: String) {
}
}
}
}
}

View File

@ -37,7 +37,6 @@ import 'package:git_touch/screens/gh_issue.dart';
import 'package:git_touch/screens/gh_issue_form.dart';
import 'package:git_touch/screens/gh_issues.dart';
import 'package:git_touch/screens/gh_object.dart';
import 'package:git_touch/screens/gh_org_repos.dart';
import 'package:git_touch/screens/gh_orgs.dart';
import 'package:git_touch/screens/gh_pulls.dart';
import 'package:git_touch/screens/gh_releases.dart';
@ -122,9 +121,8 @@ final router = GoRouter(
case 'stars':
return GhStars(login);
case 'repositories':
return GhRepos(login);
case 'orgrepo':
return GhOrgReposScreen(login);
return GhRepos(login);
case 'organizations':
return GhUserOrganizationScreen(login);
case 'gists':

View File

@ -1,56 +0,0 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/repository_item.dart';
import 'package:github/github.dart';
import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago;
/// There are some restrictions of organization repos with OAuth
///
/// https://help.github.com/en/github/setting-up-and-managing-organizations-and-teams/restricting-access-to-your-organizations-data
///
/// So we use RESTful API here for repos of org
class GhOrgReposScreen extends StatelessWidget {
final String owner;
const GhOrgReposScreen(this.owner);
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<Repository, int>(
title: AppBarTitle(AppLocalizations.of(context)!.repositories),
fetch: (page) async {
page = page ?? 1;
final rs = await context
.read<AuthModel>()
.ghClient
.getJSON<List, List<Repository>>(
'/orgs/$owner/repos?sort=updated&page=$page',
convert: (vs) => [for (var v in vs) Repository.fromJson(v)],
);
return ListPayload(
cursor: page + 1,
items: rs,
hasMore: rs.isNotEmpty, // TODO:
);
},
itemBuilder: (v) {
return RepositoryItem.gh(
owner: v.owner!.login,
avatarUrl: v.owner!.avatarUrl,
name: v.name,
description: v.description,
starCount: v.stargazersCount,
forkCount: v.forksCount,
primaryLanguageName: v.language,
primaryLanguageColor: null,
note: 'Updated ${timeago.format(v.updatedAt!)}',
isPrivate: v.isPrivate,
isFork: v.isFork,
);
},
);
}
}

View File

@ -26,7 +26,7 @@ class GhRepos extends StatelessWidget {
});
final OperationResponse<GReposData, GReposVars?> res =
await auth.gqlClient.request(req).first;
final p = res.data!.user!.repositories;
final p = res.data!.repositoryOwner!.repositories;
return ListPayload(
cursor: p.pageInfo.endCursor,
hasMore: p.pageInfo.hasNextPage,