Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: create new ArrayAttribute class#1866

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
nejch merged 1 commit intomainfromjlvillal/arrays_2
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletiongitlab/types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,9 @@ def get_for_api(self) -> Any:
return self._value


class CommaSeparatedListAttribute(GitlabAttribute):
class _ListArrayAttribute(GitlabAttribute):
"""Helper class to support `list` / `array` types."""

def set_from_cli(self, cli_value: str) -> None:
if not cli_value.strip():
self._value = []
Expand All@@ -49,6 +51,17 @@ def get_for_api(self) -> str:
return ",".join([str(x) for x in self._value])


class ArrayAttribute(_ListArrayAttribute):
"""To support `array` types as documented in
https://docs.gitlab.com/ee/api/#array"""


class CommaSeparatedListAttribute(_ListArrayAttribute):
"""For values which are sent to the server as a Comma Separated Values
(CSV) string. We allow them to be specified as a list and we convert it
into a CSV"""


class LowercaseStringAttribute(GitlabAttribute):
def get_for_api(self) -> str:
return str(self._value).lower()
Expand Down
7 changes: 2 additions & 5 deletionsgitlab/v4/objects/groups.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -314,10 +314,7 @@ class GroupManager(CRUDMixin, RESTManager):
"shared_runners_setting",
),
)
_types = {
"avatar": types.ImageAttribute,
"skip_groups": types.CommaSeparatedListAttribute,
}
_types = {"avatar": types.ImageAttribute, "skip_groups": types.ArrayAttribute}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Group:
return cast(Group, super().get(id=id, lazy=lazy, **kwargs))
Expand DownExpand Up@@ -377,7 +374,7 @@ class GroupSubgroupManager(ListMixin, RESTManager):
"with_custom_attributes",
"min_access_level",
)
_types = {"skip_groups": types.CommaSeparatedListAttribute}
_types = {"skip_groups": types.ArrayAttribute}


class GroupDescendantGroup(RESTObject):
Expand Down
15 changes: 3 additions & 12 deletionsgitlab/v4/objects/issues.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,10 +65,7 @@ class IssueManager(RetrieveMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}
_types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Issue:
return cast(Issue, super().get(id=id, lazy=lazy, **kwargs))
Expand DownExpand Up@@ -98,10 +95,7 @@ class GroupIssueManager(ListMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}
_types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}
Copy link
Member

Choose a reason for hiding this comment

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

lol, this is infuriating:
https://docs.gitlab.com/ee/api/issues.html#list-issues

GET /issues?iids[]=42&iids[]=43GET /issues?labels=foo,bar

😁 thanks for going through all the endpoints. I hope the API docs are accurate.



class ProjectIssue(
Expand DownExpand Up@@ -239,10 +233,7 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
"discussion_locked",
),
)
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}
_types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
4 changes: 2 additions & 2 deletionsgitlab/v4/objects/members.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class GroupMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.CommaSeparatedListAttribute}
_types = {"user_ids": types.ArrayAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand DownExpand Up@@ -101,7 +101,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.CommaSeparatedListAttribute}
_types = {"user_ids": types.ArrayAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
14 changes: 7 additions & 7 deletionsgitlab/v4/objects/merge_requests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,8 +95,8 @@ class MergeRequestManager(ListMixin, RESTManager):
"deployed_after",
)
_types = {
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"approver_ids": types.ArrayAttribute,
"approved_by_ids": types.ArrayAttribute,
"in": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}
Expand DownExpand Up@@ -133,8 +133,8 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
"wip",
)
_types = {
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"approver_ids": types.ArrayAttribute,
"approved_by_ids": types.ArrayAttribute,
"labels": types.CommaSeparatedListAttribute,
}

Expand DownExpand Up@@ -455,9 +455,9 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
"wip",
)
_types = {
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"iids": types.CommaSeparatedListAttribute,
"approver_ids": types.ArrayAttribute,
"approved_by_ids": types.ArrayAttribute,
"iids": types.ArrayAttribute,
"labels": types.CommaSeparatedListAttribute,
}

Expand Down
4 changes: 2 additions & 2 deletionsgitlab/v4/objects/milestones.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.CommaSeparatedListAttribute}
_types = {"iids": types.ArrayAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand DownExpand Up@@ -177,7 +177,7 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.CommaSeparatedListAttribute}
_types = {"iids": types.ArrayAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
2 changes: 1 addition & 1 deletiongitlab/v4/objects/projects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -125,7 +125,7 @@ class ProjectGroupManager(ListMixin, RESTManager):
"shared_min_access_level",
"shared_visible_only",
)
_types = {"skip_groups": types.CommaSeparatedListAttribute}
_types = {"skip_groups": types.ArrayAttribute}


