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

feat(model): アプリバージョンのモデルを追加 #654

Merged
merged 1 commit into from
Oct 5, 2024
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
4 changes: 2 additions & 2 deletions app/mobile/lib/config/remote_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ UpdateVersion _resolveUpdateVersion(FirebaseRemoteConfig firebaseRemoteConfig) {
firebaseRemoteConfig.getString(appVersionsKey),
);
return UpdateVersion(
force: updateVersions['force'] as String,
optional: updateVersions['optional'] as String,
force: AppVersion.parse(updateVersions['force'] as String),
optional: AppVersion.parse(updateVersions['optional'] as String),
Comment on lines +30 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

AppVersion.parse メソッドにエラーハンドリングが存在しません。

AppVersion.parse メソッド内でバージョン文字列のパース時にエラーハンドリングが実装されていないようです。無効な文字列が渡された場合に適切に対処するために、try-catch ブロックやエラーチェックを追加することを検討してください。

  • ファイル: core/model/lib/src/config/app_version.dart
  • メソッド: AppVersion.parse
🔗 Analysis chain

アプリケーションバージョンモデルの導入を承認します。

この変更は、文字列バージョンをAppVersionオブジェクトに変換することで、型安全性を向上させています。これはPRの目的であるアプリケーションバージョンモデルの追加に合致しています。

以下の点を確認するために、次のスクリプトを実行してください:

改善の提案:

  1. AppVersion.parseメソッドが失敗した場合のエラーハンドリングを検討してください。
  2. Firebase Remote Configから取得した文字列がAppVersion.parseメソッドで期待される形式であることを確認してください。

これらの改善により、コードの堅牢性がさらに向上します。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# AppVersion クラスの実装を確認し、parse メソッドのエラーハンドリングを検証します。

# AppVersion クラスの定義を検索
ast-grep --lang dart --pattern 'class AppVersion {
  $$$
  static AppVersion parse($_) {
    $$$
  }
  $$$
}'

# parse メソッドの使用箇所を検索
rg --type dart 'AppVersion\.parse'

Length of output: 559


Script:

#!/bin/bash
# AppVersion.parse メソッド内のエラーハンドリングを確認します。

# AppVersion.parse メソッドの実装を取得
ast-grep --lang dart --pattern 'class AppVersion {
  $$$
  static AppVersion parse($_) {
    $$$
  }
  $$$
}' core/model/lib/src/config/app_version.dart

Length of output: 154


Script:

#!/bin/bash
# AppVersion.parse メソッド内のエラーハンドリングを確認します。より柔軟なパターンを使用します。

# AppVersion クラスの定義全体を取得
ast-grep --lang dart --pattern 'class AppVersion { $$$ }' core/model/lib/src/config/app_version.dart

# AppVersion.parse メソッド内でのエラーハンドリング関連キーワードを検索
rg --type dart 'AppVersion\.parse.*\btry\b|\bcatch\b|\bthrow\b' core/model/lib/src/config/app_version.dart

Length of output: 211

);
}
4 changes: 2 additions & 2 deletions app/mobile/lib/initializer/app_config_initializer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:app_mobile/env.dart';
import 'package:core_model/config.dart';
import 'package:flutter/services.dart';
import 'package:app_mobile/env.dart';
import 'package:package_info_plus/package_info_plus.dart';

Future<AppConfig> initializeAppConfig() async {
Expand All @@ -15,7 +15,7 @@ Future<AppConfig> initializeAppConfig() async {
flavor: flavor,
appName: packageInfo.appName,
packageName: packageInfo.packageName,
version: packageInfo.version,
version: AppVersion.parse(packageInfo.version),
buildNumber: packageInfo.buildNumber,
buildSignature: packageInfo.buildSignature,
installerStore: packageInfo.installerStore,
Expand Down
1 change: 1 addition & 0 deletions core/model/lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'src/config/app_config.dart';
export 'src/config/app_version.dart';
export 'src/config/flavor.dart';
export 'src/config/remote_config.dart';
export 'src/config/update_version.dart';
5 changes: 3 additions & 2 deletions core/model/lib/src/config/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:core_model/src/config/app_version.dart';
import 'package:core_model/src/config/flavor.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand All @@ -19,7 +20,7 @@ class AppConfig with _$AppConfig {
const factory AppConfig({
required String appName,
required String packageName,
required String version,
required AppVersion version,
required String buildNumber,
required String buildSignature,
required Flavor flavor,
Expand All @@ -33,7 +34,7 @@ class AppConfig with _$AppConfig {
const fakeAppConfig = AppConfig(
appName: 'Fake App',
packageName: 'com.example.fake_app',
version: '1.0.0',
version: AppVersion(major: 1, minor: 0, patch: 0),
buildNumber: '1',
buildSignature: '1',
flavor: Flavor.dev,
Expand Down
31 changes: 23 additions & 8 deletions core/model/lib/src/config/app_config.freezed.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions core/model/lib/src/config/app_version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'app_version.freezed.dart';

/// アプリバージョン
///
/// {@category Model}
@freezed
class AppVersion with _$AppVersion {
const factory AppVersion({
required int major,
required int minor,
required int patch,
}) = _AppVersion;

factory AppVersion.parse(String version) {
final versionList = version.split('.').map(int.parse).toList();
return AppVersion(
major: versionList[0],
minor: versionList[1],
patch: versionList[2],
);
}
Comment on lines +16 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

AppVersion.parse() メソッドでの入力値の検証を追加してください

現在の parse メソッドでは、入力されたバージョン文字列が正しい形式でない場合、例外が発生する可能性があります。バージョン文字列が "1.2.3" のような正しい形式であるかを確認し、不正な入力に対して適切なエラーハンドリングを行うことをお勧めします。

以下の差分を適用して、入力値の検証を強化できます:

 factory AppVersion.parse(String version) {
+    final versionParts = version.split('.');
+    if (versionParts.length != 3) {
+      throw FormatException('バージョン文字列の形式が不正です。期待される形式: major.minor.patch');
+    }
+    final versionList = versionParts.map(int.parse).toList();
     return AppVersion(
       major: versionList[0],
       minor: versionList[1],
       patch: versionList[2],
     );
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
factory AppVersion.parse(String version) {
final versionList = version.split('.').map(int.parse).toList();
return AppVersion(
major: versionList[0],
minor: versionList[1],
patch: versionList[2],
);
}
factory AppVersion.parse(String version) {
final versionParts = version.split('.');
if (versionParts.length != 3) {
throw FormatException('バージョン文字列の形式が不正です。期待される形式: major.minor.patch');
}
final versionList = versionParts.map(int.parse).toList();
return AppVersion(
major: versionList[0],
minor: versionList[1],
patch: versionList[2],
);
}


const AppVersion._();

String get value => '$major.$minor.$patch';

int compareTo(AppVersion other) {
if (major != other.major) {
return major.compareTo(other.major);
}
if (minor != other.minor) {
return minor.compareTo(other.minor);
}
return patch.compareTo(other.patch);
}

bool operator >(AppVersion other) => compareTo(other) > 0;

bool operator <(AppVersion other) => compareTo(other) < 0;

bool operator >=(AppVersion other) => compareTo(other) >= 0;

bool operator <=(AppVersion other) => compareTo(other) <= 0;
}
181 changes: 181 additions & 0 deletions core/model/lib/src/config/app_version.freezed.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading