Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/Add Faculties to bug report #652

Merged
merged 13 commits into from
Feb 23, 2023
1 change: 1 addition & 0 deletions uni/lib/controller/logout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';


Future logout(BuildContext context) async {
final prefs = await SharedPreferences.getInstance();
final faculties = await AppSharedPreferences.getUserFaculties();
Expand Down
24 changes: 24 additions & 0 deletions uni/lib/model/entities/bug_report.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Stores information about Bug Report
import 'package:tuple/tuple.dart';

class BugReport{
final String title;
final String text;
final String email;
final Tuple2<String,String>? bugLabel;
final List<String> faculties;
BugReport(
this.title,
this.text,
this.email,
this.bugLabel,
this.faculties
);
Map<String,dynamic> toMap() => {
'title':title,
'text':text,
'email':email,
'bugLabel':bugLabel!.item2,
'faculties':faculties
};
}
43 changes: 24 additions & 19 deletions uni/lib/view/bug_report/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import 'package:http/http.dart' as http;
import 'package:logger/logger.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:tuple/tuple.dart';
import 'package:uni/model/entities/bug_report.dart';
import 'package:uni/view/bug_report/widgets/text_field.dart';
import 'package:uni/view/common_widgets/page_title.dart';
import 'package:uni/view/common_widgets/toast_message.dart';
import 'package:uni/controller/local_storage/app_shared_preferences.dart';

class BugReportForm extends StatefulWidget {
const BugReportForm({super.key});
Expand Down Expand Up @@ -53,14 +55,12 @@ class BugReportFormState extends State<BugReportForm> {
if (ghToken == '') loadGHKey();
loadBugClassList();
}

void loadBugClassList() {
bugList = [];

bugDescriptions.forEach((int key, Tuple2<String, String> tup) =>
{bugList.add(DropdownMenuItem(value: key, child: Text(tup.item1)))});
}

@override
Widget build(BuildContext context) {
return Form(
Expand Down Expand Up @@ -233,16 +233,19 @@ class BugReportFormState extends State<BugReportForm> {
setState(() {
_isButtonTapped = true;
});

final String bugLabel = bugDescriptions[_selectedBug] == null
? 'Unidentified bug'
: bugDescriptions[_selectedBug]!.item2;

final List<String> faculties = await AppSharedPreferences.getUserFaculties();
final bugReport = BugReport(
titleController.text,
descriptionController.text,
emailController.text,
bugDescriptions[_selectedBug],
faculties
).toMap();
String toastMsg;
bool status;
try {
final sentryId = await submitSentryEvent(bugLabel);
final gitHubRequestStatus = await submitGitHubIssue(sentryId, bugLabel);
final sentryId = await submitSentryEvent(bugReport);
final gitHubRequestStatus = await submitGitHubIssue(sentryId, bugReport);
if (gitHubRequestStatus < 200 || gitHubRequestStatus > 400) {
throw Exception('Network error');
}
Expand All @@ -265,15 +268,17 @@ class BugReportFormState extends State<BugReportForm> {
});
}
}

Future<int> submitGitHubIssue(SentryId sentryEvent, String bugLabel) async {
Future<int> submitGitHubIssue(SentryId sentryEvent, Map<String,dynamic> bugReport) async {
final String description =
'${descriptionController.text}\nFurther information on: $_sentryLink$sentryEvent';
'${bugReport['bugLabel']}\nFurther information on: $_sentryLink$sentryEvent';
final Map data = {
'title': titleController.text,
'title': bugReport['title'],
'body': description,
'labels': ['In-app bug report', bugLabel],
'labels': ['In-app bug report', bugReport['bugLabel']],
};
for (String faculty in bugReport['faculties']){
data['labels'].add(faculty);
}
return http
.post(Uri.parse(_gitHubPostUrl),
headers: {
Expand All @@ -286,12 +291,12 @@ class BugReportFormState extends State<BugReportForm> {
});
}

Future<SentryId> submitSentryEvent(String bugLabel) async {
final String description = emailController.text == ''
? descriptionController.text
: '${descriptionController.text}\nContact: ${emailController.text}';
Future<SentryId> submitSentryEvent(Map<String,dynamic> bugReport) async {
final String description = bugReport['email'] == ''
? '${bugReport['text']} from ${bugReport['faculty']}'
: '${bugReport['text']} from ${bugReport['faculty']}\nContact: ${bugReport['email']}';
return Sentry.captureMessage(
'$bugLabel: ${titleController.text}\n$description');
'${bugReport['bugLabel']}: ${bugReport['text']}\n$description');
}

void clearForm() {
Expand Down