From cea2a8f741d623ca2085e8149112de3a20a4779f Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 24 Oct 2017 13:28:06 +0300 Subject: Basic ref fetching for commits --- lib/api/commits.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/api/commits.rb') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index d8fd6a6eb06..3cf88551fa7 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -156,6 +156,31 @@ module API end end + desc 'Get all reference a commit is pushed to' do + detail 'This feature was introduced in GitLab 10.6' + success Entities::SimpleRef + end + params do + requires :sha, type: String, desc: 'A commit sha' + optional :type, type: String, values: %w(branches tags all), default: 'all', desc: 'Scope' + end + get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + commit = user_project.commit(params[:sha]) + not_found!('Commit') unless commit + + case params[:type] + when 'branches' + refs = user_project.repository.branch_names_contains(commit.id) + when 'tags' + refs = user_project.repository.tag_names_contains(commit.id) + else + refs = user_project.repository.branch_names_contains(commit.id) + refs.push(*user_project.repository.tag_names_contains(commit.id)) + end + + present refs, with: Entities::SimpleRef + end + desc 'Post comment to commit' do success Entities::CommitNote end -- cgit v1.2.1 From 4cefb568d96c4868404caa14534a4329e2dd887f Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 9 Feb 2018 14:30:27 +0100 Subject: Incorporate feedback --- lib/api/commits.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'lib/api/commits.rb') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 3cf88551fa7..6d845253c3a 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -156,29 +156,30 @@ module API end end - desc 'Get all reference a commit is pushed to' do + desc 'Get all references a commit is pushed to' do detail 'This feature was introduced in GitLab 10.6' - success Entities::SimpleRef + success Entities::BasicRef end params do requires :sha, type: String, desc: 'A commit sha' - optional :type, type: String, values: %w(branches tags all), default: 'all', desc: 'Scope' + optional :type, type: String, values: %w[branches tags all], default: 'all', desc: 'Scope' end get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) not_found!('Commit') unless commit - case params[:type] - when 'branches' - refs = user_project.repository.branch_names_contains(commit.id) - when 'tags' - refs = user_project.repository.tag_names_contains(commit.id) - else - refs = user_project.repository.branch_names_contains(commit.id) - refs.push(*user_project.repository.tag_names_contains(commit.id)) - end + refs = + case params[:type] + when 'branches' + user_project.repository.branch_names_contains(commit.id) + when 'tags' + user_project.repository.tag_names_contains(commit.id) + else + refs = user_project.repository.branch_names_contains(commit.id) + refs.concat(user_project.repository.tag_names_contains(commit.id)) + end - present refs, with: Entities::SimpleRef + present refs, with: Entities::BasicRef end desc 'Post comment to commit' do @@ -190,7 +191,7 @@ module API optional :path, type: String, desc: 'The file path' given :path do requires :line, type: Integer, desc: 'The line number' - requires :line_type, type: String, values: %w(new old), default: 'new', desc: 'The type of the line' + requires :line_type, type: String, values: %w[new old], default: 'new', desc: 'The type of the line' end end post ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do -- cgit v1.2.1 From 922d156a5e0412a12662df94e03479f7ed015f7b Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 9 Feb 2018 17:46:41 +0100 Subject: Separate branch and tag names --- lib/api/commits.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/api/commits.rb') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 6d845253c3a..afaf68114e8 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -171,12 +171,12 @@ module API refs = case params[:type] when 'branches' - user_project.repository.branch_names_contains(commit.id) + user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]} when 'tags' - user_project.repository.tag_names_contains(commit.id) + user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]} else - refs = user_project.repository.branch_names_contains(commit.id) - refs.concat(user_project.repository.tag_names_contains(commit.id)) + refs = user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]} + refs.concat(user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]}) end present refs, with: Entities::BasicRef -- cgit v1.2.1 From a724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 13 Feb 2018 20:22:37 +0100 Subject: Refactor commits/refs API to use hash and add pagination headers --- lib/api/commits.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'lib/api/commits.rb') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index afaf68114e8..d83c43ee49b 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -162,24 +162,19 @@ module API end params do requires :sha, type: String, desc: 'A commit sha' - optional :type, type: String, values: %w[branches tags all], default: 'all', desc: 'Scope' + optional :type, type: String, values: %w[branch tag all], default: 'all', desc: 'Scope' + use :pagination end get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) not_found!('Commit') unless commit - refs = - case params[:type] - when 'branches' - user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]} - when 'tags' - user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]} - else - refs = user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]} - refs.concat(user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]}) - end + refs = [] + refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| { type: 'branch', name: name }}) unless params[:type] == 'tag' + refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| { type: 'tag', name: name }}) unless params[:type] == 'branch' + refs = Kaminari.paginate_array(refs) - present refs, with: Entities::BasicRef + present paginate(refs), with: Entities::BasicRef end desc 'Post comment to commit' do -- cgit v1.2.1