Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Provide API wrapper for cherry picking commits#236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpocentek merged 8 commits intopython-gitlab:masterfromcgumpert:cherry_pick_commit
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionsdocs/gl_objects/commits.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,10 @@
diff = commit.diff()
# end diff

# cherry
commit.cherry_pick(branch='target_branch')
# end cherry

# comments list
comments = gl.project_commit_comments.list(project_id=1, commit_id='master')
# or
Expand Down
6 changes: 6 additions & 0 deletionsdocs/gl_objects/commits.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,12 @@ Get the diff for a commit:
:start-after: # diff
:end-before: # end diff

Cherry-pick a commit into another branch:

.. literalinclude:: commits.py
:start-after: # cherry
:end-before: # end cherry

Commit comments
===============

Expand Down
11 changes: 10 additions & 1 deletiongitlab/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,9 @@
gitlab.ProjectCommit: {'diff': {'required': ['id', 'project-id']},
'blob': {'required': ['id', 'project-id',
'filepath']},
'builds': {'required': ['id', 'project-id']}},
'builds': {'required': ['id', 'project-id']},
'cherrypick': {'required': ['id', 'project-id',
'branch']}},
gitlab.ProjectIssue: {'subscribe': {'required': ['id', 'project-id']},
'unsubscribe': {'required': ['id', 'project-id']},
'move': {'required': ['id', 'project-id',
Expand DownExpand Up@@ -267,6 +269,13 @@ def do_project_commit_builds(self, cls, gl, what, args):
except Exception as e:
_die("Impossible to get commit builds", e)

def do_project_commit_cherrypick(self, cls, gl, what, args):
try:
o = self.do_get(cls, gl, what, args)
o.cherry_pick(branch=args['branch'])
except Exception as e:
_die("Impossible to cherry-pick commit", e)

def do_project_build_cancel(self, cls, gl, what, args):
try:
o = self.do_get(cls, gl, what, args)
Expand Down
4 changes: 4 additions & 0 deletionsgitlab/exceptions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -147,6 +147,10 @@ class GitlabTimeTrackingError(GitlabOperationError):
pass


class GitlabCherryPickError(GitlabOperationError):
pass


def raise_error_from_response(response, error, expected_code=200):
"""Tries to parse gitlab error message from response and raises error.

Expand Down
21 changes: 19 additions & 2 deletionsgitlab/objects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1137,7 +1137,7 @@ class ProjectBranch(GitlabObject):
requiredCreateAttrs = ['branch_name', 'ref']

def protect(self, protect=True, **kwargs):
"""Protects theproject."""
"""Protects thebranch."""
url = self._url % {'project_id': self.project_id}
action = 'protect' if protect else 'unprotect'
url = "%s/%s/%s" % (url, self.name, action)
Expand All@@ -1150,7 +1150,7 @@ def protect(self, protect=True, **kwargs):
del self.protected

def unprotect(self, **kwargs):
"""Unprotects theproject."""
"""Unprotects thebranch."""
self.protect(False, **kwargs)


Expand DownExpand Up@@ -1353,6 +1353,23 @@ def builds(self, **kwargs):
{'project_id': self.project_id},
**kwargs)

def cherry_pick(self, branch, **kwargs):
"""Cherry-pick a commit into a branch.

Args:
branch (str): Name of target branch.

Raises:
GitlabCherryPickError: If the cherry pick could not be applied.
"""
url = ('/projects/%s/repository/commits/%s/cherry_pick' %
(self.project_id, self.id))

r = self.gitlab._raw_post(url, data={'project_id': self.project_id,
'branch': branch}, **kwargs)
errors = {400: GitlabCherryPickError}
raise_error_from_response(r, errors, expected_code=201)


class ProjectCommitManager(BaseManager):
obj_cls = ProjectCommit
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp