| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 19242c3 commit 5298964
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,6 +72,10 @@ Cherry-pick a commit into another branch:: | |||
| 72 | 72 | ||
| 73 | 73 | commit.cherry_pick(branch='target_branch') | |
| 74 | 74 | ||
| 75 | + Revert a commit on a given branch:: | ||
| 76 | + | ||
| 77 | + commit.revert(branch='target_branch') | ||
| 78 | + | ||
| 75 | 79 | Get the references the commit has been pushed to (branches and tags):: | |
| 76 | 80 | ||
| 77 | 81 | commit.refs() # all references | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,6 +245,10 @@ class GitlabRepairError(GitlabOperationError): | |||
| 245 | 245 | pass | |
| 246 | 246 | ||
| 247 | 247 | ||
| 248 | + class GitlabRevertError(GitlabOperationError): | ||
| 249 | + pass | ||
| 250 | + | ||
| 251 | + | ||
| 248 | 252 | class GitlabLicenseError(GitlabOperationError): | |
| 249 | 253 | pass | |
| 250 | 254 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2136,6 +2136,22 @@ def merge_requests(self, **kwargs): | |||
| 2136 | 2136 | path = "%s/%s/merge_requests" % (self.manager.path, self.get_id()) | |
| 2137 | 2137 | return self.manager.gitlab.http_get(path, **kwargs) | |
| 2138 | 2138 | ||
| 2139 | + @cli.register_custom_action("ProjectCommit", ("branch",)) | ||
| 2140 | + @exc.on_http_error(exc.GitlabRevertError) | ||
| 2141 | + def revert(self, branch, **kwargs): | ||
| 2142 | + """Revert a commit on a given branch. | ||
| 2143 | + | ||
| 2144 | + Args: | ||
| 2145 | + branch (str): Name of target branch | ||
| 2146 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 2147 | + | ||
| 2148 | + Raises: | ||
| 2149 | + GitlabAuthenticationError: If authentication is not correct | ||
| 2150 | + GitlabRevertError: If the revert could not be performed | ||
| 2151 | + """ | ||
| 2152 | + path = "%s/%s/revert" % (self.manager.path, self.get_id()) | ||
| 2153 | + post_data = {"branch": branch} | ||
| 2154 | + self.manager.gitlab.http_post(path, post_data=post_data, **kwargs) | ||
| 2139 | 2155 | ||
| 2140 | 2156 | class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager): | |
| 2141 | 2157 | _path = "/projects/%(project_id)s/repository/commits" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,15 @@ testcase "merge request validation" ' | |||
| 100 | 100 | --iid "$MR_ID" >/dev/null 2>&1 | |
| 101 | 101 | ' | |
| 102 | 102 | ||
| 103 | + # Test revert commit | ||
| 104 | + COMMITS=$(GITLAB -v project-commit list --project-id "${PROJECT_ID}") | ||
| 105 | + COMMIT_ID=$(pecho "${COMMITS}" | grep -m1 '^id:' | cut -d' ' -f2) | ||
| 106 | + | ||
| 107 | + testcase "revert commit" ' | ||
| 108 | + GITLAB project-commit revert --project-id "$PROJECT_ID" \ | ||
| 109 | + --id "$COMMIT_ID" --branch master | ||
| 110 | + ' | ||
| 111 | + | ||
| 103 | 112 | # Test project labels | |
| 104 | 113 | testcase "create project label" ' | |
| 105 | 114 | OUTPUT=$(GITLAB -v project-label create --project-id $PROJECT_ID \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -462,6 +462,21 @@ | |||
| 462 | 462 | discussion = commit.discussions.get(discussion.id) | |
| 463 | 463 | # assert len(discussion.attributes["notes"]) == 1 | |
| 464 | 464 | ||
| 465 | + # Revert commit | ||
| 466 | + commit.revert(branch="master") | ||
| 467 | + revert_commit = admin_project.commits.list()[0] | ||
| 468 | + | ||
| 469 | + expected_message = "Revert \"{}\"\n\nThis reverts commit {}".format( | ||
| 470 | + commit.message, commit.id) | ||
| 471 | + assert revert_commit.message == expected_message | ||
| 472 | + | ||
| 473 | + try: | ||
| 474 | + commit.revert(branch="master") | ||
| 475 | + # Only here to really ensure expected error without a full test framework | ||
| 476 | + raise AssertionError("Two revert attempts should raise GitlabRevertError") | ||
| 477 | + except gitlab.GitlabRevertError: | ||
| 478 | + pass | ||
| 479 | + | ||
| 465 | 480 | # housekeeping | |
| 466 | 481 | admin_project.housekeeping() | |
| 467 | 482 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments