2019-09-12 15:19:17 +02:00
|
|
|
import 'package:filesize/filesize.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-01-07 08:07:57 +01:00
|
|
|
import 'package:git_touch/graphql/gh.dart';
|
2019-09-27 14:52:38 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2019-09-08 16:17:29 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2020-01-20 07:18:45 +01:00
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
2020-11-04 09:41:04 +01:00
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
2020-01-14 06:51:53 +01:00
|
|
|
import 'package:git_touch/widgets/label.dart';
|
2020-02-08 07:04:02 +01:00
|
|
|
import 'package:git_touch/widgets/language_bar.dart';
|
2020-01-12 07:49:46 +01:00
|
|
|
import 'package:git_touch/widgets/mutation_button.dart';
|
2020-01-29 11:23:51 +01:00
|
|
|
import 'package:git_touch/widgets/repo_header.dart';
|
2019-09-08 16:17:29 +02:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2020-02-08 04:49:31 +01:00
|
|
|
import 'package:github/github.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2020-10-06 16:26:03 +02:00
|
|
|
import 'package:tuple/tuple.dart';
|
2019-09-30 10:31:07 +02:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2020-10-30 07:34:48 +01:00
|
|
|
import 'package:universal_io/prefer_universal/io.dart';
|
2021-01-05 10:25:19 +01:00
|
|
|
import '../generated/l10n.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2020-02-07 07:17:05 +01:00
|
|
|
class GhRepoScreen extends StatelessWidget {
|
2019-02-07 07:35:19 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2019-09-23 11:08:51 +02:00
|
|
|
final String branch;
|
2020-02-07 07:17:05 +01:00
|
|
|
GhRepoScreen(this.owner, this.name, {this.branch});
|
2019-02-10 11:50:40 +01:00
|
|
|
|
2020-10-06 16:26:03 +02:00
|
|
|
Future<GhRepoRepository> _query(BuildContext context) async {
|
|
|
|
var res = await context.read<AuthModel>().gqlClient.execute(GhRepoQuery(
|
|
|
|
variables: GhRepoArguments(
|
|
|
|
owner: owner,
|
|
|
|
name: name,
|
|
|
|
branchSpecified: branch != null,
|
|
|
|
branch: branch ?? '')));
|
|
|
|
return res.data.repository;
|
|
|
|
}
|
|
|
|
|
2020-02-06 06:53:43 +01:00
|
|
|
String _buildWatchState(GhRepoSubscriptionState state) {
|
|
|
|
switch (state) {
|
|
|
|
case GhRepoSubscriptionState.IGNORED:
|
|
|
|
return 'Ignoring';
|
|
|
|
case GhRepoSubscriptionState.SUBSCRIBED:
|
|
|
|
return 'Watching';
|
|
|
|
case GhRepoSubscriptionState.UNSUBSCRIBED:
|
|
|
|
return 'Not watching';
|
|
|
|
default:
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2020-02-08 04:49:31 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2020-11-03 11:44:05 +01:00
|
|
|
return RefreshStatefulScaffold<
|
2020-11-06 11:47:56 +01:00
|
|
|
Tuple3<GhRepoRepository, Future<int>, MarkdownViewData>>(
|
2021-01-05 10:25:19 +01:00
|
|
|
title: AppBarTitle(S.of(context).repository),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () async {
|
2020-11-03 11:44:05 +01:00
|
|
|
final ghClient = context.read<AuthModel>().ghClient;
|
|
|
|
|
|
|
|
final repo = await _query(context);
|
2020-10-06 16:26:03 +02:00
|
|
|
|
2020-11-03 11:44:05 +01:00
|
|
|
final countFuture = ghClient
|
|
|
|
.getJSON('/repos/$owner/$name/stats/contributors')
|
|
|
|
.then((v) => (v as List).length);
|
|
|
|
|
2020-11-06 11:47:56 +01:00
|
|
|
final readmeFactory = (String acceptHeader) {
|
|
|
|
return () {
|
|
|
|
return ghClient.request(
|
|
|
|
'GET',
|
|
|
|
'/repos/$owner/$name/readme',
|
|
|
|
headers: {HttpHeaders.acceptHeader: acceptHeader},
|
|
|
|
).then((res) {
|
|
|
|
return res.body;
|
|
|
|
}).catchError((err) {
|
|
|
|
// 404
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
final readmeData = MarkdownViewData(
|
|
|
|
context,
|
|
|
|
md: readmeFactory('application/vnd.github.v3.raw'),
|
|
|
|
html: readmeFactory('application/vnd.github.v3.html'),
|
|
|
|
);
|
2020-11-03 11:44:05 +01:00
|
|
|
|
2020-11-06 11:47:56 +01:00
|
|
|
return Tuple3(repo, countFuture, readmeData);
|
2019-12-07 09:12:18 +01:00
|
|
|
},
|
2020-10-06 16:26:03 +02:00
|
|
|
actionBuilder: (data, setState) {
|
|
|
|
final repo = data.item1;
|
2019-09-25 15:41:44 +02:00
|
|
|
return ActionButton(
|
2021-01-05 10:25:19 +01:00
|
|
|
title: S.of(context).repositoryActions,
|
2019-09-30 09:46:06 +02:00
|
|
|
items: [
|
2020-01-01 13:59:20 +01:00
|
|
|
ActionItem(
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).projects + '(${repo.projects.totalCount})',
|
2020-01-01 13:59:20 +01:00
|
|
|
url: repo.projectsUrl,
|
|
|
|
),
|
|
|
|
ActionItem(
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).releases + '(${repo.releases.totalCount})',
|
2020-01-01 13:59:20 +01:00
|
|
|
url: 'https://github.com/$owner/$name/releases',
|
|
|
|
),
|
2020-01-27 06:41:17 +01:00
|
|
|
...ActionItem.getUrlActions(repo.url),
|
2019-09-25 15:41:44 +02:00
|
|
|
],
|
|
|
|
);
|
2019-02-10 11:50:40 +01:00
|
|
|
},
|
2020-10-06 16:26:03 +02:00
|
|
|
bodyBuilder: (data, setState) {
|
|
|
|
final repo = data.item1;
|
2020-11-03 11:44:05 +01:00
|
|
|
final contributionFuture = data.item2;
|
2020-11-06 11:47:56 +01:00
|
|
|
final readmeData = data.item3;
|
2020-11-03 11:44:05 +01:00
|
|
|
|
2019-12-07 09:12:18 +01:00
|
|
|
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
|
2019-12-21 09:16:17 +01:00
|
|
|
final license = repo.licenseInfo?.spdxId ?? repo.licenseInfo?.name;
|
2019-11-08 11:29:08 +01:00
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
return Column(
|
2019-09-08 16:17:29 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2019-02-04 14:38:29 +01:00
|
|
|
children: <Widget>[
|
2020-01-29 11:23:51 +01:00
|
|
|
RepoHeader(
|
|
|
|
avatarUrl: repo.owner.avatarUrl,
|
2020-05-12 17:31:30 +02:00
|
|
|
avatarLink: '/github/${repo.owner.login}',
|
2020-01-29 11:23:51 +01:00
|
|
|
name: repo.name,
|
|
|
|
owner: repo.owner.login,
|
|
|
|
description: repo.description,
|
|
|
|
homepageUrl: repo.homepageUrl,
|
|
|
|
actions: [
|
2020-02-06 06:53:43 +01:00
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
MutationButton(
|
2020-02-06 07:23:54 +01:00
|
|
|
active: repo.viewerSubscription ==
|
|
|
|
GhRepoSubscriptionState.SUBSCRIBED,
|
2020-02-06 06:53:43 +01:00
|
|
|
text: _buildWatchState(repo.viewerSubscription),
|
2020-10-08 11:09:50 +02:00
|
|
|
onTap: () async {
|
2020-04-06 05:18:35 +02:00
|
|
|
final vs = GhRepoSubscriptionState.values.where((v) =>
|
|
|
|
v != GhRepoSubscriptionState.ARTEMIS_UNKNOWN);
|
2020-02-06 06:53:43 +01:00
|
|
|
theme.showActions(context, [
|
|
|
|
for (var v in vs)
|
|
|
|
ActionItem(
|
2020-04-06 05:18:35 +02:00
|
|
|
text: _buildWatchState(v),
|
2020-02-06 06:53:43 +01:00
|
|
|
onTap: (_) async {
|
2020-04-06 05:18:35 +02:00
|
|
|
switch (v) {
|
|
|
|
case GhRepoSubscriptionState.SUBSCRIBED:
|
|
|
|
case GhRepoSubscriptionState.IGNORED:
|
2020-10-04 14:37:23 +02:00
|
|
|
final res = await context
|
|
|
|
.read<AuthModel>()
|
|
|
|
.ghClient
|
|
|
|
.activity
|
2020-10-03 08:01:33 +02:00
|
|
|
.setRepositorySubscription(
|
2020-10-04 14:37:23 +02:00
|
|
|
RepositorySlug(
|
|
|
|
repo.owner.login, repo.name),
|
|
|
|
subscribed: v ==
|
|
|
|
GhRepoSubscriptionState
|
|
|
|
.SUBSCRIBED,
|
|
|
|
ignored: v ==
|
|
|
|
GhRepoSubscriptionState.IGNORED,
|
|
|
|
);
|
2020-04-06 05:18:35 +02:00
|
|
|
setState(() {
|
|
|
|
if (res.subscribed) {
|
|
|
|
repo.viewerSubscription =
|
|
|
|
GhRepoSubscriptionState.SUBSCRIBED;
|
|
|
|
} else if (res.ignored) {
|
|
|
|
repo.viewerSubscription =
|
|
|
|
GhRepoSubscriptionState.IGNORED;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case GhRepoSubscriptionState.UNSUBSCRIBED:
|
2020-10-04 14:37:23 +02:00
|
|
|
await context
|
|
|
|
.read<AuthModel>()
|
|
|
|
.ghClient
|
|
|
|
.activity
|
2020-04-06 05:18:35 +02:00
|
|
|
.deleteRepositorySubscription(
|
2020-10-04 14:37:23 +02:00
|
|
|
RepositorySlug(
|
|
|
|
repo.owner.login,
|
|
|
|
repo.name,
|
|
|
|
),
|
|
|
|
);
|
2020-04-06 05:18:35 +02:00
|
|
|
setState(() {
|
2020-02-06 06:53:43 +01:00
|
|
|
repo.viewerSubscription =
|
|
|
|
GhRepoSubscriptionState.UNSUBSCRIBED;
|
2020-04-06 05:18:35 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
2020-02-06 06:53:43 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SizedBox(width: 8),
|
|
|
|
MutationButton(
|
2020-02-06 07:23:54 +01:00
|
|
|
active: repo.viewerHasStarred,
|
2020-02-06 06:53:43 +01:00
|
|
|
text: repo.viewerHasStarred ? 'Unstar' : 'Star',
|
2020-10-08 11:09:50 +02:00
|
|
|
onTap: () async {
|
2020-04-06 05:18:35 +02:00
|
|
|
if (repo.viewerHasStarred) {
|
2020-10-04 14:37:23 +02:00
|
|
|
await context
|
|
|
|
.read<AuthModel>()
|
|
|
|
.ghClient
|
|
|
|
.activity
|
|
|
|
.unstar(
|
|
|
|
RepositorySlug(repo.owner.login, repo.name));
|
2020-04-06 05:18:35 +02:00
|
|
|
} else {
|
2020-10-04 14:37:23 +02:00
|
|
|
await context
|
|
|
|
.read<AuthModel>()
|
|
|
|
.ghClient
|
|
|
|
.activity
|
|
|
|
.star(
|
|
|
|
RepositorySlug(repo.owner.login, repo.name));
|
2020-04-06 05:18:35 +02:00
|
|
|
}
|
2020-02-06 06:53:43 +01:00
|
|
|
setState(() {
|
2020-04-06 05:18:35 +02:00
|
|
|
repo.viewerHasStarred = !repo.viewerHasStarred;
|
2020-02-06 06:53:43 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2020-01-29 11:23:51 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
trailings: <Widget>[
|
|
|
|
if (repo.repositoryTopics.nodes.isNotEmpty)
|
|
|
|
// TODO: link
|
|
|
|
Wrap(
|
|
|
|
spacing: 4,
|
|
|
|
runSpacing: 4,
|
|
|
|
children: repo.repositoryTopics.nodes.map((node) {
|
|
|
|
return MyLabel(
|
|
|
|
name: node.topic.name,
|
|
|
|
// color: Colors.blue.shade50,
|
|
|
|
color: theme.palette.grayBackground,
|
|
|
|
textColor: theme.palette.primary,
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
)
|
|
|
|
],
|
2020-01-01 13:44:18 +01:00
|
|
|
),
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.border,
|
2019-09-08 16:17:29 +02:00
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
EntryItem(
|
2019-12-07 09:12:18 +01:00
|
|
|
count: repo.watchers.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).watchers,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$owner/$name/watchers',
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
EntryItem(
|
2019-12-07 09:12:18 +01:00
|
|
|
count: repo.stargazers.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).stars,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$owner/$name/stargazers',
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
EntryItem(
|
2019-12-07 09:12:18 +01:00
|
|
|
count: repo.forks.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).forks,
|
2020-01-17 07:44:33 +01:00
|
|
|
url: 'https://github.com/$owner/$name/network/members',
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-11 14:22:52 +01:00
|
|
|
if (repo.languages.edges.isNotEmpty) ...[
|
|
|
|
CommonStyle.border,
|
2020-02-08 07:04:02 +01:00
|
|
|
LanguageBar([
|
|
|
|
for (var edge in repo.languages.edges)
|
|
|
|
LanguageBarItem(
|
|
|
|
name: edge.node.name,
|
|
|
|
ratio: edge.size / repo.languages.totalSize,
|
|
|
|
hexColor: edge.node.color,
|
|
|
|
)
|
|
|
|
]),
|
2020-01-11 14:22:52 +01:00
|
|
|
],
|
2019-09-15 09:08:09 +02:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2019-12-07 09:12:18 +01:00
|
|
|
if (ref != null)
|
2019-09-23 10:08:53 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.code,
|
2020-01-22 11:47:58 +01:00
|
|
|
text: Text(repo.primaryLanguage?.name ?? 'Code'),
|
2020-01-14 06:33:02 +01:00
|
|
|
rightWidget: Text(
|
|
|
|
(license == null ? '' : '$license • ') +
|
|
|
|
filesize(repo.diskUsage * 1000),
|
|
|
|
),
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$owner/$name/blob/${ref.name}',
|
2019-09-15 09:08:09 +02:00
|
|
|
),
|
2019-12-07 09:12:18 +01:00
|
|
|
if (repo.hasIssuesEnabled)
|
2019-09-23 10:01:55 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.issue_opened,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).issues),
|
2019-09-30 11:13:12 +02:00
|
|
|
rightWidget:
|
2019-12-07 09:12:18 +01:00
|
|
|
Text(numberFormat.format(repo.issues.totalCount)),
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$owner/$name/issues',
|
2019-09-23 10:01:55 +02:00
|
|
|
),
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_pull_request,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).pullRequests),
|
2019-12-07 09:12:18 +01:00
|
|
|
rightWidget:
|
|
|
|
Text(numberFormat.format(repo.pullRequests.totalCount)),
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$owner/$name/pulls',
|
2019-09-15 09:08:09 +02:00
|
|
|
),
|
2019-12-07 09:12:18 +01:00
|
|
|
if (ref != null) ...[
|
2020-10-06 09:39:40 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.history,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).commits),
|
2020-10-06 09:39:40 +02:00
|
|
|
rightWidget: Text(
|
|
|
|
((ref.target as GhRepoCommit).history?.totalCount ?? 0)
|
|
|
|
.toString()),
|
|
|
|
url: '/github/$owner/$name/commits',
|
|
|
|
),
|
2019-12-07 09:12:18 +01:00
|
|
|
if (repo.refs != null)
|
2019-09-23 13:51:49 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_branch,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).branches),
|
2019-12-07 09:12:18 +01:00
|
|
|
rightWidget: Text(ref.name +
|
2019-09-23 13:51:49 +02:00
|
|
|
' • ' +
|
2019-12-07 09:12:18 +01:00
|
|
|
numberFormat.format(repo.refs.totalCount)),
|
2019-09-23 13:51:49 +02:00
|
|
|
onTap: () async {
|
2019-12-07 09:12:18 +01:00
|
|
|
final refs = repo.refs.nodes;
|
2019-09-25 14:55:06 +02:00
|
|
|
if (refs.length < 2) return;
|
|
|
|
|
2020-02-08 04:49:31 +01:00
|
|
|
await theme.showPicker(
|
2019-09-29 09:35:33 +02:00
|
|
|
context,
|
|
|
|
PickerGroupItem(
|
2019-12-07 09:12:18 +01:00
|
|
|
value: ref.name,
|
2019-09-29 09:35:33 +02:00
|
|
|
items: refs
|
2019-12-07 09:12:18 +01:00
|
|
|
.map((b) => PickerItem(b.name, text: b.name))
|
2019-09-29 09:35:33 +02:00
|
|
|
.toList(),
|
2020-04-06 07:20:11 +02:00
|
|
|
onClose: (ref) {
|
2019-12-12 14:20:24 +01:00
|
|
|
if (ref != branch) {
|
2020-05-12 17:31:30 +02:00
|
|
|
theme.push(
|
|
|
|
context, '/github/$owner/$name?ref=$ref',
|
2019-12-12 14:20:24 +01:00
|
|
|
replace: true);
|
2019-10-06 09:52:41 +02:00
|
|
|
}
|
2019-09-29 09:35:33 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2019-09-23 13:51:49 +02:00
|
|
|
},
|
|
|
|
),
|
2020-10-06 09:39:40 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).contributors),
|
2020-11-03 11:44:05 +01:00
|
|
|
rightWidget: FutureBuilder<int>(
|
|
|
|
future: contributionFuture,
|
2020-10-06 09:39:40 +02:00
|
|
|
builder: (context, snapshot) {
|
2020-11-03 11:44:05 +01:00
|
|
|
return Text(snapshot.data?.toString() ?? '');
|
2020-10-06 09:39:40 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
url: '/github/$owner/$name/contributors',
|
|
|
|
)
|
2019-09-23 13:51:49 +02:00
|
|
|
],
|
2019-09-15 09:08:09 +02:00
|
|
|
],
|
|
|
|
),
|
2020-11-06 11:47:56 +01:00
|
|
|
MarkdownView(readmeData),
|
2019-02-04 14:38:29 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-01-25 13:35:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|