mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
GitHost AutoConfigure: Handle errors a bit better
This commit is contained in:
@ -20,3 +20,16 @@ class GitRepo {
|
|||||||
return 'GitRepo{fulleName: $fullName, cloneUrl: $cloneUrl}';
|
return 'GitRepo{fulleName: $fullName, cloneUrl: $cloneUrl}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GitHostException implements Exception {
|
||||||
|
static const OAuthFailed = const GitHostException("OAuthFailed");
|
||||||
|
static const RepoExists = const GitHostException("RepoExists");
|
||||||
|
|
||||||
|
final String cause;
|
||||||
|
const GitHostException(this.cause);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "GitHostException: " + cause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,7 +30,7 @@ class GitHub implements GitHost {
|
|||||||
var authCode = uri.queryParameters['code'];
|
var authCode = uri.queryParameters['code'];
|
||||||
if (authCode == null) {
|
if (authCode == null) {
|
||||||
print("GitHub: Missing auth code. Now what?");
|
print("GitHub: Missing auth code. Now what?");
|
||||||
callback();
|
throw GitHostException.OAuthFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._accessCode = await _getAccessCode(authCode);
|
this._accessCode = await _getAccessCode(authCode);
|
||||||
@ -51,7 +51,7 @@ class GitHub implements GitHost {
|
|||||||
response.statusCode.toString() +
|
response.statusCode.toString() +
|
||||||
": " +
|
": " +
|
||||||
response.body);
|
response.body);
|
||||||
return null;
|
throw GitHostException.OAuthFailed;
|
||||||
}
|
}
|
||||||
print("GithubResponse: " + response.body);
|
print("GithubResponse: " + response.body);
|
||||||
|
|
||||||
|
@ -27,19 +27,21 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
print("GitLab: Called onUrl with " + call.arguments.toString());
|
print("GitLab: Called onUrl with " + call.arguments.toString());
|
||||||
|
|
||||||
var url = call.arguments["URL"];
|
String url = call.arguments["URL"];
|
||||||
var uri = Uri.parse(url);
|
var queryParamters = url.substring(url.indexOf('#') + 1);
|
||||||
|
var map = Uri.splitQueryString(queryParamters);
|
||||||
|
|
||||||
var state = uri.queryParameters['state'];
|
var state = map['state'];
|
||||||
if (state != _stateOAuth) {
|
if (state != _stateOAuth) {
|
||||||
print("GitLab: OAuth State incorrect");
|
print("GitLab: OAuth State incorrect");
|
||||||
callback();
|
print("Required State: " + _stateOAuth);
|
||||||
|
print("Actual State: " + state);
|
||||||
|
throw GitHostException.OAuthFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
_accessCode = uri.queryParameters['access_token'];
|
_accessCode = map['access_token'];
|
||||||
if (_accessCode == null) {
|
if (_accessCode == null) {
|
||||||
print("GitLab: Missing access code. Now what?");
|
throw GitHostException.OAuthFailed;
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
@ -19,40 +19,74 @@ class GitHostSetupAutoConfigure extends StatefulWidget {
|
|||||||
|
|
||||||
class GitHostSetupAutoConfigureState extends State<GitHostSetupAutoConfigure> {
|
class GitHostSetupAutoConfigureState extends State<GitHostSetupAutoConfigure> {
|
||||||
GitHost gitHost;
|
GitHost gitHost;
|
||||||
|
String errorMessage = "";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
print("Starting autoconfigure");
|
||||||
gitHost = createGitHost(widget.gitHostType);
|
gitHost = createGitHost(widget.gitHostType);
|
||||||
gitHost.init(() async {
|
try {
|
||||||
print("GitHub Initalized");
|
gitHost.init(() async {
|
||||||
|
print("GitHost Initalized: " + widget.gitHostType.toString());
|
||||||
|
|
||||||
var repo = await gitHost.createRepo("journal");
|
var repo = await gitHost.createRepo("journal");
|
||||||
var publicKey = await generateSSHKeys(comment: "GitJournal");
|
var publicKey = await generateSSHKeys(comment: "GitJournal");
|
||||||
await gitHost.addDeployKey(publicKey, repo.fullName);
|
await gitHost.addDeployKey(publicKey, repo.fullName);
|
||||||
|
|
||||||
widget.onDone(repo.cloneUrl);
|
widget.onDone(repo.cloneUrl);
|
||||||
});
|
});
|
||||||
gitHost.launchOAuthScreen();
|
gitHost.launchOAuthScreen();
|
||||||
|
} on GitHostException catch (e) {
|
||||||
|
print("GitHostSetupAutoConfigur: " + e.toString());
|
||||||
|
setState(() {
|
||||||
|
errorMessage = widget.gitHostType.toString() + ": " + e.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var children = <Widget>[
|
var children = <Widget>[];
|
||||||
Text(
|
if (this.errorMessage == null || this.errorMessage.isEmpty) {
|
||||||
'Configuring ...',
|
children = <Widget>[
|
||||||
textAlign: TextAlign.center,
|
Padding(
|
||||||
style: Theme.of(context).textTheme.display1,
|
padding: const EdgeInsets.all(8.0),
|
||||||
),
|
child: Text(
|
||||||
SizedBox(height: 8.0),
|
'Configuring ...',
|
||||||
Padding(
|
textAlign: TextAlign.center,
|
||||||
padding: const EdgeInsets.all(8.0),
|
style: Theme.of(context).textTheme.display1,
|
||||||
child: CircularProgressIndicator(
|
),
|
||||||
value: null,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 8.0),
|
||||||
];
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
children = <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'Failed',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.display1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
this.errorMessage,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.display1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
Reference in New Issue
Block a user