-
Notifications
You must be signed in to change notification settings - Fork 107
chore: handle unknown commit date in version #836
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
Conversation
WalkthroughThis change updates the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Contracts/Version.php (1)
45-56: Consider hardeningfromArray()against non‑string or malformedcommitDatevaluesRight now,
fromArray()gracefully handles the literal'unknown', but any other unexpected value (e.g.null, empty string, or a badly formatted date) will still be passed tonew \DateTimeImmutable(...)and can throw, which seems slightly at odds with the PR goal of being robust to “unknown or unparsable” dates.If the upstream
/versionendpoint might ever returnnullor an invalid string, you could defensively treat such cases as “unknown” and keep$commitDateatnull, for example:public static function fromArray(array $data): Version { - $commitDate = null; - if ('unknown' !== $data['commitDate']) { - $commitDate = new \DateTimeImmutable($data['commitDate']); - } + $commitDate = null; + $rawCommitDate = $data['commitDate'] ?? null; + + if (is_string($rawCommitDate) && $rawCommitDate !== 'unknown' && $rawCommitDate !== '') { + try { + $commitDate = new \DateTimeImmutable($rawCommitDate); + } catch (\Exception) { + // Leave $commitDate as null if parsing fails. + } + } @@ return new self( $data['commitSha'], $commitDate, $data['pkgVersion'], );This keeps the happy path unchanged while avoiding hard failures if the API ever sends
nullor a malformed date. If the Meilisearch contract strictly guarantees only ISO timestamps or'unknown', the current implementation is fine, but this tweak would make it future‑proof.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Contracts/Version.php(3 hunks)tests/Contracts/VersionTest.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Contracts/VersionTest.php (1)
src/Contracts/Version.php (3)
Version(7-58)fromArray(45-57)getCommitDate(28-31)
🔇 Additional comments (2)
tests/Contracts/VersionTest.php (1)
38-49: New test correctly exercises the'unknown'commitDate pathThis test cleanly verifies that
Version::fromArray()maps a'unknown'commitDatetonullwhile keepingcommitShaandpkgVersionintact; assertion choices and structure look good and consistent with existing tests.src/Contracts/Version.php (1)
13-31: Nullability change forcommitDatelooks consistent with intended behaviorMaking the
commitDateproperty andgetCommitDate()return type nullable aligns with the new"unknown"case and the added test. Existing callers that already treat the commit date as optional will work as-is; others will now get static-analysis hints to handlenull, which matches the reality of the upstream API.
Pull Request
This PR improves the handling of the
commitDatefield from Meilisearch's/versionendpoint.It appears
commitDatecan be the string "unknown" instead of a timestamp, which can cause parsing errors. This change adds robustness by handling "unknown", null, or other unparsable values, ensuring the application remains stable.This fixes failing tests that can be seen here: https://github.com/meilisearch/meilisearch-php/actions/runs/19986589382/job/57321426973?pr=835
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.