refactor(gh): create issue with rest api

This commit is contained in:
Rongjian Zhang 2020-04-06 12:03:44 +08:00
parent 80764817ca
commit ea9e26134a
1 changed files with 17 additions and 12 deletions

View File

@ -1,10 +1,12 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:git_touch/graphql/gh.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/common.dart'; import 'package:git_touch/scaffolds/common.dart';
import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/utils/utils.dart';
import 'package:github/github.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class GhIssueFormScreen extends StatefulWidget { class GhIssueFormScreen extends StatefulWidget {
@ -57,20 +59,23 @@ class _GhIssueFormScreenState extends State<GhIssueFormScreen> {
onPressed: () async { onPressed: () async {
final auth = Provider.of<AuthModel>(context); final auth = Provider.of<AuthModel>(context);
final theme = Provider.of<ThemeModel>(context); final theme = Provider.of<ThemeModel>(context);
final r0 = await auth.gqlClient.execute(
GhRepoIdQuery( final slug = RepositorySlug(widget.owner, widget.name);
variables:
GhRepoIdArguments(owner: widget.owner, name: widget.name), // TODO: https://github.com/SpinlockLabs/github.dart/issues/211
), // final res = await auth.ghClient.issues
// .create(slug, IssueRequest(title: _title, body: _body));
final response = await auth.ghClient.request(
'POST',
'/repos/${slug.fullName}/issues',
body: jsonEncode({'title': _title, 'body': _body}),
); );
final res = await auth.gqlClient.execute(GhCreateIssueQuery( final res = Issue.fromJson(
variables: GhCreateIssueArguments( jsonDecode(response.body) as Map<String, dynamic>);
repoId: r0.data.repository.id, title: _title, body: _body),
));
final issue = res.data.createIssue.issue;
await theme.push( await theme.push(
context, context,
'/${issue.repository.owner.login}/${issue.repository.name}/issues/${issue.number}', '/${widget.owner}/${widget.name}/issues/${res.number}',
replace: true, replace: true,
); );
}, },