From ea4777ff501e370a39ae30e76a955136afe3c1fa Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 31 Dec 2015 15:19:13 +0100 Subject: Add features for list and show details of variables in API --- app/models/ci/variable.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb index 56759d3e50f..0e2712086ca 100644 --- a/app/models/ci/variable.rb +++ b/app/models/ci/variable.rb @@ -9,6 +9,7 @@ # encrypted_value :text # encrypted_value_salt :string(255) # encrypted_value_iv :string(255) +# gl_project_id :integer # module Ci -- cgit v1.2.1 From b60c146267dfa8dc1c170426e1817c6b2a168d1a Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 7 Jan 2016 13:49:38 +0100 Subject: Change :variable_id to :key as resource ID in API --- app/models/ci/variable.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb index 0e2712086ca..1d9ee91a31c 100644 --- a/app/models/ci/variable.rb +++ b/app/models/ci/variable.rb @@ -18,8 +18,12 @@ module Ci belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id - validates_presence_of :key validates_uniqueness_of :key, scope: :gl_project_id + validates :key, + presence: true, + length: { within: 0..255 }, + format: { with: /\A[a-zA-Z0-9_]+\z/, + message: "can contain only letters, digits and '_'." } attr_encrypted :value, mode: :per_attribute_iv_and_salt, key: Gitlab::Application.secrets.db_key_base end -- cgit v1.2.1 From bc7ef8e5b7a002ca6bc2d7a5e6be11b4a59b6710 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 29 Dec 2015 17:53:55 -0200 Subject: Add ldap_blocked as new state to users state machine --- app/models/user.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index 46b36c605b0..67b47b0f329 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -198,16 +198,26 @@ class User < ActiveRecord::Base transition active: :blocked end + event :ldap_block do + transition active: :ldap_blocked + end + event :activate do transition blocked: :active end + + state :blocked, :ldap_blocked do + def blocked? + true + end + end end mount_uploader :avatar, AvatarUploader # Scopes scope :admins, -> { where(admin: true) } - scope :blocked, -> { with_state(:blocked) } + scope :blocked, -> { with_states(:blocked, :ldap_blocked) } scope :active, -> { with_state(:active) } scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all } scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') } -- cgit v1.2.1 From ec67e9be1d7486199b47e19c766202a8bfdefe93 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 6 Jan 2016 05:38:52 -0200 Subject: Repair ldap_blocked state when no ldap identity exist anymore --- app/models/identity.rb | 4 ++++ app/models/user.rb | 1 + 2 files changed, 5 insertions(+) (limited to 'app/models') diff --git a/app/models/identity.rb b/app/models/identity.rb index 8bcdc194953..830b99fa3f2 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -18,4 +18,8 @@ class Identity < ActiveRecord::Base validates :provider, presence: true validates :extern_uid, allow_blank: true, uniqueness: { scope: :provider } validates :user_id, uniqueness: { scope: :provider } + + def is_ldap? + provider.starts_with?('ldap') + end end diff --git a/app/models/user.rb b/app/models/user.rb index 67b47b0f329..5eed9cf91c7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -196,6 +196,7 @@ class User < ActiveRecord::Base state_machine :state, initial: :active do event :block do transition active: :blocked + transition ldap_blocked: :blocked end event :ldap_block do -- cgit v1.2.1 From ac6a10f3e88c5d2081b8638df63016089517a844 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 12 Jan 2016 12:29:10 -0200 Subject: Codestyle changes --- app/models/identity.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/identity.rb b/app/models/identity.rb index 830b99fa3f2..e1915b079d4 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -19,7 +19,7 @@ class Identity < ActiveRecord::Base validates :extern_uid, allow_blank: true, uniqueness: { scope: :provider } validates :user_id, uniqueness: { scope: :provider } - def is_ldap? + def ldap? provider.starts_with?('ldap') end end -- cgit v1.2.1 From d11ca78cdcd761f7f9b6388474765ede51011085 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 13 Jan 2016 17:01:05 -0800 Subject: Fix the undefinded variable error in Project's safe_import_url method --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/project.rb b/app/models/project.rb index 31990485f7d..7e131151513 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -397,7 +397,7 @@ class Project < ActiveRecord::Base result.password = '*****' unless result.password.nil? result.to_s rescue - original_url + self.import_url end def check_limit -- cgit v1.2.1 From dd6fc01ff8a073880b67a323a547edeb5d63f167 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Thu, 14 Jan 2016 03:31:27 -0200 Subject: fixed LDAP activation on login to use new ldap_blocked state --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index 5eed9cf91c7..592468933ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -205,6 +205,7 @@ class User < ActiveRecord::Base event :activate do transition blocked: :active + transition ldap_blocked: :active end state :blocked, :ldap_blocked do -- cgit v1.2.1 From a1cfd2754e66365f601e6ee88eb09724dd60084c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 17 Dec 2015 09:09:46 +0100 Subject: Add `artifacts_metadata` field to `Ci::Build` This will contain serialized array of files inside artifacts tarball. --- app/models/ci/build.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index a4779d06de8..a2dca97ad31 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -30,6 +30,7 @@ # description :string(255) # artifacts_file :text # gl_project_id :integer +# artifacts_metadata :text # module Ci @@ -40,6 +41,7 @@ module Ci belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' serialize :options + serialize :artifacts_metadata validates :coverage, numericality: true, allow_blank: true validates_presence_of :ref -- cgit v1.2.1 From 79fe18d9e7290fb880f1feb5f2c9f3f96b2d74fe Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 17 Dec 2015 14:24:43 +0100 Subject: Move build artifacts implementation to separate controller --- app/models/ci/build.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index a2dca97ad31..b928416aa11 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -326,7 +326,7 @@ module Ci def download_url if artifacts_file.exists? Gitlab::Application.routes.url_helpers. - download_namespace_project_build_path(project.namespace, project, self) + download_namespace_project_build_artifacts_path(project.namespace, project, self) end end -- cgit v1.2.1 From a96d45c694bd8fe7d07283d0b46725ca8e4c281b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 17 Dec 2015 15:17:00 +0100 Subject: Add view action to artifacts controller --- app/models/ci/build.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index b928416aa11..11b707e57a0 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -336,8 +336,6 @@ module Ci project.execute_services(build_data.dup, :build_hooks) end - - private def yaml_variables -- cgit v1.2.1 From ebd69c5fc1296f30238326b901ad73c891d696da Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 10:35:51 +0100 Subject: Remove artifacts metadata column from database --- app/models/ci/build.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 11b707e57a0..347022ff29b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -30,7 +30,6 @@ # description :string(255) # artifacts_file :text # gl_project_id :integer -# artifacts_metadata :text # module Ci @@ -41,7 +40,6 @@ module Ci belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' serialize :options - serialize :artifacts_metadata validates :coverage, numericality: true, allow_blank: true validates_presence_of :ref @@ -336,6 +334,10 @@ module Ci project.execute_services(build_data.dup, :build_hooks) end + def artifacts_metadata(path) + [] + end + private def yaml_variables -- cgit v1.2.1 From d8cc9e4ef7da6ac971d44361546188eebfb3beff Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 11:10:39 +0100 Subject: Add button to CI build artifacts browser into build summary --- app/models/ci/build.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 347022ff29b..c69cb661746 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -328,6 +328,13 @@ module Ci end end + def artifacts_browse_url + if artifacts_file.exists? + Gitlab::Application.routes.url_helpers. + browse_namespace_project_build_artifacts_path(project.namespace, project, self) + end + end + def execute_hooks build_data = Gitlab::BuildDataBuilder.build(self) project.execute_hooks(build_data.dup, :build_hooks) -- cgit v1.2.1 From 612ab584bf919a96eaaaf86ef474f8ffe7cbf2b2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 11:13:28 +0100 Subject: Mix `url_helpers` into `Ci::Build` --- app/models/ci/build.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index c69cb661746..e576f94fd4e 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -34,6 +34,7 @@ module Ci class Build < CommitStatus + include Gitlab::Application.routes.url_helpers LAZY_ATTRIBUTES = ['trace'] belongs_to :runner, class_name: 'Ci::Runner' @@ -291,21 +292,18 @@ module Ci end def target_url - Gitlab::Application.routes.url_helpers. - namespace_project_build_url(project.namespace, project, self) + namespace_project_build_url(project.namespace, project, self) end def cancel_url if active? - Gitlab::Application.routes.url_helpers. - cancel_namespace_project_build_path(project.namespace, project, self) + cancel_namespace_project_build_path(project.namespace, project, self) end end def retry_url if retryable? - Gitlab::Application.routes.url_helpers. - retry_namespace_project_build_path(project.namespace, project, self) + retry_namespace_project_build_path(project.namespace, project, self) end end @@ -323,15 +321,13 @@ module Ci def download_url if artifacts_file.exists? - Gitlab::Application.routes.url_helpers. - download_namespace_project_build_artifacts_path(project.namespace, project, self) + download_namespace_project_build_artifacts_path(project.namespace, project, self) end end def artifacts_browse_url if artifacts_file.exists? - Gitlab::Application.routes.url_helpers. - browse_namespace_project_build_artifacts_path(project.namespace, project, self) + browse_namespace_project_build_artifacts_path(project.namespace, project, self) end end -- cgit v1.2.1 From 9e0e9342a47022a9caaa4a5596ec3ddb91fddc58 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 11:21:01 +0100 Subject: Rename method that returns url to CI build artifacts download --- app/models/ci/build.rb | 2 +- app/models/commit_status.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index e576f94fd4e..9adbfdd2c92 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -319,7 +319,7 @@ module Ci pending? && !any_runners_online? end - def download_url + def artifacts_download_url if artifacts_file.exists? download_namespace_project_build_artifacts_path(project.namespace, project, self) end diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index ff479493474..4ce9b998dfc 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -131,7 +131,11 @@ class CommitStatus < ActiveRecord::Base false end - def download_url + def artifacts_download_url + nil + end + + def artifacts_browse_url nil end end -- cgit v1.2.1 From 8eeed761a9c25ea8ccfc347fbd3f5894b5957d9e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 11:43:15 +0100 Subject: Update specs for CI Build, add `artifacts?` method `artifacts?` method checks if artifacts archive is available. --- app/models/ci/build.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 9adbfdd2c92..327114e0350 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -319,24 +319,26 @@ module Ci pending? && !any_runners_online? end - def artifacts_download_url - if artifacts_file.exists? - download_namespace_project_build_artifacts_path(project.namespace, project, self) - end - end - - def artifacts_browse_url - if artifacts_file.exists? - browse_namespace_project_build_artifacts_path(project.namespace, project, self) - end - end - def execute_hooks build_data = Gitlab::BuildDataBuilder.build(self) project.execute_hooks(build_data.dup, :build_hooks) project.execute_services(build_data.dup, :build_hooks) end + def artifacts? + artifacts_file.exists? + end + + def artifacts_download_url + download_namespace_project_build_artifacts_path(project.namespace, project, self) if + artifacts? + end + + def artifacts_browse_url + browse_namespace_project_build_artifacts_path(project.namespace, project, self) if + artifacts? + end + def artifacts_metadata(path) [] end -- cgit v1.2.1 From 5ff7ec42dc8759717c485478261128d61ea70b9a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 12:06:27 +0100 Subject: Add method that checks if artifacts browser is supported This is needed because of backward compatibility. Previously artifacts archive had `.tar.gz` format, but artifacts browser requires ZIP format now. --- app/models/ci/build.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 327114e0350..1506e957b3c 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -339,6 +339,12 @@ module Ci artifacts? end + def artifacts_browser_supported? + # TODO, since carrierwave 0.10.0 we will be able to check mime type here + # + artifacts? && artifacts_file.path.end_with?('zip') + end + def artifacts_metadata(path) [] end -- cgit v1.2.1 From c33b105f11ce2b9232de8c7d07f810c29edd3f5b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 29 Dec 2015 11:34:46 +0100 Subject: Make some conditions in `Ci::Build` more readable --- app/models/ci/build.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 1506e957b3c..ee82fe824c5 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -330,13 +330,15 @@ module Ci end def artifacts_download_url - download_namespace_project_build_artifacts_path(project.namespace, project, self) if - artifacts? + if artifacts? + download_namespace_project_build_artifacts_path(project.namespace, project, self) + end end def artifacts_browse_url - browse_namespace_project_build_artifacts_path(project.namespace, project, self) if - artifacts? + if artifacts? + browse_namespace_project_build_artifacts_path(project.namespace, project, self) + end end def artifacts_browser_supported? -- cgit v1.2.1 From 662f4b9e1dec8e461c4ea8da3ccc46a259d9d205 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 30 Dec 2015 14:41:44 +0100 Subject: Add artifacts metadata uploader filed Artifacts metadata field will be used to store a filename of gzipped file containing metadata definition for given artifacts archive. --- app/models/ci/build.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ee82fe824c5..98f9e6911f2 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -30,6 +30,7 @@ # description :string(255) # artifacts_file :text # gl_project_id :integer +# artifacts_metadata :text # module Ci @@ -50,6 +51,7 @@ module Ci scope :similar, ->(build) { where(ref: build.ref, tag: build.tag, trigger_request_id: build.trigger_request_id) } mount_uploader :artifacts_file, ArtifactUploader + mount_uploader :artifacts_metadata, ArtifactUploader acts_as_taggable @@ -344,11 +346,11 @@ module Ci def artifacts_browser_supported? # TODO, since carrierwave 0.10.0 we will be able to check mime type here # - artifacts? && artifacts_file.path.end_with?('zip') + artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? end - def artifacts_metadata(path) - [] + def artifacts_metadata_for(path) + {} end private -- cgit v1.2.1 From 447f56036e837fc9a9c2bcaf382d38dc513a9733 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 31 Dec 2015 09:25:59 +0100 Subject: Use metadata stored in artifacats metadata file --- app/models/ci/build.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 98f9e6911f2..2c389bbdf61 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -349,8 +349,23 @@ module Ci artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? end - def artifacts_metadata_for(path) - {} + def artifacts_metadata_for_path(path) + return {} unless artifacts_metadata.exists? + metadata = [] + meta_path = path.sub(/^\.\//, '') + + File.open(artifacts_metadata.path) do |file| + gzip = Zlib::GzipReader.new(file) + gzip.each_line do |line| + if line =~ %r{^#{meta_path}[^/]+/?\s} + path, meta = line.split(' ') + metadata << path + end + end + gzip.close + end + + metadata end private -- cgit v1.2.1 From 3de8a4620a70c886c815576dc0a30a745cbb8ccb Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 31 Dec 2015 12:21:56 +0100 Subject: Parse artifacts metadata stored in JSON format --- app/models/ci/build.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2c389bbdf61..f6783e21d90 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -350,22 +350,23 @@ module Ci end def artifacts_metadata_for_path(path) - return {} unless artifacts_metadata.exists? - metadata = [] + return [] unless artifacts_metadata.exists? + paths, metadata = [], [] meta_path = path.sub(/^\.\//, '') File.open(artifacts_metadata.path) do |file| gzip = Zlib::GzipReader.new(file) gzip.each_line do |line| if line =~ %r{^#{meta_path}[^/]+/?\s} - path, meta = line.split(' ') - metadata << path + path, meta = line.split(' ') + paths << path + metadata << JSON.parse(meta) end end gzip.close end - metadata + [paths, metadata] end private -- cgit v1.2.1 From df41148662142ce20a77b092665f48dd4dfa7bfb Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 2 Jan 2016 20:09:21 +0100 Subject: Improve path sanitization in `StringPath` --- app/models/ci/build.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index f6783e21d90..df51a5ce079 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -352,15 +352,15 @@ module Ci def artifacts_metadata_for_path(path) return [] unless artifacts_metadata.exists? paths, metadata = [], [] - meta_path = path.sub(/^\.\//, '') + metadata_path = path.sub(/^\.\//, '') File.open(artifacts_metadata.path) do |file| gzip = Zlib::GzipReader.new(file) gzip.each_line do |line| - if line =~ %r{^#{meta_path}[^/]+/?\s} - path, meta = line.split(' ') - paths << path - metadata << JSON.parse(meta) + if line =~ %r{^#{Regexp.escape(metadata_path)}[^/\s]+/?\s} + matched_path, matched_meta = line.split(' ') + paths << matched_path + metadata << JSON.parse(matched_meta) end end gzip.close -- cgit v1.2.1 From a7f99b67a0bf1160f41ebf4dc92c618eb13a7a10 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Jan 2016 13:08:49 +0100 Subject: Extract artifacts metadata implementation to separate class --- app/models/ci/build.rb | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index df51a5ce079..7983ce0e88e 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -349,24 +349,10 @@ module Ci artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? end - def artifacts_metadata_for_path(path) - return [] unless artifacts_metadata.exists? - paths, metadata = [], [] - - metadata_path = path.sub(/^\.\//, '') - File.open(artifacts_metadata.path) do |file| - gzip = Zlib::GzipReader.new(file) - gzip.each_line do |line| - if line =~ %r{^#{Regexp.escape(metadata_path)}[^/\s]+/?\s} - matched_path, matched_meta = line.split(' ') - paths << matched_path - metadata << JSON.parse(matched_meta) - end - end - gzip.close - end - [paths, metadata] + def artifacts_metadata_string_path(path) + file = artifacts_metadata.path + Gitlab::Ci::Build::Artifacts::Metadata.new(file, path).to_string_path end private -- cgit v1.2.1 From 61fb47a43202332fe9ac57847996da929ba42d3f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 9 Jan 2016 14:41:43 +0100 Subject: Simplify implementation of build artifacts browser (refactoring) --- app/models/ci/build.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 7983ce0e88e..2d2206cc4d7 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -338,21 +338,19 @@ module Ci end def artifacts_browse_url - if artifacts? + if artifacts_browser_supported? browse_namespace_project_build_artifacts_path(project.namespace, project, self) end end def artifacts_browser_supported? - # TODO, since carrierwave 0.10.0 we will be able to check mime type here - # artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? end - def artifacts_metadata_string_path(path) - file = artifacts_metadata.path - Gitlab::Ci::Build::Artifacts::Metadata.new(file, path).to_string_path + def artifacts_metadata_path(path) + metadata_file = artifacts_metadata.path + Gitlab::Ci::Build::Artifacts::Metadata.new(metadata_file, path).to_path end private -- cgit v1.2.1 From 09a4a5aff8c53dd5930044ddbb285a95ef177d8a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 11 Jan 2016 09:57:03 +0100 Subject: Render only valid paths in artifacts metadata In this version we will support only relative paths in artifacts metadata. Support for absolute paths will be introduced later. --- app/models/ci/build.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2d2206cc4d7..7593ceda488 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -347,10 +347,8 @@ module Ci artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? end - def artifacts_metadata_path(path) - metadata_file = artifacts_metadata.path - Gitlab::Ci::Build::Artifacts::Metadata.new(metadata_file, path).to_path + Gitlab::Ci::Build::Artifacts::Metadata.new(artifacts_metadata.path, path).to_path end private -- cgit v1.2.1 From 487b0a026f9efe2d8214c19a7b95b391708ba3f4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Jan 2016 11:02:15 +0100 Subject: Improvements, readability for artifacts browser --- app/models/ability.rb | 2 +- app/models/ci/build.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 5a1a67db8e1..5375148a654 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -175,7 +175,7 @@ class Ability :create_merge_request, :create_wiki, :manage_builds, - :download_build_artifacts, + :read_build_artifacts, :push_code ] end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 7593ceda488..fef667f865e 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -344,7 +344,7 @@ module Ci end def artifacts_browser_supported? - artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists? + artifacts? && artifacts_metadata.exists? end def artifacts_metadata_path(path) -- cgit v1.2.1 From 6b0a43aff36f0bbb9050b3c04155a3ccd9c1a75b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 13 Jan 2016 21:17:28 +0100 Subject: Improve readability of artifacts browser `Entry` related code --- app/models/ci/build.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index fef667f865e..6cc26abce66 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -347,8 +347,8 @@ module Ci artifacts? && artifacts_metadata.exists? end - def artifacts_metadata_path(path) - Gitlab::Ci::Build::Artifacts::Metadata.new(artifacts_metadata.path, path).to_path + def artifacts_metadata_entry(path) + Gitlab::Ci::Build::Artifacts::Metadata.new(artifacts_metadata.path, path).to_entry end private -- cgit v1.2.1