-
-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor uploadFile #313
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
base: main
Are you sure you want to change the base?
Refactor uploadFile #313
Conversation
Add correct filename and extension Signed-off-by: eshimischi <eshimischi@gmail.com>
|
Warning Rate limit exceeded@eshimischi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 49 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRemoved automatic injection of a Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Signed-off-by: eshimischi <eshimischi@gmail.com>
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: 1
🤖 Fix all issues with AI agents
In @src/Client/MultipartTrait.php:
- Around line 29-30: The change removed automatic injection of the 'name' key
for array-valued multipart elements causing GuzzleHttp MultipartStream to fail;
restore backward compatibility in MultipartTrait by ensuring any array $value
with 'contents' gets a 'name' key when missing (i.e., before pushing to
$elements, if is_array($value) && isset($value['contents']) and
!isset($value['name']) then set $value['name'] to the appropriate field name),
so callers that only provide 'contents'/'filename' continue to work;
alternatively update all endpoints that build multipart arrays (LDAPEndpoint,
UsersEndpoint, SAMLEndpoint, SystemEndpoint, TeamsEndpoint, PluginsEndpoint,
EmojiEndpoint) to include 'name' at construction time, but prefer restoring the
conditional injection in MultipartTrait for immediate compatibility.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Client/MultipartTrait.php
🧰 Additional context used
📓 Path-based instructions (2)
**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.php: Run static analysis withvendor/bin/phpstan analyse
Use Rector for code quality fixes withcomposer rector:dry-runto preview andcomposer rectorto apply fixes
Files:
src/Client/MultipartTrait.php
src/Client/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
Regenerate API client from OpenAPI spec using
php bin/api-generateafter spec changes
Files:
src/Client/MultipartTrait.php
|
In order to upload correct filename with proper extension into Mattermost |
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: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Client/Endpoint/FilesEndpoint.php (1)
66-67: Remove redundant query parameters; use multipart/form-data approach exclusively.The code adds
channel_idandfilenameas query parameters (lines 66-67), then also includeschannel_idin the multipart form data (line 82) and sets a multipart Content-Type header (line 89). The Mattermost API v4 file upload endpoint supports two mutually exclusive approaches: either multipart/form-data with parameters in the form data, or raw body with parameters in the query string. This implementation mixes both, which is not a valid request pattern.Remove lines 66-67 to use only the multipart/form-data approach, which is already correctly implemented in lines 75-90 and is the recommended pattern for backward compatibility.
🤖 Fix all issues with AI agents
In @src/Client/Endpoint/FilesEndpoint.php:
- Line 78: pathinfo() is being called on $files which per the docblock can be a
string, resource, or Psr\Http\Message\StreamInterface; to fix, guard the call by
checking the type of $files and only call pathinfo($files, PATHINFO_FILENAME)
when is_string($files), otherwise fall back to using the provided $filename
parameter (or require/validate a separate form name) and if neither is available
throw/return a clear error; update the logic around $files and $filename where
$file_name is assigned so resources/streams use $filename (or a validated
alternative) and StreamInterface cases are handled explicitly.
- Line 79: The multipart form entry in FilesEndpoint.php sets the form field
"name" incorrectly to the filename variable; update the $multipartFields
assignment for 'files' in the send/upload routine so the 'name' key is the
static form field identifier "files" (i.e. set 'name' => 'files' instead of
using $file_name) and keep 'contents' => $files and 'filename' => $filename to
match other endpoints and produce Content-Disposition: form-data; name="files".
🧹 Nitpick comments (1)
src/Client/Endpoint/FilesEndpoint.php (1)
81-83: Remove redundant null check.Since
$channel_idis now a non-nullablestringparameter (line 59), it cannot be null. This check is redundant and should be removed.♻️ Suggested cleanup
-if ($channel_id !== null) { - $multipartFields['channel_id'] = $channel_id; -} +$multipartFields['channel_id'] = $channel_id;
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Client/Endpoint/FilesEndpoint.php
🧰 Additional context used
📓 Path-based instructions (4)
**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.php: Run static analysis withvendor/bin/phpstan analyse
Use Rector for code quality fixes withcomposer rector:dry-runto preview andcomposer rectorto apply fixes
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
Regenerate API client from OpenAPI spec using
php bin/api-generateafter spec changes
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/{Endpoint,Model}/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
src/Client/{Endpoint,Model}/**/*.php: Do not manually edit generated files insrc/Client/Endpoint/andsrc/Client/Model/
Ensure generated code insrc/Client/Endpoint/andsrc/Client/Model/is included in Rector validation for consistent code quality
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/Endpoint/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
Implement endpoint groups in
src/Client/Endpoint/with methods for specific API operations
Files:
src/Client/Endpoint/FilesEndpoint.php
🧬 Code graph analysis (1)
src/Client/Endpoint/FilesEndpoint.php (1)
src/Client.php (1)
files(156-159)
🔇 Additional comments (1)
src/Client/Endpoint/FilesEndpoint.php (1)
5-8: This file is already generated byphp bin/api-generate(commit 5ee35a0). No manual edits were made to this file that would be lost on regeneration. If there are code quality concerns with the current implementation, they should be addressed by updating the OpenAPI specification and regenerating, or by fixing the generation logic itself, not by treating this as a manually-edited file.Likely an incorrect or invalid review comment.
Signed-off-by: eshimischi <eshimischi@gmail.com>
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: 2
🤖 Fix all issues with AI agents
In @src/Client/Endpoint/FilesEndpoint.php:
- Around line 77-80: The code currently calls pathinfo($files,
PATHINFO_FILENAME) which is invalid when $files is a resource, StreamInterface,
or raw binary; replace deriving name from $files with using the provided
$filename (or validate $files is a path string before calling pathinfo). Update
the block that sets $multipartFields['files'] (the code referencing $files,
pathinfo and $filename in FilesEndpoint.php) to use $filename (or a sanitized
fallback) for the 'name' field and avoid calling pathinfo on non-string inputs;
add a simple type check (is_string) if you still want to support path inputs and
otherwise skip pathinfo.
🧹 Nitpick comments (1)
src/Client/Endpoint/FilesEndpoint.php (1)
81-83: Redundant null check —$channel_idis non-nullable.Since
$channel_idis now typed asstring(non-nullable), theif ($channel_id !== null)check is always true. This can be simplified.♻️ Suggested simplification
- if ($channel_id !== null) { - $multipartFields['channel_id'] = $channel_id; - } + $multipartFields['channel_id'] = $channel_id;
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Client/Endpoint/FilesEndpoint.php
🧰 Additional context used
📓 Path-based instructions (4)
**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.php: Run static analysis withvendor/bin/phpstan analyse
Use Rector for code quality fixes withcomposer rector:dry-runto preview andcomposer rectorto apply fixes
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
Regenerate API client from OpenAPI spec using
php bin/api-generateafter spec changes
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/{Endpoint,Model}/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
src/Client/{Endpoint,Model}/**/*.php: Do not manually edit generated files insrc/Client/Endpoint/andsrc/Client/Model/
Ensure generated code insrc/Client/Endpoint/andsrc/Client/Model/is included in Rector validation for consistent code quality
Files:
src/Client/Endpoint/FilesEndpoint.php
src/Client/Endpoint/**/*.php
📄 CodeRabbit inference engine (CLAUDE.md)
Implement endpoint groups in
src/Client/Endpoint/with methods for specific API operations
Files:
src/Client/Endpoint/FilesEndpoint.php
Signed-off-by: eshimischi <eshimischi@gmail.com>
Signed-off-by: eshimischi <eshimischi@gmail.com>
|
@cedricziel not sure about a proper way to change openapi.json, would you please help with it |
Add correct filename and extension
Summary by CodeRabbit
Bug Fixes
New Features / UX
✏️ Tip: You can customize this high-level summary in your review settings.