summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab/v4/objects.py')
-rw-r--r--gitlab/v4/objects.py70
1 files changed, 68 insertions, 2 deletions
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index f22229c..13fbb53 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -229,6 +229,17 @@ class UserImpersonationTokenManager(NoUpdateMixin, RESTManager):
_list_filters = ("state",)
+class UserMembership(RESTObject):
+ _id_attr = "source_id"
+
+
+class UserMembershipManager(RetrieveMixin, RESTManager):
+ _path = "/users/%(user_id)s/memberships"
+ _obj_cls = UserMembership
+ _from_parent_attrs = {"user_id": "id"}
+ _list_filters = ("type",)
+
+
class UserProject(RESTObject):
pass
@@ -311,6 +322,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
("gpgkeys", "UserGPGKeyManager"),
("impersonationtokens", "UserImpersonationTokenManager"),
("keys", "UserKeyManager"),
+ ("memberships", "UserMembershipManager"),
("projects", "UserProjectManager"),
("status", "UserStatusManager"),
)
@@ -414,6 +426,7 @@ class UserManager(CRUDMixin, RESTManager):
"search",
"custom_attributes",
"status",
+ "two_factor",
)
_create_attrs = (
tuple(),
@@ -438,6 +451,8 @@ class UserManager(CRUDMixin, RESTManager):
"organization",
"location",
"avatar",
+ "public_email",
+ "private_profile",
),
)
_update_attrs = (
@@ -459,6 +474,8 @@ class UserManager(CRUDMixin, RESTManager):
"organization",
"location",
"avatar",
+ "public_email",
+ "private_profile",
),
)
_types = {"confirm": types.LowercaseStringAttribute, "avatar": types.ImageAttribute}
@@ -719,7 +736,16 @@ class FeatureManager(ListMixin, DeleteMixin, RESTManager):
_obj_cls = Feature
@exc.on_http_error(exc.GitlabSetError)
- def set(self, name, value, feature_group=None, user=None, **kwargs):
+ def set(
+ self,
+ name,
+ value,
+ feature_group=None,
+ user=None,
+ group=None,
+ project=None,
+ **kwargs
+ ):
"""Create or update the object.
Args:
@@ -727,6 +753,8 @@ class FeatureManager(ListMixin, DeleteMixin, RESTManager):
value (bool/int): The value to set for the object
feature_group (str): A feature group name
user (str): A GitLab username
+ group (str): A GitLab group
+ project (str): A GitLab project in form group/project
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
@@ -737,7 +765,14 @@ class FeatureManager(ListMixin, DeleteMixin, RESTManager):
obj: The created/updated attribute
"""
path = "%s/%s" % (self.path, name.replace("/", "%2F"))
- data = {"value": value, "feature_group": feature_group, "user": user}
+ data = {
+ "value": value,
+ "feature_group": feature_group,
+ "user": user,
+ "group": group,
+ "project": project,
+ }
+ data = utils.remove_none_from_dict(data)
server_data = self.gitlab.http_post(path, post_data=data, **kwargs)
return self._obj_cls(self, server_data)
@@ -2113,6 +2148,26 @@ class ProjectCommit(RESTObject):
path = "%s/%s/merge_requests" % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)
+ @cli.register_custom_action("ProjectCommit", ("branch",))
+ @exc.on_http_error(exc.GitlabRevertError)
+ def revert(self, branch, **kwargs):
+ """Revert a commit on a given branch.
+
+ Args:
+ branch (str): Name of target branch
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabRevertError: If the revert could not be performed
+
+ Returns:
+ dict: The new commit data (*not* a RESTObject)
+ """
+ path = "%s/%s/revert" % (self.manager.path, self.get_id())
+ post_data = {"branch": branch}
+ return self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
+
class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits"
@@ -5087,3 +5142,14 @@ class GeoNodeManager(RetrieveMixin, UpdateMixin, DeleteMixin, RESTManager):
list: The list of failures
"""
return self.gitlab.http_list("/geo_nodes/current/failures", **kwargs)
+
+
+class Application(ObjectDeleteMixin, RESTObject):
+ _url = "/applications"
+ _short_print_attr = "name"
+
+
+class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
+ _path = "/applications"
+ _obj_cls = Application
+ _create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",))