summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-07-29 11:41:44 +0000
committerNick Thomas <nick@gitlab.com>2019-07-29 11:41:44 +0000
commit3bb3ac3d53398a8e2e5d2de95ee2a226db84efe2 (patch)
tree5dda2df5ffd753e56cf935f335e8048bce8a3ef1 /lib/api
parentca05130319ae9d74ee7771b5a8adb6cf25857fb7 (diff)
parent5a8eaef42e771e9de6f6cbce715877352807f53c (diff)
downloadgitlab-ce-3bb3ac3d53398a8e2e5d2de95ee2a226db84efe2.tar.gz
Merge branch 'add-git-blame-api' into 'master'
Expose git blame in api Closes #51345 See merge request gitlab-org/gitlab-ce!30675
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb13
-rw-r--r--lib/api/files.rb25
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 2e78331df6c..2d6dd18d4ea 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -2,6 +2,19 @@
module API
module Entities
+ class BlameRangeCommit < Grape::Entity
+ expose :id
+ expose :parent_ids
+ expose :message
+ expose :authored_date, :author_name, :author_email
+ expose :committed_date, :committer_name, :committer_email
+ end
+
+ class BlameRange < Grape::Entity
+ expose :commit, using: BlameRangeCommit
+ expose :lines
+ end
+
class WikiPageBasic < Grape::Entity
expose :format
expose :slug
diff --git a/lib/api/files.rb b/lib/api/files.rb
index ca59d330e1c..0b438fb5bbc 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -83,6 +83,31 @@ module API
resource :projects, requirements: FILE_ENDPOINT_REQUIREMENTS do
allow_access_with_scope :read_repository, if: -> (request) { request.get? || request.head? }
+ desc 'Get blame file metadata from repository'
+ params do
+ requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
+ requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false
+ end
+ head ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do
+ assign_file_vars!
+
+ set_http_headers(blob_data)
+ end
+
+ desc 'Get blame file from the repository'
+ params do
+ requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
+ requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false
+ end
+ get ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do
+ assign_file_vars!
+
+ set_http_headers(blob_data)
+
+ blame_ranges = Gitlab::Blame.new(@blob, @commit).groups(highlight: false)
+ present blame_ranges, with: Entities::BlameRange
+ end
+
desc 'Get raw file metadata from repository'
params do
requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'