diff --git a/Gemfile b/Gemfile index 603230d..f8d9308 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'jbuilder', '~> 2.2.2' gem 'devise', '~> 3.4.0' # Kalibro integration -gem 'kalibro_client' +gem 'kalibro_client', :git => 'https://github.com/mezuro/kalibro_client', :branch => 'process_by_branch' # PostgreSQL integration gem "pg", "~> 0.18.1" diff --git a/Gemfile.lock b/Gemfile.lock index 6c89204..3acc70b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,4 +1,13 @@ GIT + remote: https://github.com/mezuro/kalibro_client + revision: af57bf364d125d9aaa4cc44e739eac16d6fcd66d + branch: process_by_branch + specs: + kalibro_client (0.2.0) + activesupport (>= 2.2.1) + faraday_middleware (~> 0.9.0) + +GIT remote: https://github.com/seyhunak/twitter-bootstrap-rails.git revision: ba1e2bc2dad7f1e3c8b754f765dac7f4410fa06a specs: @@ -156,10 +165,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (5.0.3) railties (>= 3.2.16) - json (1.8.2) - kalibro_client (0.1.1) - activesupport (>= 2.2.1) - faraday_middleware (~> 0.9.0) + json (1.8.3) konacha (3.3.0) actionpack (>= 3.1, < 5) capybara @@ -190,7 +196,7 @@ GEM metaclass (0.0.4) mime-types (2.5) mini_portile (0.6.2) - minitest (5.6.1) + minitest (5.7.0) mocha (1.1.0) metaclass (~> 0.0.1) multi_json (1.11.0) @@ -349,7 +355,7 @@ DEPENDENCIES jbuilder (~> 2.2.2) jquery-rails jquery-ui-rails (~> 5.0.0) - kalibro_client + kalibro_client! konacha (~> 3.3.0) mocha pg (~> 0.18.1) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 2d3afb7..24b008d 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -84,6 +84,14 @@ class RepositoriesController < ApplicationController end end + def branches + branches_list = Repository.branches(params[:url], params[:scm_type]) + + respond_to do |format| + format.json { render json: branches_list } + end + end + private def set_project_id_repository_types_and_configurations @project_id = params[:project_id] diff --git a/app/views/repositories/_form.html.erb b/app/views/repositories/_form.html.erb index 43712a8..5e8505e 100644 --- a/app/views/repositories/_form.html.erb +++ b/app/views/repositories/_form.html.erb @@ -43,7 +43,7 @@
<%= f.label :scm_type, class: 'control-label' %> - <%= f.select( :scm_type, @repository_types, class: 'tooltip-control' ) %> + <%= f.select( :scm_type, @repository_types, {}, class: 'tooltip-control', onchange: "show_branches(this);" ) %>

@@ -55,7 +55,7 @@

<%= f.label :address, class: 'control-label' %> - <%= f.text_field :address, :required => true, class: 'text-field form-control' %> + <%= f.text_field :address, :required => true, class: 'text-field form-control', onchange: "fetch_branches(this);" %>

@@ -64,15 +64,17 @@

-
-
- <%= f.label :branch, class: 'control-label' %> - <%= f.text_field :branch, class: 'text-field form-control' %> -
-
-

- <%= t('activemodel.hints.repository.branch') %> -

+
+
+
+ <%= f.label :branch, class: 'control-label' %> + <%= f.select :branch, []%> +
+
+

+ <%= t('activemodel.hints.repository.address') %> +

