Skip to content

Commit 7981987

Browse files
author
Gauvain Pocentek
committed
Implement setting release info on a tag
Add the set_release_description() method to ProjectTag. Add python API test for this method.
1 parent 0814d86 commit 7981987

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

gitlab/objects.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ class ProjectBranch(GitlabObject):
638638
canUpdate = False
639639
requiredUrlAttrs = ['project_id']
640640
requiredCreateAttrs = ['branch_name', 'ref']
641-
_constructorTypes = {'commit': 'ProjectCommit'}
642641

643642
def protect(self, protect=True, **kwargs):
644643
url = self._url % {'project_id': self.project_id}
@@ -832,8 +831,23 @@ class ProjectNoteManager(BaseManager):
832831
obj_cls = ProjectNote
833832

834833

834+
class ProjectTagRelease(GitlabObject):
835+
_url = '/projects/%(project_id)s/repository/tags/%(tag_name)/release'
836+
canDelete = False
837+
canList = False
838+
requiredUrlAttrs = ['project_id', 'tag_name']
839+
requiredCreateAttrs = ['description']
840+
shortPrintAttr = 'description'
841+
842+
843+
class ProjectTagReleaseManager(BaseManager):
844+
obj_cls = ProjectTagRelease
845+
846+
835847
class ProjectTag(GitlabObject):
836848
_url = '/projects/%(project_id)s/repository/tags'
849+
_constructorTypes = {'release': 'ProjectTagRelease',
850+
'commit': 'ProjectCommit'}
837851
idAttr = 'name'
838852
canGet = 'from_list'
839853
canUpdate = False
@@ -842,6 +856,17 @@ class ProjectTag(GitlabObject):
842856
optionalCreateAttrs = ['message']
843857
shortPrintAttr = 'name'
844858

859+
def set_release_description(self, description):
860+
url = '/projects/%s/repository/tags/%s/release' % (self.project_id,
861+
self.name)
862+
if self.release is None:
863+
r = self.gitlab._raw_post(url, data={'description': description})
864+
raise_error_from_response(r, GitlabCreateError, 201)
865+
else:
866+
r = self.gitlab._raw_put(url, data={'description': description})
867+
raise_error_from_response(r, GitlabUpdateError, 200)
868+
self.release = ProjectTagRelease(self, r.json())
869+
845870

846871
class ProjectTagManager(BaseManager):
847872
obj_cls = ProjectTag

tools/python_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,7 @@
148148
# tags
149149
tag1 = admin_project.tags.create({'tag_name': 'v1.0', 'ref': 'master'})
150150
assert(len(admin_project.tags.list()) == 1)
151+
tag1.set_release_description('Description 1')
152+
tag1.set_release_description('Description 2')
153+
assert(tag1.release.description == 'Description 2')
151154
tag1.delete()

0 commit comments

Comments
 (0)