| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -433,7 +433,9 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs): | |||
| 433 | 433 | ||
| 434 | 434 | ||
| 435 | 435 | class SubscribableMixin(object): | |
| 436 | - @cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest", "ProjectLabel")) | ||
| 436 | + @cli.register_custom_action( | ||
| 437 | + ("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel") | ||
| 438 | + ) | ||
| 437 | 439 | @exc.on_http_error(exc.GitlabSubscribeError) | |
| 438 | 440 | def subscribe(self, **kwargs): | |
| 439 | 441 | """Subscribe to the object notifications. | |
@@ -449,7 +451,9 @@ def subscribe(self, **kwargs): | |||
| 449 | 451 | server_data = self.manager.gitlab.http_post(path, **kwargs) | |
| 450 | 452 | self._update_attrs(server_data) | |
| 451 | 453 | ||
| 452 | - @cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest", "ProjectLabel")) | ||
| 454 | + @cli.register_custom_action( | ||
| 455 | + ("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel") | ||
| 456 | + ) | ||
| 453 | 457 | @exc.on_http_error(exc.GitlabUnsubscribeError) | |
| 454 | 458 | def unsubscribe(self, **kwargs): | |
| 455 | 459 | """Unsubscribe from the object notifications. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -833,6 +833,64 @@ class GroupIssueManager(ListMixin, RESTManager): | |||
| 833 | 833 | _types = {"labels": types.ListAttribute} | |
| 834 | 834 | ||
| 835 | 835 | ||
| 836 | + class GroupLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject): | ||
| 837 | + _id_attr = "name" | ||
| 838 | + | ||
| 839 | + # Update without ID, but we need an ID to get from list. | ||
| 840 | + @exc.on_http_error(exc.GitlabUpdateError) | ||
| 841 | + def save(self, **kwargs): | ||
| 842 | + """Saves the changes made to the object to the server. | ||
| 843 | + | ||
| 844 | + The object is updated to match what the server returns. | ||
| 845 | + | ||
| 846 | + Args: | ||
| 847 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 848 | + | ||
| 849 | + Raises: | ||
| 850 | + GitlabAuthenticationError: If authentication is not correct. | ||
| 851 | + GitlabUpdateError: If the server cannot perform the request. | ||
| 852 | + """ | ||
| 853 | + updated_data = self._get_updated_data() | ||
| 854 | + | ||
| 855 | + # call the manager | ||
| 856 | + server_data = self.manager.update(None, updated_data, **kwargs) | ||
| 857 | + self._update_attrs(server_data) | ||
| 858 | + | ||
| 859 | + | ||
| 860 | + class GroupLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager): | ||
| 861 | + _path = "/groups/%(group_id)s/labels" | ||
| 862 | + _obj_cls = GroupLabel | ||
| 863 | + _from_parent_attrs = {"group_id": "id"} | ||
| 864 | + _create_attrs = (("name", "color"), ("description", "priority")) | ||
| 865 | + _update_attrs = (("name",), ("new_name", "color", "description", "priority")) | ||
| 866 | + | ||
| 867 | + # Update without ID. | ||
| 868 | + def update(self, name, new_data={}, **kwargs): | ||
| 869 | + """Update a Label on the server. | ||
| 870 | + | ||
| 871 | + Args: | ||
| 872 | + name: The name of the label | ||
| 873 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 874 | + """ | ||
| 875 | + new_data["name"] = name | ||
| 876 | + super().update(id=None, new_data=new_data, **kwargs) | ||
| 877 | + | ||
| 878 | + # Delete without ID. | ||
| 879 | + @exc.on_http_error(exc.GitlabDeleteError) | ||
| 880 | + def delete(self, name, **kwargs): | ||
| 881 | + """Delete a Label on the server. | ||
| 882 | + | ||
| 883 | + Args: | ||
| 884 | + name: The name of the label | ||
| 885 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 886 | + | ||
| 887 | + Raises: | ||
| 888 | + GitlabAuthenticationError: If authentication is not correct | ||
| 889 | + GitlabDeleteError: If the server cannot perform the request | ||
| 890 | + """ | ||
| 891 | + self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs) | ||
| 892 | + | ||
| 893 | + | ||
| 836 | 894 | class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 837 | 895 | _short_print_attr = "username" | |
| 838 | 896 | ||
@@ -1042,6 +1100,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 1042 | 1100 | ("customattributes", "GroupCustomAttributeManager"), | |
| 1043 | 1101 | ("epics", "GroupEpicManager"), | |
| 1044 | 1102 | ("issues", "GroupIssueManager"), | |
| 1103 | + ("labels", "GroupLabelManager"), | ||
| 1045 | 1104 | ("members", "GroupMemberManager"), | |
| 1046 | 1105 | ("mergerequests", "GroupMergeRequestManager"), | |
| 1047 | 1106 | ("milestones", "GroupMilestoneManager"), | |
@@ -2934,6 +2993,17 @@ class ProjectLabelManager( | |||
| 2934 | 2993 | _create_attrs = (("name", "color"), ("description", "priority")) | |
| 2935 | 2994 | _update_attrs = (("name",), ("new_name", "color", "description", "priority")) | |
| 2936 | 2995 | ||
| 2996 | + # Update without ID. | ||
| 2997 | + def update(self, name, new_data={}, **kwargs): | ||
| 2998 | + """Update a Label on the server. | ||
| 2999 | + | ||
| 3000 | + Args: | ||
| 3001 | + name: The name of the label | ||
| 3002 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 3003 | + """ | ||
| 3004 | + new_data["name"] = name | ||
| 3005 | + super().update(id=None, new_data=new_data, **kwargs) | ||
| 3006 | + | ||
| 2937 | 3007 | # Delete without ID. | |
| 2938 | 3008 | @exc.on_http_error(exc.GitlabDeleteError) | |
| 2939 | 3009 | def delete(self, name, **kwargs): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,17 @@ testcase "project update" ' | |||
| 25 | 25 | GITLAB project update --id "$PROJECT_ID" --description "My New Description" | |
| 26 | 26 | ' | |
| 27 | 27 | ||
| 28 | + testcase "group creation" ' | ||
| 29 | + OUTPUT=$(try GITLAB group create --name test-group1 --path group1) || exit 1 | ||
| 30 | + GROUP_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d" " -f2) | ||
| 31 | + OUTPUT=$(try GITLAB group list) || exit 1 | ||
| 32 | + pecho "${OUTPUT}" | grep -q test-group1 | ||
| 33 | + ' | ||
| 34 | + | ||
| 35 | + testcase "group update" ' | ||
| 36 | + GITLAB group update --id "$GROUP_ID" --description "My New Description" | ||
| 37 | + ' | ||
| 38 | + | ||
| 28 | 39 | testcase "user creation" ' | |
| 29 | 40 | OUTPUT=$(GITLAB user create --email fake@email.com --username user1 \ | |
| 30 | 41 | --name "User One" --password fakepassword) | |
@@ -89,6 +100,46 @@ testcase "merge request validation" ' | |||
| 89 | 100 | --iid "$MR_ID" >/dev/null 2>&1 | |
| 90 | 101 | ' | |
| 91 | 102 | ||
| 103 | + # Test project labels | ||
| 104 | + testcase "create project label" ' | ||
| 105 | + OUTPUT=$(GITLAB -v project-label create --project-id $PROJECT_ID \ | ||
| 106 | + --name prjlabel1 --description "prjlabel1 description" --color "#112233") | ||
| 107 | + ' | ||
| 108 | + | ||
| 109 | + testcase "list project label" ' | ||
| 110 | + OUTPUT=$(GITLAB -v project-label list --project-id $PROJECT_ID) | ||
| 111 | + ' | ||
| 112 | + | ||
| 113 | + testcase "update project label" ' | ||
| 114 | + OUTPUT=$(GITLAB -v project-label update --project-id $PROJECT_ID \ | ||
| 115 | + --name prjlabel1 --new-name prjlabel2 --description "prjlabel2 description" --color "#332211") | ||
| 116 | + ' | ||
| 117 | + | ||
| 118 | + testcase "delete project label" ' | ||
| 119 | + OUTPUT=$(GITLAB -v project-label delete --project-id $PROJECT_ID \ | ||
| 120 | + --name prjlabel2) | ||
| 121 | + ' | ||
| 122 | + | ||
| 123 | + # Test group labels | ||
| 124 | + testcase "create group label" ' | ||
| 125 | + OUTPUT=$(GITLAB -v group-label create --group-id $GROUP_ID \ | ||
| 126 | + --name grplabel1 --description "grplabel1 description" --color "#112233") | ||
| 127 | + ' | ||
| 128 | + | ||
| 129 | + testcase "list group label" ' | ||
| 130 | + OUTPUT=$(GITLAB -v group-label list --group-id $GROUP_ID) | ||
| 131 | + ' | ||
| 132 | + | ||
| 133 | + testcase "update group label" ' | ||
| 134 | + OUTPUT=$(GITLAB -v group-label update --group-id $GROUP_ID \ | ||
| 135 | + --name grplabel1 --new-name grplabel2 --description "grplabel2 description" --color "#332211") | ||
| 136 | + ' | ||
| 137 | + | ||
| 138 | + testcase "delete group label" ' | ||
| 139 | + OUTPUT=$(GITLAB -v group-label delete --group-id $GROUP_ID \ | ||
| 140 | + --name grplabel2) | ||
| 141 | + ' | ||
| 142 | + | ||
| 92 | 143 | # Test project variables | |
| 93 | 144 | testcase "create project variable" ' | |
| 94 | 145 | OUTPUT=$(GITLAB -v project-variable create --project-id $PROJECT_ID \ | |
@@ -128,6 +179,10 @@ testcase "project deletion" ' | |||
| 128 | 179 | GITLAB project delete --id "$PROJECT_ID" | |
| 129 | 180 | ' | |
| 130 | 181 | ||
| 182 | + testcase "group deletion" ' | ||
| 183 | + OUTPUT=$(try GITLAB group delete --id $GROUP_ID) | ||
| 184 | + ' | ||
| 185 | + | ||
| 131 | 186 | testcase "application settings get" ' | |
| 132 | 187 | GITLAB application-settings get >/dev/null 2>&1 | |
| 133 | 188 | ' | |
@@ -146,3 +201,4 @@ testcase "values from files" ' | |||
| 146 | 201 | --description @/tmp/gitlab-project-description) | |
| 147 | 202 | echo $OUTPUT | grep -q "Multi line" | |
| 148 | 203 | ' | |
| 204 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -337,6 +337,18 @@ | |||
| 337 | 337 | g_v.delete() | |
| 338 | 338 | assert len(group1.variables.list()) == 0 | |
| 339 | 339 | ||
| 340 | + # group labels | ||
| 341 | + group1.labels.create({"name": "foo", "description": "bar", "color": "#112233"}) | ||
| 342 | + g_l = group1.labels.get("foo") | ||
| 343 | + assert g_l.description == "bar" | ||
| 344 | + g_l.description = "baz" | ||
| 345 | + g_l.save() | ||
| 346 | + g_l = group1.labels.get("foo") | ||
| 347 | + assert g_l.description == "baz" | ||
| 348 | + assert len(group1.labels.list()) == 1 | ||
| 349 | + g_l.delete() | ||
| 350 | + assert len(group1.labels.list()) == 0 | ||
| 351 | + | ||
| 340 | 352 | # hooks | |
| 341 | 353 | hook = gl.hooks.create({"url": "http://whatever.com"}) | |
| 342 | 354 | assert len(gl.hooks.list()) == 1 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments