Skip to content

Commit 7b96b0c

Browse files
author
Colin D Bennett
committed
Support setting commit status
Support commit status updates. Commit status can be set by a POST to the appropriate commit URL. The status can be updated by a subsequent POST to the same URL with the same `name` and `ref`, but different values for `state`, `description`, etc. Add project-commit-status example to README.md file. Note: Listing the commit statuses is not yet supported. This is done through a different path on the server, under the `repository` path.
1 parent dc0099d commit 7b96b0c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,9 @@ Impossible to create object (Missing attribute(s): title, file-name, code)
166166

167167
# oops, let's add the attributes:
168168
gitlab project-snippet create --project-id 2 --title "the title" --file-name "the name" --code "the code"
169+
170+
# add a build status to a commit
171+
gitlab project-commit-status create --project-id 2 --commit-id a43290c \
172+
--state success --name ci/jenkins --target-url http://server/build/123 \
173+
--description "Jenkins build succeeded"
169174
`````

gitlab/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,21 @@ def Team(self, id=None, **kwargs):
521521
to write it on the server.
522522
"""
523523
return Team._get_list_or_object(self, id, **kwargs)
524+
525+
def Status(self, id=None, **kwargs):
526+
"""Create status for a Git commit.
527+
528+
This is often used for automated software build or test status.
529+
530+
Args:
531+
id: Commit reference.
532+
kwargs: Arbitrary keyword arguments for the status:
533+
Required:
534+
- state: pending, running, success, failed, canceled
535+
Optional:
536+
- description: short description of this status
537+
- name: label for this status e.g., name=ci/jenkins
538+
- ref: branch reference e.g., ref=master
539+
- target_url: hyperlink target for this status
540+
"""
541+
return ProjectCommitStatus._get_list_or_object(self, id, **kwargs)

gitlab/objects.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,21 @@ class ProjectCommitManager(BaseManager):
520520
obj_cls = ProjectCommit
521521

522522

523+
class ProjectCommitStatus(GitlabObject):
524+
_url = '/projects/%(project_id)s/statuses/%(commit_id)s'
525+
canUpdate = False
526+
canDelete = False
527+
requiredUrlAttrs = ['project_id', 'commit_id']
528+
requiredCreateAttrs = ['state']
529+
optionalCreateAttrs = ['description', 'name', 'ref', 'target_url']
530+
requiredGetAttrs = []
531+
requiredUpdateAttrs = []
532+
requiredDeleteAttrs = []
533+
534+
class ProjectCommitStatusManager(BaseManager):
535+
obj_cls = ProjectCommitStatus
536+
537+
523538
class ProjectKey(GitlabObject):
524539
_url = '/projects/%(project_id)s/keys'
525540
canUpdate = False
@@ -787,6 +802,7 @@ class Project(GitlabObject):
787802
managers = [
788803
('branches', ProjectBranchManager, [('project_id', 'id')]),
789804
('commits', ProjectCommitManager, [('project_id', 'id')]),
805+
('statuses', ProjectCommitStatusManager, [('project_id', 'id')]),
790806
('events', ProjectEventManager, [('project_id', 'id')]),
791807
('files', ProjectFileManager, [('project_id', 'id')]),
792808
('hooks', ProjectHookManager, [('project_id', 'id')]),

0 commit comments

Comments
 (0)