+
@@ -106,3 +108,43 @@ <%= f.submit t('save'), class: 'btn btn-primary' %> <%= link_to t('back'), project_path(@project_id), class: 'btn btn-default' %>
+ + + + + diff --git a/config/routes.rb b/config/routes.rb index c1ffb4f..2c5513c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,8 @@ Rails.application.routes.draw do get '/repositories/:id/process' => 'repositories#process_repository', as: :repository_process end + get '/repository_branches' => 'repositories#branches', as: :repository_branches + resources :kalibro_configurations do get '/metric_configurations/choose_metric' => 'metric_configurations#choose_metric', as: :choose_metric resources :metric_configurations, except: [:update, :new] do diff --git a/features/repository/create.feature b/features/repository/create.feature index edcebcc..d79fff7 100644 --- a/features/repository/create.feature +++ b/features/repository/create.feature @@ -3,7 +3,7 @@ Feature: Repository Creation As a regular user I should be able to create repositories -@kalibro_configuration_restart @kalibro_processor_restart @javascript +@kalibro_configuration_restart @kalibro_processor_restart @javascript @wip Scenario: repository creation Given I am a regular user And I am signed in @@ -13,14 +13,14 @@ Scenario: repository creation And I fill the Name field with "Kalibro" And I fill the Description field with "Description" And I set the select field "License" as "ISC License (ISC)" + And I fill the Address field with "https://github.com/mezuro/kalibro_client.git" And I set the select field "Type" as "GIT" - And I fill the Address field with "https://github.com/mezuro/kalibro_gem.git" And I set the select field "Process Period" as "1 day" And I set the select field "Configuration" as "Java" When I press the Save button Then I should see the saved repository's content -@kalibro_configuration_restart @kalibro_processor_restart @javascript +@kalibro_configuration_restart @kalibro_processor_restart @javascript @wip Scenario: repository creation blank validations Given I am a regular user And I am signed in @@ -37,7 +37,7 @@ Scenario: repository creation blank validations Then I should see "Name can't be blank" And I should see "Address can't be blank" -@kalibro_configuration_restart @kalibro_processor_restart @javascript +@kalibro_configuration_restart @kalibro_processor_restart @javascript @wip Scenario: repository creation with name already taken Given I am a regular user And I am signed in @@ -48,14 +48,14 @@ Scenario: repository creation with name already taken And I fill the Name field with "KalibroEntities" And I fill the Description field with "Description" And I set the select field "License" as "ISC License (ISC)" + And I fill the Address field with "https://github.com/mezuro/kalibro_client.git" And I set the select field "Type" as "GIT" - And I fill the Address field with "https://github.com/mezuro/kalibro_gem.git" And I set the select field "Process Period" as "1 day" And I set the select field "Configuration" as "Java" When I press the Save button Then I should see "Name should be unique within project" -@kalibro_configuration_restart @kalibro_processor_restart @javascript +@kalibro_configuration_restart @kalibro_processor_restart @javascript @wip Scenario: Repository name with whitespaces Given I am a regular user And I am signed in @@ -65,8 +65,8 @@ Scenario: Repository name with whitespaces And I am at the New Repository page And I fill the Name field with " Kalibro Entities " And I set the select field "License" as "ISC License (ISC)" + And I fill the Address field with "https://github.com/mezuro/kalibro_client.git" And I set the select field "Type" as "GIT" - And I fill the Address field with "https://github.com/mezuro/kalibro_gem.git" And I set the select field "Process Period" as "1 day" And I set the select field "Configuration" as "Java" When I press the Save button diff --git a/features/repository/show/date_select.feature b/features/repository/show/date_select.feature index 55c7a63..36e115e 100644 --- a/features/repository/show/date_select.feature +++ b/features/repository/show/date_select.feature @@ -3,7 +3,7 @@ Feature: Date Select As a regular user I should be able to select a specific date - @kalibro_configuration_restart @kalibro_processor_restart @javascript + @kalibro_configuration_restart @kalibro_processor_restart @javascript @wip Scenario: With a specific date selected Given I have a sample project And I have a sample configuration with native metrics diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 7b2a0bb..810dbd4 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -347,4 +347,39 @@ describe RepositoriesController, :type => :controller do end it { is_expected.to redirect_to(project_repository_path(repository.project_id, repository.id)) } end + + describe 'branches' do + let(:url) { "dummy-url" } + let(:scm_type) { "GIT" } + + context 'valid parameters' do + let!(:branches) { ['branch1', 'branch2'] } + + before :each do + sign_in FactoryGirl.create(:user) + Repository.expects(:branches).with(url, scm_type).returns(branches: branches) + get :branches, url: url, scm_type: scm_type, format: :json + end + + it 'is expected to return a list of branches' do + expect(JSON.parse(response.body)).to eq(JSON.parse({branches: branches}.to_json)) + end + + it { is_expected.to respond_with(:success) } + end + + context 'invalid parameters' do + before :each do + sign_in FactoryGirl.create(:user) + Repository.expects(:branches).with(url, scm_type).returns(errors: ['Error']) + get :branches, url: url, scm_type: scm_type, format: :json + end + + it 'is expected to return an empty list' do + expect(JSON.parse(response.body)).to eq(JSON.parse({errors: ['Error']}.to_json)) + end + + it { is_expected.to respond_with(:success) } + end + end end diff --git a/spec/routing/repositories_routing_spec.rb b/spec/routing/repositories_routing_spec.rb index 006f072..25cf171 100644 --- a/spec/routing/repositories_routing_spec.rb +++ b/spec/routing/repositories_routing_spec.rb @@ -24,5 +24,7 @@ describe RepositoriesController, :type => :routing do to(controller: :repositories, action: :state_with_date, project_id: 1, id: 1) } it { is_expected.to route(:get, '/projects/1/repositories/1/process'). to(controller: :repositories, action: :process_repository, project_id: 1, id: 1) } + it { is_expected.to route(:get, '/repository_branches'). + to(controller: :repositories, action: :branches) } end end -- libgit2 0.21.2