diff options
author | Vincent Lae <vincent.lae@gmail.com> | 2019-10-04 22:11:49 +0200 |
---|---|---|
committer | Vincent Lae <vincent.lae@gmail.com> | 2019-10-04 22:26:24 +0200 |
commit | f5b4a113a298d33cb72f80c94d85bdfec3c4e149 (patch) | |
tree | 02b5043610b2ff15e5c3db38b88efc4c568b8f28 | |
parent | ba2b60e32c12cacf18762a286d05e073529b9898 (diff) | |
download | gitlab-f5b4a113a298d33cb72f80c94d85bdfec3c4e149.tar.gz |
feat(project): add file blame api
https://docs.gitlab.com/ee/api/repository_files.html#get-file-blame-from-repository
-rw-r--r-- | docs/gl_objects/projects.rst | 4 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 22 | ||||
-rw-r--r-- | tools/python_test_v4.py | 2 |
3 files changed, 28 insertions, 0 deletions
diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst index ff297cc..85e5cb9 100644 --- a/docs/gl_objects/projects.rst +++ b/docs/gl_objects/projects.rst @@ -362,6 +362,10 @@ Delete a file:: f.delete(commit_message='Delete testfile') +Get file blame:: + + b = project.files.blame(file_path='README.rst', ref='master') + Project tags ============ diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 9f1918b..15aecf5 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3211,6 +3211,28 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa ) return utils.response_content(result, streamed, action, chunk_size) + @cli.register_custom_action("ProjectFileManager", ("file_path", "ref")) + @exc.on_http_error(exc.GitlabListError) + def blame(self, file_path, ref, **kwargs): + """Return the content of a file for a commit. + + Args: + file_path (str): Path of the file to retrieve + ref (str): Name of the branch, tag or commit + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabListError: If the server failed to perform the request + + Returns: + list(blame): a list of commits/lines matching the file + """ + file_path = file_path.replace("/", "%2F").replace(".", "%2E") + path = "%s/%s/blame" % (self.path, file_path) + query_data = {"ref": ref} + return self.gitlab.http_list(path, query_data, **kwargs) + class ProjectPipelineJob(RESTObject): pass diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index a27d854..9085f6f 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -423,6 +423,8 @@ readme = admin_project.files.get(file_path="README.rst", ref="master") # object method assert readme.decode().decode() == "Initial content" +blame = admin_project.files.blame(file_path="README.rst", ref="master") + data = { "branch": "master", "commit_message": "blah blah blah", |