| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,10 @@ | |||
| 39 | 39 | diff = commit.diff() | |
| 40 | 40 | # end diff | |
| 41 | 41 | ||
| 42 | + # cherry | ||
| 43 | + commit.cherry_pick(branch='target_branch') | ||
| 44 | + # end cherry | ||
| 45 | + | ||
| 42 | 46 | # comments list | |
| 43 | 47 | comments = gl.project_commit_comments.list(project_id=1, commit_id='master') | |
| 44 | 48 | # or | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,12 @@ Get the diff for a commit: | |||
| 43 | 43 | :start-after: # diff | |
| 44 | 44 | :end-before: # end diff | |
| 45 | 45 | ||
| 46 | + Cherry-pick a commit into another branch: | ||
| 47 | + | ||
| 48 | + .. literalinclude:: commits.py | ||
| 49 | + :start-after: # cherry | ||
| 50 | + :end-before: # end cherry | ||
| 51 | + | ||
| 46 | 52 | Commit comments | |
| 47 | 53 | =============== | |
| 48 | 54 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,9 @@ | |||
| 42 | 42 | gitlab.ProjectCommit: {'diff': {'required': ['id', 'project-id']}, | |
| 43 | 43 | 'blob': {'required': ['id', 'project-id', | |
| 44 | 44 | 'filepath']}, | |
| 45 | - 'builds': {'required': ['id', 'project-id']}}, | ||
| 45 | + 'builds': {'required': ['id', 'project-id']}, | ||
| 46 | + 'cherrypick': {'required': ['id', 'project-id', | ||
| 47 | + 'branch']}}, | ||
| 46 | 48 | gitlab.ProjectIssue: {'subscribe': {'required': ['id', 'project-id']}, | |
| 47 | 49 | 'unsubscribe': {'required': ['id', 'project-id']}, | |
| 48 | 50 | 'move': {'required': ['id', 'project-id', | |
@@ -267,6 +269,13 @@ def do_project_commit_builds(self, cls, gl, what, args): | |||
| 267 | 269 | except Exception as e: | |
| 268 | 270 | _die("Impossible to get commit builds", e) | |
| 269 | 271 | ||
| 272 | + def do_project_commit_cherrypick(self, cls, gl, what, args): | ||
| 273 | + try: | ||
| 274 | + o = self.do_get(cls, gl, what, args) | ||
| 275 | + o.cherry_pick(branch=args['branch']) | ||
| 276 | + except Exception as e: | ||
| 277 | + _die("Impossible to cherry-pick commit", e) | ||
| 278 | + | ||
| 270 | 279 | def do_project_build_cancel(self, cls, gl, what, args): | |
| 271 | 280 | try: | |
| 272 | 281 | o = self.do_get(cls, gl, what, args) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,6 +147,10 @@ class GitlabTimeTrackingError(GitlabOperationError): | |||
| 147 | 147 | pass | |
| 148 | 148 | ||
| 149 | 149 | ||
| 150 | + class GitlabCherryPickError(GitlabOperationError): | ||
| 151 | + pass | ||
| 152 | + | ||
| 153 | + | ||
| 150 | 154 | def raise_error_from_response(response, error, expected_code=200): | |
| 151 | 155 | """Tries to parse gitlab error message from response and raises error. | |
| 152 | 156 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1158,7 +1158,7 @@ class ProjectBranch(GitlabObject): | |||
| 1158 | 1158 | requiredCreateAttrs = ['branch_name', 'ref'] | |
| 1159 | 1159 | ||
| 1160 | 1160 | def protect(self, protect=True, **kwargs): | |
| 1161 | - """Protects the project.""" | ||
| 1161 | + """Protects the branch.""" | ||
| 1162 | 1162 | url = self._url % {'project_id': self.project_id} | |
| 1163 | 1163 | action = 'protect' if protect else 'unprotect' | |
| 1164 | 1164 | url = "%s/%s/%s" % (url, self.name, action) | |
@@ -1171,7 +1171,7 @@ def protect(self, protect=True, **kwargs): | |||
| 1171 | 1171 | del self.protected | |
| 1172 | 1172 | ||
| 1173 | 1173 | def unprotect(self, **kwargs): | |
| 1174 | - """Unprotects the project.""" | ||
| 1174 | + """Unprotects the branch.""" | ||
| 1175 | 1175 | self.protect(False, **kwargs) | |
| 1176 | 1176 | ||
| 1177 | 1177 | ||
@@ -1374,6 +1374,23 @@ def builds(self, **kwargs): | |||
| 1374 | 1374 | {'project_id': self.project_id}, | |
| 1375 | 1375 | **kwargs) | |
| 1376 | 1376 | ||
| 1377 | + def cherry_pick(self, branch, **kwargs): | ||
| 1378 | + """Cherry-pick a commit into a branch. | ||
| 1379 | + | ||
| 1380 | + Args: | ||
| 1381 | + branch (str): Name of target branch. | ||
| 1382 | + | ||
| 1383 | + Raises: | ||
| 1384 | + GitlabCherryPickError: If the cherry pick could not be applied. | ||
| 1385 | + """ | ||
| 1386 | + url = ('/projects/%s/repository/commits/%s/cherry_pick' % | ||
| 1387 | + (self.project_id, self.id)) | ||
| 1388 | + | ||
| 1389 | + r = self.gitlab._raw_post(url, data={'project_id': self.project_id, | ||
| 1390 | + 'branch': branch}, **kwargs) | ||
| 1391 | + errors = {400: GitlabCherryPickError} | ||
| 1392 | + raise_error_from_response(r, errors, expected_code=201) | ||
| 1393 | + | ||
| 1377 | 1394 | ||
| 1378 | 1395 | class ProjectCommitManager(BaseManager): | |
| 1379 | 1396 | obj_cls = ProjectCommit | |
| Back | FazBrowse Home | New Git URL |
0 commit comments