| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 905781b commit 6d7c88a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,10 @@ Update a label for a project:: | |||
| 36 | 36 | label.color = '#112233' | |
| 37 | 37 | label.save() | |
| 38 | 38 | ||
| 39 | + Promote a project label to a group label:: | ||
| 40 | + | ||
| 41 | + label.promote() | ||
| 42 | + | ||
| 39 | 43 | Delete a label for a project:: | |
| 40 | 44 | ||
| 41 | 45 | project.labels.delete(label_id) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,6 +111,10 @@ class GitlabProjectDeployKeyError(GitlabOperationError): | |||
| 111 | 111 | pass | |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | + class GitlabPromoteError(GitlabOperationError): | ||
| 115 | + pass | ||
| 116 | + | ||
| 117 | + | ||
| 114 | 118 | class GitlabCancelError(GitlabOperationError): | |
| 115 | 119 | pass | |
| 116 | 120 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -926,3 +926,50 @@ def render(self, link_url: str, image_url: str, **kwargs: Any) -> Dict[str, Any] | |||
| 926 | 926 | if TYPE_CHECKING: | |
| 927 | 927 | assert not isinstance(result, requests.Response) | |
| 928 | 928 | return result | |
| 929 | + | ||
| 930 | + | ||
| 931 | + class PromoteMixin(_RestObjectBase): | ||
| 932 | + _id_attr: Optional[str] | ||
| 933 | + _attrs: Dict[str, Any] | ||
| 934 | + _module: ModuleType | ||
| 935 | + _parent_attrs: Dict[str, Any] | ||
| 936 | + _updated_attrs: Dict[str, Any] | ||
| 937 | + _update_uses_post: bool = False | ||
| 938 | + manager: base.RESTManager | ||
| 939 | + | ||
| 940 | + def _get_update_method( | ||
| 941 | + self, | ||
| 942 | + ) -> Callable[..., Union[Dict[str, Any], requests.Response]]: | ||
| 943 | + """Return the HTTP method to use. | ||
| 944 | + | ||
| 945 | + Returns: | ||
| 946 | + object: http_put (default) or http_post | ||
| 947 | + """ | ||
| 948 | + if self._update_uses_post: | ||
| 949 | + http_method = self.manager.gitlab.http_post | ||
| 950 | + else: | ||
| 951 | + http_method = self.manager.gitlab.http_put | ||
| 952 | + return http_method | ||
| 953 | + | ||
| 954 | + @exc.on_http_error(exc.GitlabPromoteError) | ||
| 955 | + def promote(self, **kwargs: Any) -> Dict[str, Any]: | ||
| 956 | + """Promote the item. | ||
| 957 | + | ||
| 958 | + Args: | ||
| 959 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 960 | + | ||
| 961 | + Raises: | ||
| 962 | + GitlabAuthenticationError: If authentication is not correct | ||
| 963 | + GitlabPromoteError: If the item could not be promoted | ||
| 964 | + GitlabParsingError: If the json data could not be parsed | ||
| 965 | + | ||
| 966 | + Returns: | ||
| 967 | + dict: The updated object data (*not* a RESTObject) | ||
| 968 | + """ | ||
| 969 | + | ||
| 970 | + path = "%s/%s/promote" % (self.manager.path, self.id) | ||
| 971 | + http_method = self._get_update_method() | ||
| 972 | + result = http_method(path, **kwargs) | ||
| 973 | + if TYPE_CHECKING: | ||
| 974 | + assert not isinstance(result, requests.Response) | ||
| 975 | + return result | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | DeleteMixin, | |
| 6 | 6 | ListMixin, | |
| 7 | 7 | ObjectDeleteMixin, | |
| 8 | + PromoteMixin, | ||
| 8 | 9 | RetrieveMixin, | |
| 9 | 10 | SaveMixin, | |
| 10 | 11 | SubscribableMixin, | |
@@ -83,7 +84,9 @@ def delete(self, name, **kwargs): | |||
| 83 | 84 | self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs) | |
| 84 | 85 | ||
| 85 | 86 | ||
| 86 | - class ProjectLabel(SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject): | ||
| 87 | + class ProjectLabel( | ||
| 88 | + PromoteMixin, SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject | ||
| 89 | + ): | ||
| 87 | 90 | _id_attr = "name" | |
| 88 | 91 | ||
| 89 | 92 | # Update without ID, but we need an ID to get from list. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + import uuid | ||
| 2 | + | ||
| 1 | 3 | import pytest | |
| 2 | 4 | ||
| 3 | 5 | import gitlab | |
@@ -159,6 +161,28 @@ def test_project_labels(project): | |||
| 159 | 161 | assert len(project.labels.list()) == 0 | |
| 160 | 162 | ||
| 161 | 163 | ||
| 164 | + def test_project_label_promotion(gl, group): | ||
| 165 | + """ | ||
| 166 | + Label promotion requires the project to be a child of a group (not in a user namespace) | ||
| 167 | + | ||
| 168 | + """ | ||
| 169 | + _id = uuid.uuid4().hex | ||
| 170 | + data = { | ||
| 171 | + "name": f"test-project-{_id}", | ||
| 172 | + "namespace_id": group.id, | ||
| 173 | + } | ||
| 174 | + project = gl.projects.create(data) | ||
| 175 | + | ||
| 176 | + label_name = "promoteme" | ||
| 177 | + promoted_label = project.labels.create({"name": label_name, "color": "#112233"}) | ||
| 178 | + promoted_label.promote() | ||
| 179 | + | ||
| 180 | + assert any(label.name == label_name for label in group.labels.list()) | ||
| 181 | + | ||
| 182 | + group.labels.delete(label_name) | ||
| 183 | + assert not any(label.name == label_name for label in group.labels.list()) | ||
| 184 | + | ||
| 185 | + | ||
| 162 | 186 | def test_project_milestones(project): | |
| 163 | 187 | milestone = project.milestones.create({"title": "milestone1"}) | |
| 164 | 188 | assert len(project.milestones.list()) == 1 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments