Skip to content

Commit

Permalink
Added package completion endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Apr 12, 2021
1 parent 06e0482 commit b64bd6c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 58 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Do not run workflow for now
name: Publish
on:
push:
tags:
- "NOT_VALID*"
release:
types: [published]

jobs:
publish:
Expand All @@ -16,6 +15,12 @@ jobs:
- uses: actions/checkout@v2
- name: Install dependencies
run: pub get
- name: Install Cider
run: flutter pub global activate cider
- name: Set new version
run: cider version ${{ github.event.release.tag_name }}
- name: Set a new release
run: cider release
- name: Build Runner
run: pub run build_runner build --delete-conflicting-outputs
- name: Run tests
Expand All @@ -25,13 +30,3 @@ jobs:
with:
credential: ${{ secrets.PUB_CREDENTIALS }}
flutter_package: false
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
## 2.0.1
## Unreleased

- Removed deprecations for smaller dependency tree
### Added

- Ability to get all package names for completion functionality

### Changed

- Fetching Google packages calls hosted static file

### Removed

- Check latest update API
- Deprecated packages to keep smaller dependency tree

## 2.0.0

### Changed

- Deprecated checkUpdatePrinter
- Null safety

## 1.0.9

### Changed

- Ability to pass custom http Client as param.
- Changed latest version to display stable version only

## 1.0.8

### Changed

- Added search filter for `publisher` or for `dependency`
- Added Google packages helpers

## 1.0.7

### Changed

- Added package publisher
- Added package options
- Added package version info
Expand All @@ -27,25 +46,37 @@

## 1.0.5

### Changed

- Better pubspec parsing

## 1.0.4

### Changed

- Added check for package update
- Added console printer for package update

## 1.0.3

### Changed

- Added user-agent to requests

## 1.0.2

### Changed

- Further improvements

## 1.0.1

### Changed

- Test improvements and API clean up

## 1.0.0

### Changed

- Initial version
5 changes: 4 additions & 1 deletion lib/src/endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Endpoint {
/// Package publisher endpoint
String packagePublisher(String name) => '$packageUrl/$name/publisher';

/// Package documentaiton endpoint
/// Package documentation endpoint
String packageDocumentation(String name) => '$apiUrl/documentation/$name';

// Not part of API endpoint
Expand All @@ -41,6 +41,9 @@ class Endpoint {
String packageVersionInfo(String name, String version) =>
'$packageUrl/$name/versions/$version';

/// Retrieve all package names on pub.dev
String get packageNames => '$apiUrl/package-names';

/// Search endpoint
String search(String query, int page) => '$searchUrl?q=$query&page=$page';
}
7 changes: 4 additions & 3 deletions lib/src/helpers/google_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ Future<List<String>> buildGooglePackages() async {
}

/// Retrieves all the flutter favorites
Future<List<PackageResult>> buildFlutterFavorites() async {
final results = await PubClient().search('is:flutter-favorite');
return _recursivePaging(results);
Future<List<String>> buildFlutterFavorites() async {
final searchResults = await PubClient().search('is:flutter-favorite');
final results = await _recursivePaging(searchResults);
return results.map((r) => r.package).toList();
}

/// Retrieves google packages from static file that is generated daily
Expand Down
11 changes: 9 additions & 2 deletions lib/src/pub_api_client_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ class PubClient {
return PackageVersion.fromJson(data);
}

/// Returns a `List<String>` of all packages listed on pub.dev
Future<List<String>> packageNameCompletion() async {
final data = await _fetch(endpoint.packageNames);
final packages = data['packages'] as List<dynamic>;

/// Need to map to convert dynamic into String
return packages.map((item) => item as String).toList();
}

/// Searches pub for [query] and can [page] results.
/// Can filter to [publisher] and/or a [dependency]
/// returns `SearchResults`
Expand All @@ -108,8 +117,6 @@ class PubClient {
return SearchResults.fromJson(data);
}

// Future<SearchResults> _nextSearchPage() async {}

/// Returns `PackageDocumentation` for a [packageName]
Future<PackageDocumentation> documentation(String packageName) async {
final data = await _fetch(endpoint.packageDocumentation(packageName));
Expand Down
74 changes: 37 additions & 37 deletions static/flutter_favorites.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"packages": [
{ "package": "provider" },
{ "package": "url_launcher" },
{ "package": "google_fonts" },
{ "package": "flutter_bloc" },
{ "package": "geolocator" },
{ "package": "bloc" },
{ "package": "location" },
{ "package": "flutter_slidable" },
{ "package": "animated_text_kit" },
{ "package": "built_value" },
{ "package": "mobx" },
{ "package": "flutter_mobx" },
{ "package": "just_audio" },
{ "package": "built_collection" },
{ "package": "flutter_redux" },
{ "package": "convex_bottom_bar" },
{ "package": "rxdart" },
{ "package": "sqflite" },
{ "package": "font_awesome_flutter" },
{ "package": "connectivity" },
{ "package": "flutter_local_notifications" },
{ "package": "device_info" },
{ "package": "sign_in_with_apple" },
{ "package": "bottom_navy_bar" },
{ "package": "redux" },
{ "package": "shared_preferences" },
{ "package": "package_info" },
{ "package": "android_intent" },
{ "package": "sensors" },
{ "package": "battery" },
{ "package": "mobx_codegen" },
{ "package": "android_alarm_manager" },
{ "package": "chopper" },
{ "package": "path_provider" },
{ "package": "share" },
{ "package": "json_serializable" },
{ "package": "built_value_generator" }
"provider",
"url_launcher",
"google_fonts",
"flutter_bloc",
"geolocator",
"bloc",
"location",
"flutter_slidable",
"animated_text_kit",
"built_value",
"mobx",
"flutter_mobx",
"just_audio",
"built_collection",
"flutter_redux",
"convex_bottom_bar",
"rxdart",
"sqflite",
"font_awesome_flutter",
"connectivity",
"flutter_local_notifications",
"device_info",
"sign_in_with_apple",
"bottom_navy_bar",
"redux",
"shared_preferences",
"package_info",
"android_intent",
"sensors",
"battery",
"mobx_codegen",
"android_alarm_manager",
"chopper",
"path_provider",
"share",
"json_serializable",
"built_value_generator"
]
}
5 changes: 5 additions & 0 deletions test/pubdev_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@ void main() {
expect(documentation.latestStableVersion, packageInfo.version);
expect(documentation.versions.length, packageInfo.versions.length);
});

test('Get package names', () async {
final packages = await client.packageNameCompletion();
expect(packages.length, greaterThan(20000));
});
});
}

0 comments on commit b64bd6c

Please sign in to comment.