Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@
* Use device info plus package for support all platform

## 0.0.11
* Fixed bug on issue model
* Fixed bug on issue model

## 0.0.12
* Added report issue on app version milestone
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GhSnitch.report(
screenShotBranch: '<screenshot-branch>',
labels: <List<String>?>,
assignees: <List<String>?>,
milestone: <int?>,
milestone: '<milestone> if null will create new milestone with app version name',
userId: '<user-id if exist if not package will use deviceID>',
);
```
Expand Down
9 changes: 9 additions & 0 deletions lib/src/utils/get_app_version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:package_info_plus/package_info_plus.dart';

class GetAppVersion {
static Future<String> get version async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version;
return version;
}
}
44 changes: 41 additions & 3 deletions lib/src/utils/github_snitch_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:device_info_plus/device_info_plus.dart';

import 'package:flutter/foundation.dart';
import 'package:github_snitch/src/utils/extensions.dart';
import 'package:github_snitch/src/utils/get_app_version.dart';
import 'package:string_similarity/string_similarity.dart';
import 'package:universal_io/io.dart';

Expand Down Expand Up @@ -66,14 +67,15 @@ class GhSnitchInstance {
issueBody["labels"] = labels;
}

if (milestone != null) {
issueBody["milestone"] = milestone;
}
milestone ??= await getMilestoneID() ?? await createMilestone();
issueBody["milestone"] = milestone;

String issueBodyToString = json.encode(issueBody);

GhResponse response = await ghRequest.request("POST", issueEndpoint,
body: issueBodyToString);
print(milestone);
print(response.response);
if (response.statusCode == 201) {
Map issueFieldsDecoded = Map.from(response.response);
issueFieldsDecoded
Expand Down Expand Up @@ -328,4 +330,40 @@ class GhSnitchInstance {
}
return id;
}

Future<int> createMilestone({DateTime? milestoneDueOn}) async {
int? id;
String createMilestoneEp = "$owner/$repo/milestones";
Map milestoneBody = {
'title': await GetAppVersion.version,
};
if (milestoneDueOn != null) {
milestoneBody['due_on'] = milestoneDueOn.toUtc().toString();
}
String milestoneBodyToString = json.encode(milestoneBody);
GhResponse response = await ghRequest.request("POST", createMilestoneEp,
body: milestoneBodyToString);
if (response.statusCode == 201) {
log("✅ Created Milestone");
id = response.response['number'];
} else {
log("❌ Failure to Create Milestone");
log(response.response.toString());
}
return id!;
}

Future<int?> getMilestoneID() async {
int? result;
String milestonesEndpoint = "$owner/$repo/milestones";
GhResponse ghResponse = await ghRequest.request("GET", milestonesEndpoint);
if (ghResponse.statusCode == 200) {
for (var e in (ghResponse.response as List)) {
if (e['title'] == await GetAppVersion.version) {
result = e['number'];
}
}
}
return result;
}
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: github_snitch
description: Package for capture & open github issue for crashes, issues & proposals
version: 0.0.11
version: 0.0.12
homepage: https://github.com/M97Chahboun/github_snitch

environment:
Expand All @@ -16,6 +16,7 @@ dependencies:
string_similarity: ^2.0.0
connectivity_plus: ^4.0.1
device_info_plus: ^9.0.2
package_info_plus: ^4.2.0

dev_dependencies:
flutter_test:
Expand Down