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

Build details page: normalize/trim command paths #9815

Merged
merged 4 commits into from
Dec 19, 2022

Conversation

humitos
Copy link
Member

@humitos humitos commented Dec 15, 2022

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

Screenshot_2022-12-15_18-48-01

After

Screenshot_2022-12-15_18-47-45

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.
@humitos humitos requested a review from a team as a code owner December 15, 2022 17:47
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Simple hacks ftw 👍

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)
Copy link
Member

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.

@humitos humitos enabled auto-merge (squash) December 19, 2022 11:12
@humitos humitos merged commit 20533d4 into main Dec 19, 2022
@humitos humitos deleted the humitos/path-build-details-page branch December 19, 2022 11:35
@humitos
Copy link
Member Author

humitos commented Dec 19, 2022

Ups, I enabled auto-merge, but I didn't add a test case for this. I will add it in another PR.

humitos added a commit that referenced this pull request Dec 20, 2022
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.
ericholscher added a commit that referenced this pull request Dec 20, 2022
ericholscher added a commit that referenced this pull request Dec 20, 2022
stsewd pushed a commit that referenced this pull request Dec 20, 2022
humitos added a commit that referenced this pull request Dec 21, 2022
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.
humitos added a commit that referenced this pull request Dec 21, 2022
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.
humitos added a commit that referenced this pull request Dec 21, 2022
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.
benjaoming added a commit that referenced this pull request Dec 22, 2022
)

* 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]>
stsewd added a commit that referenced this pull request Dec 22, 2022
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants