-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Build details page: normalize/trim command paths #9815
Conversation
Small hack to trim/normalize command paths when displaying them to the user under the build detail's page. This is a simple hack and there are more we can do here. Probably, there are some edge cases this is not catching. However, the worst it can happens is the path not being trimmed.
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.
Simple hacks ftw 👍
readthedocs/api/v2/serializers.py
Outdated
if settings.RTD_DOCKER_COMPOSE: | ||
docroot = re.sub('/[0-9a-z]+/?$', '', settings.DOCROOT, count=1) | ||
|
||
command = re.sub(f'{docroot}/[0-9a-z]+/{project_slug}/envs/{version_slug}(/bin/)?', '', obj.command, count=1) |
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.
I wonder if we want to remove count=1
, so if we have multiple paths in the command they will be removed? I don't know how often that happens, but seems fine to have this for now, also.
Ups, I enabled auto-merge, but I didn't add a test case for this. I will add it in another PR. |
This commit contains the test that was missing for my other PR: #9815 The test checks the commands' PATH are trimmed before being returned by the API.
This reverts commit 20533d4.
This reverts commit 20533d4.
Continuation of the work done in #9815 that didn't work as we expected. We weren't saving the commands properly when hitting the API since `serializers.SerializerMethodField` is a read-only field. This commit fixes this problem by using a different Serializer depending if it's a GET request or not, and if it's made by an Admin or not. It overrides the method `BuildViewSet.get_serializer_class` to manage these different cases and return the proper serializer. Done on top of #9815 to be sure the tests for saving commands are passing.
Continuation of the work done in #9815 that didn't work as we expected. We weren't saving the commands properly when hitting the API since `serializers.SerializerMethodField` is a read-only field. This commit fixes this problem by using a different Serializer depending if it's a GET request or not, and if it's made by an Admin or not. It overrides the method `BuildViewSet.get_serializer_class` to manage these different cases and return the proper serializer. Done on top of #9827 to be sure the tests for saving commands are passing.
This commit contains the test that was missing for my other PR: #9815 The test checks the commands' PATH are trimmed before being returned by the API.
) * Build details page: normalize/trim command paths (second attempt) Continuation of the work done in #9815 that didn't work as we expected. We weren't saving the commands properly when hitting the API since `serializers.SerializerMethodField` is a read-only field. This commit fixes this problem by using a different Serializer depending if it's a GET request or not, and if it's made by an Admin or not. It overrides the method `BuildViewSet.get_serializer_class` to manage these different cases and return the proper serializer. Done on top of #9827 to be sure the tests for saving commands are passing. * Feedback from review addressed - rename serializer to mention "ReadOnly" on it's class name - add docstrings to these serializers * Typo when accessing the action * Optional builder hash on local instance Old builds don't have the builder hash in the docroot, since that was implmented recently. * Lint * Apply suggestions from code review Co-authored-by: Benjamin Balder Bach <[email protected]> Co-authored-by: Benjamin Balder Bach <[email protected]>
* API V2: test that command is actually saved * Build details page: normalize/trim command paths (second attempt) (#9831) Continuation of the work done in #9815 that didn't work as we expected. We weren't saving the commands properly when hitting the API since `serializers.SerializerMethodField` is a read-only field. This commit fixes this problem by using a different Serializer depending if it's a GET request or not, and if it's made by an Admin or not. It overrides the method `BuildViewSet.get_serializer_class` to manage these different cases and return the proper serializer. Done on top of #9827 to be sure the tests for saving commands are passing. * Feedback from review addressed - rename serializer to mention "ReadOnly" on it's class name - add docstrings to these serializers * Typo when accessing the action * Optional builder hash on local instance Old builds don't have the builder hash in the docroot, since that was implmented recently. Co-authored-by: Manuel Kaufmann <[email protected]> Co-authored-by: Benjamin Balder Bach <[email protected]>
Small hack to trim/normalize command paths when displaying them to the user under the build detail's page.
This is a simple hack and there are more we can do here. Probably, there are some edge cases this is not catching. However, the worst it can happens is the path not being trimmed.
Before
After