- Notifications
You must be signed in to change notification settings - Fork673
fix: use url-encoded ID in all paths#1819
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletionsgitlab/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -217,6 +217,15 @@ def get_id(self) -> Any: | ||
return None | ||
return getattr(self, self._id_attr) | ||
@property | ||
def encoded_id(self) -> Any: | ||
"""Ensure that the ID is url-encoded so that it can be safely used in a URL | ||
path""" | ||
obj_id = self.get_id() | ||
if isinstance(obj_id, str): | ||
obj_id = gitlab.utils.EncodedId(obj_id) | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return obj_id | ||
@property | ||
def attributes(self) -> Dict[str, Any]: | ||
d = self.__dict__["_updated_attrs"].copy() | ||
42 changes: 20 additions & 22 deletionsgitlab/mixins.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -99,8 +99,8 @@ def get( | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabGetError: If the server cannot perform the request | ||
""" | ||
if isinstance(id,str): | ||
id = utils.EncodedId(id) | ||
path = f"{self.path}/{id}" | ||
if TYPE_CHECKING: | ||
assert self._obj_cls is not None | ||
@@ -173,7 +173,7 @@ def refresh(self, **kwargs: Any) -> None: | ||
GitlabGetError: If the server cannot perform the request | ||
""" | ||
if self._id_attr: | ||
path = f"{self.manager.path}/{self.encoded_id}" | ||
JohnVillalovos marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
else: | ||
if TYPE_CHECKING: | ||
assert self.manager.path is not None | ||
@@ -391,7 +391,7 @@ def update( | ||
if id is None: | ||
path = self.path | ||
else: | ||
path = f"{self.path}/{utils.EncodedId(id)}" | ||
self._check_missing_update_attrs(new_data) | ||
files = {} | ||
@@ -444,7 +444,7 @@ def set(self, key: str, value: str, **kwargs: Any) -> base.RESTObject: | ||
Returns: | ||
The created/updated attribute | ||
""" | ||
path = f"{self.path}/{utils.EncodedId(key)}" | ||
data = {"value": value} | ||
server_data = self.gitlab.http_put(path, post_data=data, **kwargs) | ||
if TYPE_CHECKING: | ||
@@ -477,9 +477,7 @@ def delete(self, id: Union[str, int], **kwargs: Any) -> None: | ||
if id is None: | ||
path = self.path | ||
else: | ||
path = f"{self.path}/{utils.EncodedId(id)}" | ||
self.gitlab.http_delete(path, **kwargs) | ||
@@ -545,7 +543,7 @@ def save(self, **kwargs: Any) -> None: | ||
return | ||
# call the manager | ||
obj_id = self.encoded_id | ||
if TYPE_CHECKING: | ||
assert isinstance(self.manager, UpdateMixin) | ||
server_data = self.manager.update(obj_id, updated_data, **kwargs) | ||
@@ -575,7 +573,7 @@ def delete(self, **kwargs: Any) -> None: | ||
""" | ||
if TYPE_CHECKING: | ||
assert isinstance(self.manager, DeleteMixin) | ||
self.manager.delete(self.encoded_id, **kwargs) | ||
class UserAgentDetailMixin(_RestObjectBase): | ||
@@ -598,7 +596,7 @@ def user_agent_detail(self, **kwargs: Any) -> Dict[str, Any]: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabGetError: If the server cannot perform the request | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/user_agent_detail" | ||
result = self.manager.gitlab.http_get(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(result, requests.Response) | ||
@@ -631,7 +629,7 @@ def approve( | ||
GitlabUpdateError: If the server fails to perform the request | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/approve" | ||
data = {"access_level": access_level} | ||
server_data = self.manager.gitlab.http_put(path, post_data=data, **kwargs) | ||
if TYPE_CHECKING: | ||
@@ -705,7 +703,7 @@ def subscribe(self, **kwargs: Any) -> None: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabSubscribeError: If the subscription cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/subscribe" | ||
server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(server_data, requests.Response) | ||
@@ -725,7 +723,7 @@ def unsubscribe(self, **kwargs: Any) -> None: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabUnsubscribeError: If the unsubscription cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/unsubscribe" | ||
server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(server_data, requests.Response) | ||
@@ -752,7 +750,7 @@ def todo(self, **kwargs: Any) -> None: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabTodoError: If the todo cannot be set | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/todo" | ||
self.manager.gitlab.http_post(path, **kwargs) | ||
@@ -781,7 +779,7 @@ def time_stats(self, **kwargs: Any) -> Dict[str, Any]: | ||
if "time_stats" in self.attributes: | ||
return self.attributes["time_stats"] | ||
path = f"{self.manager.path}/{self.encoded_id}/time_stats" | ||
result = self.manager.gitlab.http_get(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(result, requests.Response) | ||
@@ -800,7 +798,7 @@ def time_estimate(self, duration: str, **kwargs: Any) -> Dict[str, Any]: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabTimeTrackingError: If the time tracking update cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/time_estimate" | ||
data = {"duration": duration} | ||
result = self.manager.gitlab.http_post(path, post_data=data, **kwargs) | ||
if TYPE_CHECKING: | ||
@@ -819,7 +817,7 @@ def reset_time_estimate(self, **kwargs: Any) -> Dict[str, Any]: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabTimeTrackingError: If the time tracking update cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/reset_time_estimate" | ||
result = self.manager.gitlab.http_post(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(result, requests.Response) | ||
@@ -838,7 +836,7 @@ def add_spent_time(self, duration: str, **kwargs: Any) -> Dict[str, Any]: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabTimeTrackingError: If the time tracking update cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/add_spent_time" | ||
data = {"duration": duration} | ||
result = self.manager.gitlab.http_post(path, post_data=data, **kwargs) | ||
if TYPE_CHECKING: | ||
@@ -857,7 +855,7 @@ def reset_spent_time(self, **kwargs: Any) -> Dict[str, Any]: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabTimeTrackingError: If the time tracking update cannot be done | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/reset_spent_time" | ||
result = self.manager.gitlab.http_post(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(result, requests.Response) | ||
@@ -893,7 +891,7 @@ def participants(self, **kwargs: Any) -> Dict[str, Any]: | ||
The list of participants | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/participants" | ||
result = self.manager.gitlab.http_get(path, **kwargs) | ||
if TYPE_CHECKING: | ||
assert not isinstance(result, requests.Response) | ||
@@ -967,7 +965,7 @@ def promote(self, **kwargs: Any) -> Dict[str, Any]: | ||
The updated object data (*not* a RESTObject) | ||
""" | ||
path = f"{self.manager.path}/{self.encoded_id}/promote" | ||
http_method = self._get_update_method() | ||
result = http_method(path, **kwargs) | ||
if TYPE_CHECKING: | ||
37 changes: 22 additions & 15 deletionsgitlab/utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiongitlab/v4/cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletionsgitlab/v4/objects/commits.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiongitlab/v4/objects/environments.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiongitlab/v4/objects/epics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiongitlab/v4/objects/features.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletionsgitlab/v4/objects/files.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.