Skip to content

Commit

Permalink
api
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Mar 2, 2024
1 parent 478b74c commit 01b4e21
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/bloc/versions/app_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';
import 'dart:html';

import 'package:chaleno/chaleno.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:http/http.dart' as http;
import 'package:statuspage/bloc/versions/app_state.dart';
Expand Down Expand Up @@ -38,11 +38,30 @@ class AppCubit extends Cubit<AppState> {
}

Future<void> addRepo(project) async {
var parser = await Chaleno()
.load('https://github.com/pagopa/${project['repository']}');
List<Result>? results = parser?.getElementsByClassName(
'css-truncate css-truncate-target text-bold mr-2');
var version = results?.first.text ?? 'ERROR';
// var parser = await Chaleno()
// .load('https://github.com/pagopa/${project['repository']}');
// List<Result>? results = parser?.getElementsByClassName(
// 'css-truncate css-truncate-target text-bold mr-2');
// var version = results?.first.text ?? 'ERROR';

final Storage storage = window.localStorage;

http.Response response;
if (storage['gh_token'] != null) {
response = await http.get(
Uri.parse(
'https://api.github.com/repos/pagopa/${project['repository']}/releases/latest'),
headers: <String, String>{
'X-GitHub-Api-Version': '2022-11-28',
'Authorization': 'Bearer ${storage['gh_token']}',
'Accept': 'application/vnd.github+json'
},
); // there are limitation 60 requests per hour
} else {
response = await http.get(Uri.parse(
'https://api.github.com/repos/pagopa/${project['repository']}/releases/latest')); // there are limitation 60 requests per hour
}
var version = jsonDecode(response.body)['tag_name'] ?? 'No Release';

state.repoVersion.update(project['product'], (value) => version,
ifAbsent: () => version);
Expand Down

0 comments on commit 01b4e21

Please sign in to comment.