From 8f3ed58cd8e3641975af1d884b441beae2093a14 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 11 Oct 2012 20:27:17 +0400 Subject: [PATCH] #671: added Projects#refs_list API action --- app/controllers/api/v1/projects_controller.rb | 7 +++++-- app/views/api/v1/projects/refs_list.json.jbuilder | 8 ++++++++ config/routes.rb | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 app/views/api/v1/projects/refs_list.json.jbuilder diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 2345e4214..7f9182563 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -2,7 +2,7 @@ class Api::V1::ProjectsController < Api::V1::BaseController before_filter :authenticate_user! - skip_before_filter :authenticate_user!, :only => [:get_id, :show] if APP_CONFIG['anonymous_access'] + skip_before_filter :authenticate_user!, :only => [:get_id, :show, :refs] if APP_CONFIG['anonymous_access'] load_and_authorize_resource @@ -15,6 +15,9 @@ class Api::V1::ProjectsController < Api::V1::BaseController end def show - end + + def refs_list + end + end diff --git a/app/views/api/v1/projects/refs_list.json.jbuilder b/app/views/api/v1/projects/refs_list.json.jbuilder new file mode 100644 index 000000000..7b913f98b --- /dev/null +++ b/app/views/api/v1/projects/refs_list.json.jbuilder @@ -0,0 +1,8 @@ +json.refs_list (@project.repo.branches + @project.repo.tags) do |json_grit, grit| + json_grit.ref grit.name + json_grit.object do |json_object| + json_object.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit') + json_object.sha grit.commit.id + end +end +json.url refs_list_api_v1_project_path(@project.id, :format => :json) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 03034a36e..9e9038b08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,9 @@ Rosa::Application.routes.draw do resources :repositories, :only => [:show] resources :projects, :only => [:show] do collection { get :get_id } + member { + get :refs_list + } end end end