forked from foss42/apidash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes foss42#502 Implement GIT integration to push/pull collections with version history. * **Add GIT Services**: Create `lib/services/git_services.dart` to handle push/export and pull/import functionalities. * **Settings Page**: Modify `lib/screens/settings_page.dart` to include GIT configuration settings (Token, Repository) and add a dialog for GIT settings. * **Collection Pane**: Update `lib/screens/home_page/collection_pane.dart` to add sync buttons for GIT push and pull actions. * **Collection Providers**: Modify `lib/providers/collection_providers.dart` to add methods for handling GIT push and pull actions. * **Constants**: Update `lib/consts.dart` to add constants for GIT settings. * **Settings Model**: Modify `lib/models/settings_model.dart` to include fields for GIT settings. * **Hive Services**: Update `lib/services/hive_services.dart` to add methods for handling GIT data storage and retrieval. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/foss42/apidash/issues/502?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
1 parent
1aad26f
commit 07f6357
Showing
7 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'dart:convert'; | ||
import 'package:git/git.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:apidash/consts.dart'; | ||
|
||
class GitService { | ||
final String repositoryUrl; | ||
final String token; | ||
final String branch; | ||
|
||
GitService({ | ||
required this.repositoryUrl, | ||
required this.token, | ||
this.branch = 'main', | ||
}); | ||
|
||
Future<void> pushData() async { | ||
final directory = await getApplicationDocumentsDirectory(); | ||
final repoDir = '${directory.path}/apidash_repo'; | ||
|
||
final gitDir = await GitDir.fromExisting(repoDir, allowSubdirectory: true); | ||
await gitDir.runCommand(['pull', 'origin', branch]); | ||
|
||
final box = await Hive.openBox(kDataBox); | ||
final data = box.toMap(); | ||
final jsonData = jsonEncode(data); | ||
|
||
final file = File('$repoDir/collections.json'); | ||
await file.writeAsString(jsonData); | ||
|
||
await gitDir.runCommand(['add', 'collections.json']); | ||
await gitDir.runCommand(['commit', '-m', 'Update collections']); | ||
await gitDir.runCommand(['push', 'origin', branch]); | ||
} | ||
|
||
Future<void> pullData() async { | ||
final directory = await getApplicationDocumentsDirectory(); | ||
final repoDir = '${directory.path}/apidash_repo'; | ||
|
||
final gitDir = await GitDir.fromExisting(repoDir, allowSubdirectory: true); | ||
await gitDir.runCommand(['pull', 'origin', branch]); | ||
|
||
final file = File('$repoDir/collections.json'); | ||
if (await file.exists()) { | ||
final jsonData = await file.readAsString(); | ||
final data = jsonDecode(jsonData); | ||
|
||
final box = await Hive.openBox(kDataBox); | ||
await box.putAll(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters