Skip to content

Commit

Permalink
Rework merge requests update
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
Gauvain Pocentek committed May 10, 2016
1 parent 1915519 commit aff99b1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions gitlab/objects.py
Expand Up @@ -215,7 +215,10 @@ def _data_for_gitlab(self, extra_parameters={}, update=False):
attributes = list(attributes) + ['sudo', 'page', 'per_page']
for attribute in attributes:
if hasattr(self, attribute):
data[attribute] = getattr(self, attribute)
value = getattr(self, attribute)
if isinstance(value, list):
value = ",".join(value)
data[attribute] = value

data.update(extra_parameters)

Expand Down Expand Up @@ -1078,7 +1081,8 @@ class ProjectMergeRequest(GitlabObject):
_constructorTypes = {'author': 'User', 'assignee': 'User'}
requiredUrlAttrs = ['project_id']
requiredCreateAttrs = ['source_branch', 'target_branch', 'title']
optionalCreateAttrs = ['assignee_id']
optionalCreateAttrs = ['assignee_id', 'description', 'target_project_id',
'labels', 'milestone_id']
managers = [('notes', ProjectMergeRequestNoteManager,
[('project_id', 'project_id'), ('merge_request_id', 'id')])]

Expand All @@ -1089,6 +1093,19 @@ def Note(self, id=None, **kwargs):
self.gitlab, id, project_id=self.project_id,
merge_request_id=self.id, **kwargs)

def _data_for_gitlab(self, extra_parameters={}, update=False):
data = (super(ProjectMergeRequest, self)
._data_for_gitlab(extra_parameters))
if update:
# Drop source_branch attribute as it is not accepted by the gitlab
# server (Issue #76)
# We need to unserialize and reserialize the
# data, this is far from optimal
d = json.loads(data)
d.pop('source_branch', None)
data = json.dumps(d)
return data

def cancel_merge_when_build_succeeds(self, **kwargs):
"""Cancel merge when build succeeds."""

Expand Down

0 comments on commit aff99b1

Please sign in to comment.