mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
OnBoarding: Integrate GitLab api
Now we can also automatically create a GitLab repo + configure it.
This commit is contained in:
@ -1,24 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:journal/apis/github.dart';
|
|
||||||
import 'package:journal/apis/git.dart';
|
import 'package:journal/apis/git.dart';
|
||||||
|
import 'package:journal/apis/githost_factory.dart';
|
||||||
enum GitRemoteRepo {
|
|
||||||
GitHub,
|
|
||||||
Gitlab,
|
|
||||||
Custom,
|
|
||||||
}
|
|
||||||
|
|
||||||
class OnBoardingAutoConfigure extends StatefulWidget {
|
class OnBoardingAutoConfigure extends StatefulWidget {
|
||||||
final GitRemoteRepo remoteRepo;
|
final GitHostType gitHostType;
|
||||||
final Function onDone;
|
final Function onDone;
|
||||||
|
|
||||||
OnBoardingAutoConfigure({
|
OnBoardingAutoConfigure({
|
||||||
@required this.remoteRepo,
|
@required this.gitHostType,
|
||||||
@required this.onDone,
|
@required this.onDone,
|
||||||
}) {
|
});
|
||||||
assert(remoteRepo == GitRemoteRepo.GitHub);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
OnBoardingAutoConfigureState createState() {
|
OnBoardingAutoConfigureState createState() {
|
||||||
@ -27,22 +18,23 @@ class OnBoardingAutoConfigure extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingAutoConfigureState extends State<OnBoardingAutoConfigure> {
|
class OnBoardingAutoConfigureState extends State<OnBoardingAutoConfigure> {
|
||||||
var gitHub = new GitHub();
|
GitHost gitHost;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
gitHub.init(() async {
|
gitHost = createGitHost(widget.gitHostType);
|
||||||
|
gitHost.init(() async {
|
||||||
print("GitHub Initalized");
|
print("GitHub Initalized");
|
||||||
|
|
||||||
var repo = await gitHub.createRepo("journal");
|
var repo = await gitHost.createRepo("journal");
|
||||||
var publicKey = await generateSSHKeys(comment: "GitJournal");
|
var publicKey = await generateSSHKeys(comment: "GitJournal");
|
||||||
await gitHub.addDeployKey(publicKey, repo.fullName);
|
await gitHost.addDeployKey(publicKey, repo.fullName);
|
||||||
|
|
||||||
widget.onDone(repo.cloneUrl);
|
widget.onDone(repo.cloneUrl);
|
||||||
});
|
});
|
||||||
gitHub.launchOAuthScreen();
|
gitHost.launchOAuthScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dots_indicator/dots_indicator.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
|
||||||
|
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:dots_indicator/dots_indicator.dart';
|
|
||||||
|
|
||||||
import 'package:journal/analytics.dart';
|
import 'package:journal/analytics.dart';
|
||||||
import 'package:journal/state_container.dart';
|
|
||||||
import 'package:journal/apis/git.dart';
|
import 'package:journal/apis/git.dart';
|
||||||
|
import 'package:journal/apis/githost_factory.dart';
|
||||||
import 'package:journal/screens/onboarding_git_url.dart';
|
|
||||||
import 'package:journal/screens/onboarding_git_clone.dart';
|
|
||||||
import 'package:journal/screens/onboarding_autoconfigure.dart';
|
import 'package:journal/screens/onboarding_autoconfigure.dart';
|
||||||
|
import 'package:journal/screens/onboarding_git_clone.dart';
|
||||||
|
import 'package:journal/screens/onboarding_git_url.dart';
|
||||||
|
import 'package:journal/state_container.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class OnBoardingScreen extends StatefulWidget {
|
class OnBoardingScreen extends StatefulWidget {
|
||||||
final Function onBoardingCompletedFunction;
|
final Function onBoardingCompletedFunction;
|
||||||
@ -35,7 +33,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
|||||||
var _pageSshKeyDone = false;
|
var _pageSshKeyDone = false;
|
||||||
var _autoConfigureStarted = false;
|
var _autoConfigureStarted = false;
|
||||||
var _autoConfigureDone = false;
|
var _autoConfigureDone = false;
|
||||||
GitRemoteRepo _remoteRepo;
|
GitHostType _gitHostType;
|
||||||
|
|
||||||
var _gitCloneUrl = "";
|
var _gitCloneUrl = "";
|
||||||
String gitCloneErrorMessage = "";
|
String gitCloneErrorMessage = "";
|
||||||
@ -99,9 +97,9 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
|||||||
|
|
||||||
if (pos == 1 && _createNewRepo) {
|
if (pos == 1 && _createNewRepo) {
|
||||||
return OnBoardingCreateRepo(
|
return OnBoardingCreateRepo(
|
||||||
onDone: (GitRemoteRepo remoteRepo, bool autoConfigure) {
|
onDone: (GitHostType gitHostType, bool autoConfigure) {
|
||||||
if (!autoConfigure) {
|
if (!autoConfigure) {
|
||||||
_launchCreateRepoPage(remoteRepo);
|
_launchCreateRepoPage(gitHostType);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -109,7 +107,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
|||||||
_pageCreateNewRepoDone = true;
|
_pageCreateNewRepoDone = true;
|
||||||
_autoConfigureStarted = autoConfigure;
|
_autoConfigureStarted = autoConfigure;
|
||||||
_autoConfigureDone = false;
|
_autoConfigureDone = false;
|
||||||
_remoteRepo = remoteRepo;
|
_gitHostType = gitHostType;
|
||||||
|
|
||||||
pageController.nextPage(
|
pageController.nextPage(
|
||||||
duration: Duration(milliseconds: 200),
|
duration: Duration(milliseconds: 200),
|
||||||
@ -122,7 +120,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
|||||||
|
|
||||||
if (pos == 2 && _createNewRepo && _autoConfigureStarted) {
|
if (pos == 2 && _createNewRepo && _autoConfigureStarted) {
|
||||||
return OnBoardingAutoConfigure(
|
return OnBoardingAutoConfigure(
|
||||||
remoteRepo: _remoteRepo,
|
gitHostType: _gitHostType,
|
||||||
onDone: (String gitCloneUrl) {
|
onDone: (String gitCloneUrl) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_gitCloneUrl = gitCloneUrl;
|
_gitCloneUrl = gitCloneUrl;
|
||||||
@ -316,11 +314,11 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _launchCreateRepoPage(GitRemoteRepo repo) async {
|
void _launchCreateRepoPage(GitHostType hostType) async {
|
||||||
try {
|
try {
|
||||||
if (repo == GitRemoteRepo.GitHub) {
|
if (hostType == GitHostType.GitHub) {
|
||||||
await launch("https://github.com/new");
|
await launch("https://github.com/new");
|
||||||
} else if (repo == GitRemoteRepo.Gitlab) {
|
} else if (hostType == GitHostType.GitLab) {
|
||||||
await launch("https://gitlab.com/projects/new");
|
await launch("https://gitlab.com/projects/new");
|
||||||
}
|
}
|
||||||
} catch (err, stack) {
|
} catch (err, stack) {
|
||||||
@ -449,7 +447,7 @@ class OnBoardingCreateRepo extends StatelessWidget {
|
|||||||
iconUrl: 'assets/icon/github-icon.png',
|
iconUrl: 'assets/icon/github-icon.png',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var switchWidget = _configureKey.currentWidget as Switch;
|
var switchWidget = _configureKey.currentWidget as Switch;
|
||||||
onDone(GitRemoteRepo.GitHub, switchWidget.value);
|
onDone(GitHostType.GitHub, switchWidget.value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 8.0),
|
SizedBox(height: 8.0),
|
||||||
@ -458,7 +456,7 @@ class OnBoardingCreateRepo extends StatelessWidget {
|
|||||||
iconUrl: 'assets/icon/gitlab-icon.png',
|
iconUrl: 'assets/icon/gitlab-icon.png',
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var switchWidget = _configureKey.currentWidget as Switch;
|
var switchWidget = _configureKey.currentWidget as Switch;
|
||||||
onDone(GitRemoteRepo.Gitlab, switchWidget.value);
|
onDone(GitHostType.GitLab, switchWidget.value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 8.0),
|
SizedBox(height: 8.0),
|
||||||
|
Reference in New Issue
Block a user