diff options
author | Robert Speicher <robert@gitlab.com> | 2018-05-09 22:20:01 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-05-09 22:20:01 +0300 |
commit | 149e91b50ea6944577a1392d487334854ec58012 (patch) | |
tree | e2068cf3ede6bca31dfb8a07199098aa5cf34a48 | |
parent | 846a80eba178e155c5ab1def1f36e778b7eab837 (diff) | |
parent | f6ecb72682000f7261219bbb6ce1ca9352aa473e (diff) |
Merge branch 'dm-repository-xcode-project' into 'master'
Add Repository#xcode_project? method
See merge request gitlab-org/gitlab-ce!18854
-rw-r--r-- | app/models/repository.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/file_detector.rb | 1 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 33 |
3 files changed, 41 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index b75c4aca982..44c6bff6b66 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -37,7 +37,7 @@ class Repository changelog license_blob license_key gitignore koding_yml gitlab_ci_yml branch_names tag_names branch_count tag_count avatar exists? root_ref has_visible_content? - issue_template_names merge_request_template_names).freeze + issue_template_names merge_request_template_names xcode_project?).freeze # Methods that use cache_method but only memoize the value MEMOIZED_CACHED_METHODS = %i(license).freeze @@ -55,7 +55,8 @@ class Repository gitlab_ci: :gitlab_ci_yml, avatar: :avatar, issue_template: :issue_template_names, - merge_request_template: :merge_request_template_names + merge_request_template: :merge_request_template_names, + xcode_config: :xcode_project? }.freeze def initialize(full_path, project, disk_path: nil, is_wiki: false) @@ -594,6 +595,11 @@ class Repository end cache_method :gitlab_ci_yml + def xcode_project? + file_on_head(:xcode_config).present? + end + cache_method :xcode_project? + def head_commit @head_commit ||= commit(self.root_ref) end diff --git a/lib/gitlab/file_detector.rb b/lib/gitlab/file_detector.rb index cc2638172ec..77af7a868d0 100644 --- a/lib/gitlab/file_detector.rb +++ b/lib/gitlab/file_detector.rb @@ -14,6 +14,7 @@ module Gitlab avatar: /\Alogo\.(png|jpg|gif)\z/, issue_template: %r{\A\.gitlab/issue_templates/[^/]+\.md\z}, merge_request_template: %r{\A\.gitlab/merge_request_templates/[^/]+\.md\z}, + xcode_config: %r{\A[^/]*\.(xcodeproj|xcworkspace)\z}, # Configuration files gitignore: '.gitignore', diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 4b736b02b7d..a7755a505d8 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1733,7 +1733,8 @@ describe Repository do :gitlab_ci, :avatar, :issue_template, - :merge_request_template + :merge_request_template, + :xcode_config ]) repository.after_change_head @@ -2058,6 +2059,36 @@ describe Repository do end end + describe '#xcode_project?' do + before do + allow(repository).to receive(:tree).with(:head).and_return(double(:tree, blobs: [blob])) + end + + context 'when the root contains a *.xcodeproj file' do + let(:blob) { double(:blob, path: 'Foo.xcodeproj') } + + it 'returns true' do + expect(repository.xcode_project?).to be_truthy + end + end + + context 'when the root contains a *.xcworkspace file' do + let(:blob) { double(:blob, path: 'Foo.xcworkspace') } + + it 'returns true' do + expect(repository.xcode_project?).to be_truthy + end + end + + context 'when the root contains no XCode config file' do + let(:blob) { double(:blob, path: 'subdir/Foo.xcworkspace') } + + it 'returns false' do + expect(repository.xcode_project?).to be_falsey + end + end + end + describe "#keep_around" do it "does not fail if we attempt to reference bad commit" do expect(repository.kept_around?('abc1234')).to be_falsey |