From 123fecc0fee8bc8a1736d122b9050cc273384d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Wed, 27 Sep 2023 16:24:42 +0100 Subject: [PATCH 1/6] Fix overlapping classes bugs --- .../parsers/parser_schedule_html.dart | 27 ++++++++++++------- uni/lib/model/entities/lecture.dart | 5 ++-- .../providers/lazy/lecture_provider.dart | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/uni/lib/controller/parsers/parser_schedule_html.dart b/uni/lib/controller/parsers/parser_schedule_html.dart index 88ac5ce8c..5b040dddb 100644 --- a/uni/lib/controller/parsers/parser_schedule_html.dart +++ b/uni/lib/controller/parsers/parser_schedule_html.dart @@ -9,9 +9,7 @@ import 'package:uni/model/entities/session.dart'; import 'package:uni/model/entities/time_utilities.dart'; Future> getOverlappedClasses( - Session session, - Document document, -) async { + Session session, Document document, Uri uri) async { final lecturesList = []; final monday = DateTime.now().getClosestMonday(); @@ -21,7 +19,7 @@ Future> getOverlappedClasses( final subject = element.querySelector('acronym > a')?.text; final typeClass = element .querySelector('td[headers=t1]') - ?.nodes[2] + ?.nodes[1] .text ?.trim() .replaceAll(RegExp('[()]+'), ''); @@ -37,20 +35,28 @@ Future> getOverlappedClasses( final classNumber = element.querySelector('td[headers=t6] > a')?.text; try { + final startTimeList = startTime?.split(':') ?? []; + if (startTimeList.isEmpty) { + throw FormatException( + 'Overlapping class $subject has invalid startTime', + ); + } final fullStartTime = monday.add( Duration( days: day, - hours: int.parse(startTime!.substring(0, 2)), - minutes: int.parse(startTime.substring(3, 5)), + hours: int.parse(startTimeList[0]), + minutes: int.parse(startTimeList[1]), ), ); - final link = + final href = element.querySelector('td[headers=t6] > a')?.attributes['href']; - if (link == null) { + if (href == null) { throw Exception(); } - final response = await NetworkRouter.getWithCookies(link, {}, session); + final faculty = uri.path.split('/')[1]; + final response = + await NetworkRouter.getWithCookies('https://${uri.host}/$faculty/$href', {}, session); final classLectures = await getScheduleFromHtml(response, session); @@ -148,7 +154,8 @@ Future> getScheduleFromHtml( }); lecturesList - ..addAll(await getOverlappedClasses(session, document)) + ..addAll( + await getOverlappedClasses(session, document, response.request!.url),) ..sort((a, b) => a.compare(b)); return lecturesList; diff --git a/uni/lib/model/entities/lecture.dart b/uni/lib/model/entities/lecture.dart index f91658b2e..b93aac32c 100644 --- a/uni/lib/model/entities/lecture.dart +++ b/uni/lib/model/entities/lecture.dart @@ -51,10 +51,11 @@ class Lecture { String classNumber, int occurrId, ) { + final startTimeList = startTimeString.split(':'); final startTime = day.add( Duration( - hours: int.parse(startTimeString.substring(0, 2)), - minutes: int.parse(startTimeString.substring(3, 5)), + hours: int.parse(startTimeList[0]), + minutes: int.parse(startTimeList[1]), ), ); final endTime = startTime.add(Duration(minutes: 30 * blocks)); diff --git a/uni/lib/model/providers/lazy/lecture_provider.dart b/uni/lib/model/providers/lazy/lecture_provider.dart index fd5789ef7..3c234c224 100644 --- a/uni/lib/model/providers/lazy/lecture_provider.dart +++ b/uni/lib/model/providers/lazy/lecture_provider.dart @@ -53,7 +53,7 @@ class LectureProvider extends StateProviderNotifier { _lectures = lectures; updateStatus(RequestStatus.successful); - } catch (e) { + } catch (e, stacktrace) { updateStatus(RequestStatus.failed); } } From 25360622d39a9af433dca26fea0b6f8a64b72ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Wed, 27 Sep 2023 17:08:48 +0100 Subject: [PATCH 2/6] fix formatting and linting --- .../controller/parsers/parser_schedule_html.dart | 15 +++++++++++---- .../model/providers/lazy/lecture_provider.dart | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/uni/lib/controller/parsers/parser_schedule_html.dart b/uni/lib/controller/parsers/parser_schedule_html.dart index 5b040dddb..1e706d8a3 100644 --- a/uni/lib/controller/parsers/parser_schedule_html.dart +++ b/uni/lib/controller/parsers/parser_schedule_html.dart @@ -9,7 +9,10 @@ import 'package:uni/model/entities/session.dart'; import 'package:uni/model/entities/time_utilities.dart'; Future> getOverlappedClasses( - Session session, Document document, Uri uri) async { + Session session, + Document document, + Uri uri, +) async { final lecturesList = []; final monday = DateTime.now().getClosestMonday(); @@ -55,8 +58,11 @@ Future> getOverlappedClasses( throw Exception(); } final faculty = uri.path.split('/')[1]; - final response = - await NetworkRouter.getWithCookies('https://${uri.host}/$faculty/$href', {}, session); + final response = await NetworkRouter.getWithCookies( + 'https://${uri.host}/$faculty/$href', + {}, + session, + ); final classLectures = await getScheduleFromHtml(response, session); @@ -155,7 +161,8 @@ Future> getScheduleFromHtml( lecturesList ..addAll( - await getOverlappedClasses(session, document, response.request!.url),) + await getOverlappedClasses(session, document, response.request!.url), + ) ..sort((a, b) => a.compare(b)); return lecturesList; diff --git a/uni/lib/model/providers/lazy/lecture_provider.dart b/uni/lib/model/providers/lazy/lecture_provider.dart index 3c234c224..fd5789ef7 100644 --- a/uni/lib/model/providers/lazy/lecture_provider.dart +++ b/uni/lib/model/providers/lazy/lecture_provider.dart @@ -53,7 +53,7 @@ class LectureProvider extends StateProviderNotifier { _lectures = lectures; updateStatus(RequestStatus.successful); - } catch (e, stacktrace) { + } catch (e) { updateStatus(RequestStatus.failed); } } From 134cad31e8c88b6b161c1163d9bd81b8bb41cbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 28 Sep 2023 14:27:09 +0100 Subject: [PATCH 3/6] refactor and fix tests --- .../schedule_fetcher/schedule_fetcher_html.dart | 8 ++++++-- uni/lib/controller/parsers/parser_schedule_html.dart | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/uni/lib/controller/fetchers/schedule_fetcher/schedule_fetcher_html.dart b/uni/lib/controller/fetchers/schedule_fetcher/schedule_fetcher_html.dart index 6d9594a4b..7fdf7ed16 100644 --- a/uni/lib/controller/fetchers/schedule_fetcher/schedule_fetcher_html.dart +++ b/uni/lib/controller/fetchers/schedule_fetcher/schedule_fetcher_html.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:http/http.dart'; import 'package:uni/controller/fetchers/schedule_fetcher/schedule_fetcher.dart'; import 'package:uni/controller/networking/network_router.dart'; @@ -39,8 +40,11 @@ class ScheduleFetcherHtml extends ScheduleFetcher { } final lectures = await Future.wait( - lectureResponses - .map((response) => getScheduleFromHtml(response, session)), + IterableZip( + [lectureResponses, NetworkRouter.getBaseUrlsFromSession(session)], + ).map( + (e) => getScheduleFromHtml(e[0] as Response, session, e[1] as String), + ), ).then((schedules) => schedules.expand((schedule) => schedule).toList()); lectures.sort((l1, l2) => l1.compare(l2)); diff --git a/uni/lib/controller/parsers/parser_schedule_html.dart b/uni/lib/controller/parsers/parser_schedule_html.dart index 1e706d8a3..6843f749d 100644 --- a/uni/lib/controller/parsers/parser_schedule_html.dart +++ b/uni/lib/controller/parsers/parser_schedule_html.dart @@ -11,7 +11,7 @@ import 'package:uni/model/entities/time_utilities.dart'; Future> getOverlappedClasses( Session session, Document document, - Uri uri, + String faculty, ) async { final lecturesList = []; @@ -57,14 +57,14 @@ Future> getOverlappedClasses( if (href == null) { throw Exception(); } - final faculty = uri.path.split('/')[1]; final response = await NetworkRouter.getWithCookies( - 'https://${uri.host}/$faculty/$href', + '$faculty$href', {}, session, ); - final classLectures = await getScheduleFromHtml(response, session); + final classLectures = + await getScheduleFromHtml(response, session, faculty); lecturesList.add( classLectures @@ -100,6 +100,7 @@ Future> getOverlappedClasses( Future> getScheduleFromHtml( http.Response response, Session session, + String faculty, ) async { final document = parse(response.body); var semana = [0, 0, 0, 0, 0, 0]; @@ -161,7 +162,7 @@ Future> getScheduleFromHtml( lecturesList ..addAll( - await getOverlappedClasses(session, document, response.request!.url), + await getOverlappedClasses(session, document, faculty), ) ..sort((a, b) => a.compare(b)); From 60bd1418380f74d7d50f05eef8c4c267c2c623b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 28 Sep 2023 14:49:07 +0100 Subject: [PATCH 4/6] make ci bump patch version if it doesn't come from develop --- .github/workflows/deploy.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 051ac1bda..555b767ae 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -14,12 +14,19 @@ jobs: with: token: ${{ secrets.NIAEFEUPBOT_PAT }} + - name: Get develop hash + if: github.ref == 'refs/heads/master' + run: | + git fetch origin develop + current_hash=$(git rev-parse HEAD) + echo "DEVELOPHASH=$current_hash" >> $GITHUB_ENV + - name: Bump flutter patch version - if: github.ref == 'refs/heads/develop' + if: github.ref == 'refs/heads/develop' || (github.ref == 'refs/heads/master' && $${{github.sha == env.DEVELOPHASH}}) run: perl -i -pe 's/^(\d+\.\d+\.)(\d+)(\+)(\d+)$/$1.($2+1).($3).($4+1)/e' ${{ env.APP_VERSION_PATH }} - name: Bump flutter minor version - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' && $${{github.sha == env.DEVELOPHASH}} run: perl -i -pe 's/^(\d+)(\.)(\d+)(\.)(\d+)(\+)(\d+)$/$1.($2).($3+1).($4).(0).($6).($7+1)/e' ${{ env.APP_VERSION_PATH }} - name: Copy app version to pubspec From 38d7561b5db0ccc5b5c4071184efed87fd6ea39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 28 Sep 2023 14:52:48 +0000 Subject: [PATCH 5/6] Fix deploy --- .github/workflows/deploy.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 555b767ae..56b862eb1 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -18,24 +18,26 @@ jobs: if: github.ref == 'refs/heads/master' run: | git fetch origin develop - current_hash=$(git rev-parse HEAD) + current_hash=$(git rev-parse origin/develop) echo "DEVELOPHASH=$current_hash" >> $GITHUB_ENV - name: Bump flutter patch version - if: github.ref == 'refs/heads/develop' || (github.ref == 'refs/heads/master' && $${{github.sha == env.DEVELOPHASH}}) + if: github.ref == 'refs/heads/develop' || github.sha != env.DEVELOPHASH run: perl -i -pe 's/^(\d+\.\d+\.)(\d+)(\+)(\d+)$/$1.($2+1).($3).($4+1)/e' ${{ env.APP_VERSION_PATH }} - name: Bump flutter minor version - if: github.ref == 'refs/heads/master' && $${{github.sha == env.DEVELOPHASH}} + if: github.ref == 'refs/heads/master' && github.sha == env.DEVELOPHASH run: perl -i -pe 's/^(\d+)(\.)(\d+)(\.)(\d+)(\+)(\d+)$/$1.($2).($3+1).($4).(0).($6).($7+1)/e' ${{ env.APP_VERSION_PATH }} - name: Copy app version to pubspec run: cat ${{ env.APP_VERSION_PATH }} | perl -i -pe 's/^(version:\s+)(\d+\.\d+\.\d+\+\d+)$/$1.()/e' ${{ env.PUBSPEC_PATH }} + - name: debug cansdo + run: git --no-pager diff + - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "Bump app version [no ci]" - - name: Propagate master version bump to develop if: github.ref == 'refs/heads/master' run: git push --force-with-lease origin HEAD:develop From e88317d2ebf365a1a960fd8ee11a7f513432702b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 28 Sep 2023 14:57:30 +0000 Subject: [PATCH 6/6] Remove debug deploy info --- .github/workflows/deploy.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 56b862eb1..cbd989070 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -32,9 +32,6 @@ jobs: - name: Copy app version to pubspec run: cat ${{ env.APP_VERSION_PATH }} | perl -i -pe 's/^(version:\s+)(\d+\.\d+\.\d+\+\d+)$/$1.()/e' ${{ env.PUBSPEC_PATH }} - - name: debug cansdo - run: git --no-pager diff - - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "Bump app version [no ci]"