From d21b3a0211061a2fed5949e92320f100ab3df05b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Mar 2016 14:16:21 +0100 Subject: [PATCH 1/7] Add links to CI setup documentation from project settings and builds pages Signed-off-by: Dmitriy Zaporozhets --- CHANGELOG | 1 + app/views/projects/_builds_settings.html.haml | 8 ++++++++ app/views/projects/builds/index.html.haml | 3 +++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d9be95defd1a..c5b316c66b23 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ v 8.7.0 (unreleased) - Preserve time notes/comments have been updated at when moving issue - Make HTTP(s) label consistent on clone bar (Stan Hu) - Fix avatar stretching by providing a cropping feature + - Add links to CI setup documentation from project settings and builds pages v 8.6.1 - Add option to reload the schema before restoring a database backup. !2807 diff --git a/app/views/projects/_builds_settings.html.haml b/app/views/projects/_builds_settings.html.haml index 95ab9ecf3e84..f1edc800bbf4 100644 --- a/app/views/projects/_builds_settings.html.haml +++ b/app/views/projects/_builds_settings.html.haml @@ -1,6 +1,14 @@ %fieldset.builds-feature %legend Builds: + + - unless @project.builds.any? + .form-group + .col-sm-offset-2.col-sm-10 + %p Before you can use Builds (Continuous Integration) feature you need to setup it. + = link_to 'Get started with Builds', help_page_path('ci/quick_start', 'README'), class: 'btn btn-info' + %hr + .form-group .col-sm-offset-2.col-sm-10 %p Get recent application code using the following command: diff --git a/app/views/projects/builds/index.html.haml b/app/views/projects/builds/index.html.haml index 811d304ea753..d21716e48874 100644 --- a/app/views/projects/builds/index.html.haml +++ b/app/views/projects/builds/index.html.haml @@ -27,6 +27,9 @@ = link_to 'Cancel running', cancel_all_namespace_project_builds_path(@project.namespace, @project), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :post + - unless @project.builds.any? + = link_to 'Get started with Builds', help_page_path('ci/quick_start', 'README'), class: 'btn btn-info' + = link_to ci_lint_path, class: 'btn btn-default' do = icon('wrench') %span CI Lint -- GitLab From 3b1543cd15fcc52c2f5f3b7f4ccf391334fb6028 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Mar 2016 15:17:13 +0100 Subject: [PATCH 2/7] Detect build setup state based on gitlab_ci.yml presense Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 4 ++++ app/views/projects/_builds_settings.html.haml | 2 +- app/views/projects/builds/index.html.haml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 13154eb42058..f874017a8f29 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -467,6 +467,10 @@ def license end end + def gitlab_ci_yml + @gitlab_ci_yml ||= blob_at(head_commit.sha, '.gitlab-ci.yml') unless empty? + end + def head_commit @head_commit ||= commit(self.root_ref) end diff --git a/app/views/projects/_builds_settings.html.haml b/app/views/projects/_builds_settings.html.haml index f1edc800bbf4..095e7e45df7e 100644 --- a/app/views/projects/_builds_settings.html.haml +++ b/app/views/projects/_builds_settings.html.haml @@ -2,7 +2,7 @@ %legend Builds: - - unless @project.builds.any? + - unless @repository.gitlab_ci_yml .form-group .col-sm-offset-2.col-sm-10 %p Before you can use Builds (Continuous Integration) feature you need to setup it. diff --git a/app/views/projects/builds/index.html.haml b/app/views/projects/builds/index.html.haml index d21716e48874..aa85f495e396 100644 --- a/app/views/projects/builds/index.html.haml +++ b/app/views/projects/builds/index.html.haml @@ -27,7 +27,7 @@ = link_to 'Cancel running', cancel_all_namespace_project_builds_path(@project.namespace, @project), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :post - - unless @project.builds.any? + - unless @repository.gitlab_ci_yml = link_to 'Get started with Builds', help_page_path('ci/quick_start', 'README'), class: 'btn btn-info' = link_to ci_lint_path, class: 'btn btn-default' do -- GitLab From b105b84e3ac34915cf00b7bfec923abf98d035ab Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Mar 2016 15:35:49 +0100 Subject: [PATCH 3/7] Use head tree (cached) for file search. Also add some tests Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 6 +++++- spec/models/repository_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index f874017a8f29..e36c6ab0f0a7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -468,7 +468,11 @@ def license end def gitlab_ci_yml - @gitlab_ci_yml ||= blob_at(head_commit.sha, '.gitlab-ci.yml') unless empty? + return nil if empty? + + @gitlab_ci_yml ||= tree(:head).blobs.find do |file| + file.name == '.gitlab-ci.yml' + end end def head_commit diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 7eac70ae9480..0ba9da29a971 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -148,6 +148,29 @@ end end + describe "#gitlab_ci_yml" do + before do + TestBlob = Struct.new(:name) + end + + it 'returns valid file' do + files = [TestBlob.new('file'), TestBlob.new('.gitlab-ci.yml'), TestBlob.new('copying')] + expect(repository.tree).to receive(:blobs).and_return(files) + + expect(repository.gitlab_ci_yml.name).to eq('.gitlab-ci.yml') + end + + it 'returns nil if not exists' do + expect(repository.tree).to receive(:blobs).and_return([]) + expect(repository.gitlab_ci_yml).to be_nil + end + + it 'returns nil for empty repository' do + expect(repository).to receive(:empty?).and_return(true) + expect(repository.gitlab_ci_yml).to be_nil + end + end + describe :add_branch do context 'when pre hooks were successful' do it 'should run without errors' do -- GitLab From 9e7e2c6b9d2e46720c0375b6c44a2fb5e0f7acbe Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 25 Mar 2016 13:18:55 +0100 Subject: [PATCH 4/7] Small refactoring and rewording Signed-off-by: Dmitriy Zaporozhets --- app/views/projects/_builds_settings.html.haml | 2 +- spec/models/repository_spec.rb | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/views/projects/_builds_settings.html.haml b/app/views/projects/_builds_settings.html.haml index 095e7e45df7e..9ae6964aaac0 100644 --- a/app/views/projects/_builds_settings.html.haml +++ b/app/views/projects/_builds_settings.html.haml @@ -5,7 +5,7 @@ - unless @repository.gitlab_ci_yml .form-group .col-sm-offset-2.col-sm-10 - %p Before you can use Builds (Continuous Integration) feature you need to setup it. + %p Builds need to be configured before you can begin using Continuous Integration. = link_to 'Get started with Builds', help_page_path('ci/quick_start', 'README'), class: 'btn btn-info' %hr diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 0ba9da29a971..417f11acca4f 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2,6 +2,7 @@ describe Repository, models: true do include RepoHelpers + TestBlob = Struct.new(:name) let(:repository) { create(:project).repository } let(:user) { create(:user) } @@ -131,7 +132,6 @@ describe "#license" do before do repository.send(:cache).expire(:license) - TestBlob = Struct.new(:name) end it 'test selection preference' do @@ -149,10 +149,6 @@ end describe "#gitlab_ci_yml" do - before do - TestBlob = Struct.new(:name) - end - it 'returns valid file' do files = [TestBlob.new('file'), TestBlob.new('.gitlab-ci.yml'), TestBlob.new('copying')] expect(repository.tree).to receive(:blobs).and_return(files) -- GitLab From ed8e1faa4c72e138f3a75139fa216873a8b67850 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 25 Mar 2016 14:19:20 +0100 Subject: [PATCH 5/7] Make sure Repository#gitlab_ci_yml is safe to use even when repository is missing Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index e36c6ab0f0a7..0a9cc364b770 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -468,7 +468,7 @@ def license end def gitlab_ci_yml - return nil if empty? + return nil if !exists? || empty? @gitlab_ci_yml ||= tree(:head).blobs.find do |file| file.name == '.gitlab-ci.yml' -- GitLab From 3dc0c3e473a68056c237de3d31415c8034ba1e52 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 25 Mar 2016 16:19:24 +0100 Subject: [PATCH 6/7] For some reason this test fails without javascript so added it Signed-off-by: Dmitriy Zaporozhets --- features/project/project.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/project/project.feature b/features/project/project.feature index f1f3ed26065e..6cca0591eaf8 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -52,6 +52,7 @@ Feature: Project And I save project Then I should see project with new settings + @javascript Scenario: I change project path When I visit edit project "Shop" page And change project path settings -- GitLab From 179bae9968e6da5c09a1789fba7c4b706e144804 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 25 Mar 2016 17:54:57 +0100 Subject: [PATCH 7/7] rescue Rugged::ReferenceError in Repository#gitlab_ci_yml method Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 4 ++++ features/project/project.feature | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 0a9cc364b770..908d765fb47d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -473,6 +473,10 @@ def gitlab_ci_yml @gitlab_ci_yml ||= tree(:head).blobs.find do |file| file.name == '.gitlab-ci.yml' end + rescue Rugged::ReferenceError + # For unknow reason spinach scenario "Scenario: I change project path" + # lead to "Reference 'HEAD' not found" exception from Repository#empty? + nil end def head_commit diff --git a/features/project/project.feature b/features/project/project.feature index 6cca0591eaf8..f1f3ed26065e 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -52,7 +52,6 @@ Feature: Project And I save project Then I should see project with new settings - @javascript Scenario: I change project path When I visit edit project "Shop" page And change project path settings -- GitLab