class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject):
Expand Down
12 changes: 6 additions & 6 deletionsgitlab/v4/objects/settings.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,12 +80,12 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
),
)
_types = {
"asset_proxy_allowlist": types.CommaSeparatedListAttribute,
"disabled_oauth_sign_in_sources": types.CommaSeparatedListAttribute,
"domain_allowlist": types.CommaSeparatedListAttribute,
"domain_denylist": types.CommaSeparatedListAttribute,
"import_sources": types.CommaSeparatedListAttribute,
"restricted_visibility_levels": types.CommaSeparatedListAttribute,
"asset_proxy_allowlist": types.ArrayAttribute,
"disabled_oauth_sign_in_sources": types.ArrayAttribute,
"domain_allowlist": types.ArrayAttribute,
"domain_denylist": types.ArrayAttribute,
"import_sources": types.ArrayAttribute,
"restricted_visibility_levels": types.ArrayAttribute,
}

@exc.on_http_error(exc.GitlabUpdateError)
Expand Down
2 changes: 1 addition & 1 deletiongitlab/v4/objects/users.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -369,7 +369,7 @@ class ProjectUserManager(ListMixin, RESTManager):
_obj_cls = ProjectUser
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("search", "skip_users")
_types = {"skip_users": types.CommaSeparatedListAttribute}
_types = {"skip_users": types.ArrayAttribute}


class UserEmail(ObjectDeleteMixin, RESTObject):
Expand Down
42 changes: 30 additions & 12 deletionstests/unit/test_types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,45 +30,63 @@ def test_gitlab_attribute_get():
assert o._value is None


deftest_csv_list_attribute_input():
o = types.CommaSeparatedListAttribute()
deftest_array_attribute_input():
o = types.ArrayAttribute()
o.set_from_cli("foo,bar,baz")
assert o.get() == ["foo", "bar", "baz"]

o.set_from_cli("foo")
assert o.get() == ["foo"]


deftest_csv_list_attribute_empty_input():
o = types.CommaSeparatedListAttribute()
deftest_array_attribute_empty_input():
o = types.ArrayAttribute()
o.set_from_cli("")
assert o.get() == []

o.set_from_cli(" ")
assert o.get() == []


deftest_csv_list_attribute_get_for_api_from_cli():
o = types.CommaSeparatedListAttribute()
deftest_array_attribute_get_for_api_from_cli():
o = types.ArrayAttribute()
o.set_from_cli("foo,bar,baz")
assert o.get_for_api() == "foo,bar,baz"


deftest_csv_list_attribute_get_for_api_from_list():
o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"])
deftest_array_attribute_get_for_api_from_list():
o = types.ArrayAttribute(["foo", "bar", "baz"])
assert o.get_for_api() == "foo,bar,baz"


deftest_csv_list_attribute_get_for_api_from_int_list():
o = types.CommaSeparatedListAttribute([1, 9, 7])
deftest_array_attribute_get_for_api_from_int_list():
o = types.ArrayAttribute([1, 9, 7])
assert o.get_for_api() == "1,9,7"


deftest_csv_list_attribute_does_not_split_string():
o = types.CommaSeparatedListAttribute("foo")
deftest_array_attribute_does_not_split_string():
o = types.ArrayAttribute("foo")
assert o.get_for_api() == "foo"


# CommaSeparatedListAttribute tests
def test_csv_string_attribute_get_for_api_from_cli():
o = types.CommaSeparatedListAttribute()
o.set_from_cli("foo,bar,baz")
assert o.get_for_api() == "foo,bar,baz"


def test_csv_string_attribute_get_for_api_from_list():
o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"])
assert o.get_for_api() == "foo,bar,baz"


def test_csv_string_attribute_get_for_api_from_int_list():
o = types.CommaSeparatedListAttribute([1, 9, 7])
assert o.get_for_api() == "1,9,7"


# LowercaseStringAttribute tests
def test_lowercase_string_attribute_get_for_api():
o = types.LowercaseStringAttribute("FOO")
assert o.get_for_api() == "foo"

[8]ページ先頭

©2009-2025 Movatter.jp