summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/branches.rb12
-rw-r--r--lib/api/entities.rb51
-rw-r--r--lib/api/todos.rb2
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb71
-rw-r--r--lib/gitlab/checks/force_push.rb4
-rw-r--r--lib/gitlab/git_access.rb1
-rw-r--r--lib/gitlab/gon_helper.rb2
-rw-r--r--lib/gitlab/import_export/avatar_restorer.rb31
-rw-r--r--lib/gitlab/import_export/avatar_saver.rb31
-rw-r--r--lib/gitlab/import_export/command_line_util.rb9
-rw-r--r--lib/gitlab/import_export/importer.rb6
-rw-r--r--lib/gitlab/import_export/uploads_saver.rb8
-rw-r--r--lib/tasks/gitlab/track_deployment.rake9
13 files changed, 149 insertions, 88 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index 35efe4f2e4a..66b853eb342 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -15,7 +15,8 @@ module API
# GET /projects/:id/repository/branches
get ":id/repository/branches" do
branches = user_project.repository.branches.sort_by(&:name)
- present branches, with: Entities::RepoObject, project: user_project
+
+ present branches, with: Entities::RepoBranch, project: user_project
end
# Get a single branch
@@ -28,7 +29,8 @@ module API
get ':id/repository/branches/:branch', requirements: { branch: /.+/ } do
@branch = user_project.repository.branches.find { |item| item.name == params[:branch] }
not_found!("Branch") unless @branch
- present @branch, with: Entities::RepoObject, project: user_project
+
+ present @branch, with: Entities::RepoBranch, project: user_project
end
# Protect a single branch
@@ -60,7 +62,7 @@ module API
developers_can_merge: developers_can_merge || false)
end
- present @branch, with: Entities::RepoObject, project: user_project
+ present @branch, with: Entities::RepoBranch, project: user_project
end
# Unprotect a single branch
@@ -79,7 +81,7 @@ module API
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
protected_branch.destroy if protected_branch
- present @branch, with: Entities::RepoObject, project: user_project
+ present @branch, with: Entities::RepoBranch, project: user_project
end
# Create branch
@@ -97,7 +99,7 @@ module API
if result[:status] == :success
present result[:branch],
- with: Entities::RepoObject,
+ with: Entities::RepoBranch,
project: user_project
else
render_api_error!(result[:message], 400)
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index d6fed1a1eed..d7e74582459 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -114,33 +114,23 @@ module API
end
end
- class RepoObject < Grape::Entity
+ class RepoBranch < Grape::Entity
expose :name
- expose :commit do |repo_obj, options|
- if repo_obj.respond_to?(:commit)
- repo_obj.commit
- elsif options[:project]
- options[:project].repository.commit(repo_obj.target)
- end
+ expose :commit do |repo_branch, options|
+ options[:project].repository.commit(repo_branch.target)
end
- expose :protected do |repo_obj, options|
- if options[:project]
- options[:project].protected_branch? repo_obj.name
- end
+ expose :protected do |repo_branch, options|
+ options[:project].protected_branch? repo_branch.name
end
- expose :developers_can_push do |repo_obj, options|
- if options[:project]
- options[:project].developers_can_push_to_protected_branch? repo_obj.name
- end
+ expose :developers_can_push do |repo_branch, options|
+ options[:project].developers_can_push_to_protected_branch? repo_branch.name
end
- expose :developers_can_merge do |repo_obj, options|
- if options[:project]
- options[:project].developers_can_merge_to_protected_branch? repo_obj.name
- end
+ expose :developers_can_merge do |repo_branch, options|
+ options[:project].developers_can_merge_to_protected_branch? repo_branch.name
end
end
@@ -437,27 +427,14 @@ module API
end
class RepoTag < Grape::Entity
- expose :name
- expose :message do |repo_obj, _options|
- if repo_obj.respond_to?(:message)
- repo_obj.message
- else
- nil
- end
- end
+ expose :name, :message
- expose :commit do |repo_obj, options|
- if repo_obj.respond_to?(:commit)
- repo_obj.commit
- elsif options[:project]
- options[:project].repository.commit(repo_obj.target)
- end
+ expose :commit do |repo_tag, options|
+ options[:project].repository.commit(repo_tag.target)
end
- expose :release, using: Entities::Release do |repo_obj, options|
- if options[:project]
- options[:project].releases.find_by(tag: repo_obj.name)
- end
+ expose :release, using: Entities::Release do |repo_tag, options|
+ options[:project].releases.find_by(tag: repo_tag.name)
end
end
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index 2a6bfa98ca4..26c24c3baff 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -75,7 +75,7 @@ module API
todos = find_todos
todos.each(&:done)
- present paginate(Kaminari.paginate_array(todos)), with: Entities::Todo, current_user: current_user
+ todos.length
end
end
end
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index a48dc542b14..83afed9f49f 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -44,23 +44,51 @@ module Ci
end
def builds_for_ref(ref, tag = false, trigger_request = nil)
- jobs_for_ref(ref, tag, trigger_request).map do |name, job|
- build_job(name, job)
+ jobs_for_ref(ref, tag, trigger_request).map do |name, _|
+ build_attributes(name)
end
end
def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
- jobs_for_stage_and_ref(stage, ref, tag, trigger_request).map do |name, job|
- build_job(name, job)
+ jobs_for_stage_and_ref(stage, ref, tag, trigger_request).map do |name, _|
+ build_attributes(name)
end
end
def builds
- @jobs.map do |name, job|
- build_job(name, job)
+ @jobs.map do |name, _|
+ build_attributes(name)
end
end
+ def build_attributes(name)
+ job = @jobs[name.to_sym] || {}
+ {
+ stage_idx: @stages.index(job[:stage]),
+ stage: job[:stage],
+ ##
+ # Refactoring note:
+ # - before script behaves differently than after script
+ # - after script returns an array of commands
+ # - before script should be a concatenated command
+ commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
+ tag_list: job[:tags] || [],
+ name: name,
+ allow_failure: job[:allow_failure] || false,
+ when: job[:when] || 'on_success',
+ environment: job[:environment],
+ yaml_variables: yaml_variables(name),
+ options: {
+ image: job[:image] || @image,
+ services: job[:services] || @services,
+ artifacts: job[:artifacts],
+ cache: job[:cache] || @cache,
+ dependencies: job[:dependencies],
+ after_script: job[:after_script] || @after_script,
+ }.compact
+ }
+ end
+
private
def initial_parsing
@@ -89,33 +117,6 @@ module Ci
@jobs[name] = { stage: stage }.merge(job)
end
- def build_job(name, job)
- {
- stage_idx: @stages.index(job[:stage]),
- stage: job[:stage],
- ##
- # Refactoring note:
- # - before script behaves differently than after script
- # - after script returns an array of commands
- # - before script should be a concatenated command
- commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
- tag_list: job[:tags] || [],
- name: name,
- allow_failure: job[:allow_failure] || false,
- when: job[:when] || 'on_success',
- environment: job[:environment],
- yaml_variables: yaml_variables(name),
- options: {
- image: job[:image] || @image,
- services: job[:services] || @services,
- artifacts: job[:artifacts],
- cache: job[:cache] || @cache,
- dependencies: job[:dependencies],
- after_script: job[:after_script] || @after_script,
- }.compact
- }
- end
-
def yaml_variables(name)
variables = global_variables.merge(job_variables(name))
variables.map do |key, value|
@@ -194,8 +195,8 @@ module Ci
raise ValidationError, "#{name} job: allow_failure parameter should be an boolean"
end
- if job[:when] && !job[:when].in?(%w[on_success on_failure always])
- raise ValidationError, "#{name} job: when parameter should be on_success, on_failure or always"
+ if job[:when] && !job[:when].in?(%w[on_success on_failure always manual])
+ raise ValidationError, "#{name} job: when parameter should be on_success, on_failure, always or manual"
end
if job[:environment] && !validate_environment(job[:environment])
diff --git a/lib/gitlab/checks/force_push.rb b/lib/gitlab/checks/force_push.rb
index dfa83a0eab3..5fe86553bd0 100644
--- a/lib/gitlab/checks/force_push.rb
+++ b/lib/gitlab/checks/force_push.rb
@@ -8,8 +8,8 @@ module Gitlab
if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
false
else
- missed_refs, _ = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev}))
- missed_refs.split("\n").size > 0
+ missed_ref, _ = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --git-dir=#{project.repository.path_to_repo} rev-list --max-count=1 #{oldrev} ^#{newrev}))
+ missed_ref.present?
end
end
end
diff --git a/lib/gitlab/git_access.rb b/lib/gitlab/git_access.rb
index 308f23bc9bc..8e8f39d9cb2 100644
--- a/lib/gitlab/git_access.rb
+++ b/lib/gitlab/git_access.rb
@@ -110,6 +110,7 @@ module Gitlab
def deploy_key_can_read_project?
if deploy_key
+ return true if project.public?
deploy_key.projects.include?(project)
else
false
diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb
index d4f12cb1df9..c5a11148d33 100644
--- a/lib/gitlab/gon_helper.rb
+++ b/lib/gitlab/gon_helper.rb
@@ -5,7 +5,7 @@ module Gitlab
gon.default_avatar_url = URI::join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s
gon.max_file_size = current_application_settings.max_attachment_size
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
- gon.shortcuts_path = help_shortcuts_path
+ gon.shortcuts_path = help_page_path('shortcuts')
gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class
gon.award_menu_url = emojis_path
diff --git a/lib/gitlab/import_export/avatar_restorer.rb b/lib/gitlab/import_export/avatar_restorer.rb
new file mode 100644
index 00000000000..352539eb594
--- /dev/null
+++ b/lib/gitlab/import_export/avatar_restorer.rb
@@ -0,0 +1,31 @@
+module Gitlab
+ module ImportExport
+ class AvatarRestorer
+
+ def initialize(project:, shared:)
+ @project = project
+ @shared = shared
+ end
+
+ def restore
+ return true unless avatar_export_file
+
+ @project.avatar = File.open(avatar_export_file)
+ @project.save!
+ rescue => e
+ @shared.error(e)
+ false
+ end
+
+ private
+
+ def avatar_export_file
+ @avatar_export_file ||= Dir["#{avatar_export_path}/*"].first
+ end
+
+ def avatar_export_path
+ File.join(@shared.export_path, 'avatar')
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import_export/avatar_saver.rb b/lib/gitlab/import_export/avatar_saver.rb
new file mode 100644
index 00000000000..998c21e2586
--- /dev/null
+++ b/lib/gitlab/import_export/avatar_saver.rb
@@ -0,0 +1,31 @@
+module Gitlab
+ module ImportExport
+ class AvatarSaver
+ include Gitlab::ImportExport::CommandLineUtil
+
+ def initialize(project:, shared:)
+ @project = project
+ @shared = shared
+ end
+
+ def save
+ return true unless @project.avatar.exists?
+
+ copy_files(avatar_path, avatar_export_path)
+ rescue => e
+ @shared.error(e)
+ false
+ end
+
+ private
+
+ def avatar_export_path
+ File.join(@shared.export_path, 'avatar', @project.avatar_identifier)
+ end
+
+ def avatar_path
+ @project.avatar.path
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb
index 2249904145c..5dd0e34c18e 100644
--- a/lib/gitlab/import_export/command_line_util.rb
+++ b/lib/gitlab/import_export/command_line_util.rb
@@ -36,6 +36,15 @@ module Gitlab
def git_bin_path
Gitlab.config.git.bin_path
end
+
+ def copy_files(source, destination)
+ # if we are copying files, create the destination folder
+ destination_folder = File.file?(source) ? File.dirname(destination) : destination
+
+ FileUtils.mkdir_p(destination_folder)
+ FileUtils.copy_entry(source, destination)
+ true
+ end
end
end
end
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
index 6b69a653f12..e9ee47fc090 100644
--- a/lib/gitlab/import_export/importer.rb
+++ b/lib/gitlab/import_export/importer.rb
@@ -9,7 +9,7 @@ module Gitlab
end
def execute
- if import_file && check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
+ if import_file && check_version! && [project_tree, avatar_restorer, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
project_tree.restored_project
else
raise Projects::ImportService::Error.new(@shared.errors.join(', '))
@@ -35,6 +35,10 @@ module Gitlab
project: @project)
end
+ def avatar_restorer
+ Gitlab::ImportExport::AvatarRestorer.new(project: project_tree.restored_project, shared: @shared)
+ end
+
def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: @shared,
diff --git a/lib/gitlab/import_export/uploads_saver.rb b/lib/gitlab/import_export/uploads_saver.rb
index d6f4fa57510..62a2553675c 100644
--- a/lib/gitlab/import_export/uploads_saver.rb
+++ b/lib/gitlab/import_export/uploads_saver.rb
@@ -1,6 +1,8 @@
module Gitlab
module ImportExport
class UploadsSaver
+ include Gitlab::ImportExport::CommandLineUtil
+
def initialize(project:, shared:)
@project = project
@shared = shared
@@ -17,12 +19,6 @@ module Gitlab
private
- def copy_files(source, destination)
- FileUtils.mkdir_p(destination)
- FileUtils.copy_entry(source, destination)
- true
- end
-
def uploads_export_path
File.join(@shared.export_path, 'uploads')
end
diff --git a/lib/tasks/gitlab/track_deployment.rake b/lib/tasks/gitlab/track_deployment.rake
new file mode 100644
index 00000000000..84aa2e8507a
--- /dev/null
+++ b/lib/tasks/gitlab/track_deployment.rake
@@ -0,0 +1,9 @@
+namespace :gitlab do
+ desc 'GitLab | Tracks a deployment in GitLab Performance Monitoring'
+ task track_deployment: :environment do
+ metric = Gitlab::Metrics::Metric.
+ new('deployments', version: Gitlab::VERSION)
+
+ Gitlab::Metrics.submit_metrics([metric.to_hash])
+ end
+end