diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 06:07:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 06:07:58 +0300 |
commit | 1eeef229aae5affdce415c2364858e8efc64f4b5 (patch) | |
tree | 7bbd126a3b41c4c8855a8e84ece3972030177acb /lib | |
parent | 5d32a7a175fd1a7a6c97019a022c11434ea637dc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 114 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/metrics.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml | 2 | ||||
-rw-r--r-- | lib/gitlab/danger/helper.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/import/metrics.rb | 60 |
5 files changed, 167 insertions, 56 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index 5af839d8a32..d8f9105d66d 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -3,6 +3,8 @@ module Gitlab module BitbucketImport class Importer + include Gitlab::BitbucketImport::Metrics + LABELS = [{ title: 'bug', color: '#FF0000' }, { title: 'enhancement', color: '#428BCA' }, { title: 'proposal', color: '#69D100' }, @@ -83,38 +85,42 @@ module Gitlab errors << { type: :wiki, errors: e.message } end - # rubocop: disable CodeReuse/ActiveRecord def import_issues return unless repo.issues_enabled? create_labels client.issues(repo).each do |issue| - description = '' - description += @formatter.author_line(issue.author) unless find_user_id(issue.author) - description += issue.description - - label_name = issue.kind - milestone = issue.milestone ? project.milestones.find_or_create_by(title: issue.milestone) : nil - - gitlab_issue = project.issues.create!( - iid: issue.iid, - title: issue.title, - description: description, - state_id: Issue.available_states[issue.state], - author_id: gitlab_user_id(project, issue.author), - milestone: milestone, - created_at: issue.created_at, - updated_at: issue.updated_at - ) - - gitlab_issue.labels << @labels[label_name] - - import_issue_comments(issue, gitlab_issue) if gitlab_issue.persisted? - rescue StandardError => e - errors << { type: :issue, iid: issue.iid, errors: e.message } + import_issue(issue) end end + + # rubocop: disable CodeReuse/ActiveRecord + def import_issue(issue) + description = '' + description += @formatter.author_line(issue.author) unless find_user_id(issue.author) + description += issue.description + + label_name = issue.kind + milestone = issue.milestone ? project.milestones.find_or_create_by(title: issue.milestone) : nil + + gitlab_issue = project.issues.create!( + iid: issue.iid, + title: issue.title, + description: description, + state_id: Issue.available_states[issue.state], + author_id: gitlab_user_id(project, issue.author), + milestone: milestone, + created_at: issue.created_at, + updated_at: issue.updated_at + ) + + gitlab_issue.labels << @labels[label_name] + + import_issue_comments(issue, gitlab_issue) if gitlab_issue.persisted? + rescue StandardError => e + errors << { type: :issue, iid: issue.iid, errors: e.message } + end # rubocop: enable CodeReuse/ActiveRecord def import_issue_comments(issue, gitlab_issue) @@ -159,37 +165,41 @@ module Gitlab pull_requests = client.pull_requests(repo) pull_requests.each do |pull_request| - description = '' - description += @formatter.author_line(pull_request.author) unless find_user_id(pull_request.author) - description += pull_request.description - - source_branch_sha = pull_request.source_branch_sha - target_branch_sha = pull_request.target_branch_sha - source_branch_sha = project.repository.commit(source_branch_sha)&.sha || source_branch_sha - target_branch_sha = project.repository.commit(target_branch_sha)&.sha || target_branch_sha - - merge_request = project.merge_requests.create!( - iid: pull_request.iid, - title: pull_request.title, - description: description, - source_project: project, - source_branch: pull_request.source_branch_name, - source_branch_sha: source_branch_sha, - target_project: project, - target_branch: pull_request.target_branch_name, - target_branch_sha: target_branch_sha, - state: pull_request.state, - author_id: gitlab_user_id(project, pull_request.author), - created_at: pull_request.created_at, - updated_at: pull_request.updated_at - ) - - import_pull_request_comments(pull_request, merge_request) if merge_request.persisted? - rescue StandardError => e - store_pull_request_error(pull_request, e) + import_pull_request(pull_request) end end + def import_pull_request(pull_request) + description = '' + description += @formatter.author_line(pull_request.author) unless find_user_id(pull_request.author) + description += pull_request.description + + source_branch_sha = pull_request.source_branch_sha + target_branch_sha = pull_request.target_branch_sha + source_branch_sha = project.repository.commit(source_branch_sha)&.sha || source_branch_sha + target_branch_sha = project.repository.commit(target_branch_sha)&.sha || target_branch_sha + + merge_request = project.merge_requests.create!( + iid: pull_request.iid, + title: pull_request.title, + description: description, + source_project: project, + source_branch: pull_request.source_branch_name, + source_branch_sha: source_branch_sha, + target_project: project, + target_branch: pull_request.target_branch_name, + target_branch_sha: target_branch_sha, + state: pull_request.state, + author_id: gitlab_user_id(project, pull_request.author), + created_at: pull_request.created_at, + updated_at: pull_request.updated_at + ) + + import_pull_request_comments(pull_request, merge_request) if merge_request.persisted? + rescue StandardError => e + store_pull_request_error(pull_request, e) + end + def import_pull_request_comments(pull_request, merge_request) comments = client.pull_request_comments(repo, pull_request.iid) diff --git a/lib/gitlab/bitbucket_import/metrics.rb b/lib/gitlab/bitbucket_import/metrics.rb new file mode 100644 index 00000000000..25e2d9b211e --- /dev/null +++ b/lib/gitlab/bitbucket_import/metrics.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + module BitbucketImport + module Metrics + extend ActiveSupport::Concern + + IMPORTER = :bitbucket_importer + + included do + prepend Gitlab::Import::Metrics + + Gitlab::Import::Metrics.measure(:execute, metrics: { + "#{IMPORTER}_imported_projects": { + type: :counter, + description: 'The number of imported Bitbucket projects' + }, + "#{IMPORTER}_total_duration_seconds": { + type: :histogram, + labels: { importer: IMPORTER }, + description: 'Total time spent importing Bitbucket projects, in seconds' + } + }) + + Gitlab::Import::Metrics.measure(:import_issue, metrics: { + "#{IMPORTER}_imported_issues": { + type: :counter, + description: 'The number of imported Bitbucket issues' + } + }) + + Gitlab::Import::Metrics.measure(:import_pull_request, metrics: { + "#{IMPORTER}_imported_pull_requests": { + type: :counter, + description: 'The number of imported Bitbucket pull requests' + } + }) + end + end + end +end diff --git a/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml index bb0de9df8bf..ceaa8115c3d 100644 --- a/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml @@ -1,6 +1,6 @@ build: stage: build - image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image/master:stable" + image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image:v0.2.0" variables: DOCKER_TLS_CERTDIR: "" services: diff --git a/lib/gitlab/danger/helper.rb b/lib/gitlab/danger/helper.rb index 6bb46b1730f..aa2737262be 100644 --- a/lib/gitlab/danger/helper.rb +++ b/lib/gitlab/danger/helper.rb @@ -100,6 +100,7 @@ module Gitlab test: "~test ~Quality for `spec/features/*`", engineering_productivity: '~"Engineering Productivity" for CI, Danger' }.freeze + # First-match win, so be sure to put more specific regex at the top... CATEGORIES = { %r{\Adoc/} => :none, # To reinstate roulette for documentation, set to `:docs`. %r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :none, # To reinstate roulette for documentation, set to `:docs`. @@ -145,9 +146,8 @@ module Gitlab %r{\A(ee/)?app/(?!assets|views)[^/]+} => :backend, %r{\A(ee/)?(bin|config|generator_templates|lib|rubocop)/} => :backend, %r{\A(ee/)?spec/features/} => :test, - %r{\A(ee/)?spec/(?!javascripts|frontend)[^/]+} => :backend, - %r{\A(ee/)?vendor/(?!assets)[^/]+} => :backend, - %r{\A(ee/)?vendor/(languages\.yml|licenses\.csv)\z} => :backend, + %r{\A(ee/)?spec/} => :backend, + %r{\A(ee/)?vendor/} => :backend, %r{\A(Gemfile|Gemfile.lock|Rakefile)\z} => :backend, %r{\A[A-Z_]+_VERSION\z} => :backend, %r{\A\.rubocop(_todo)?\.yml\z} => :backend, diff --git a/lib/gitlab/import/metrics.rb b/lib/gitlab/import/metrics.rb new file mode 100644 index 00000000000..76638a8cf86 --- /dev/null +++ b/lib/gitlab/import/metrics.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +# Prepend `Gitlab::Import::Metrics` to a class in order +# to measure and emit `Gitlab::Metrics` metrics of specified methods. +# +# @example +# class Importer +# prepend Gitlab::Import::Metrics +# +# Gitlab::ImportExport::Metrics.measure :execute, metrics: { +# importer_counter: { +# type: :counter, +# description: 'counter' +# }, +# importer_histogram: { +# type: :histogram, +# labels: { importer: 'importer' }, +# description: 'histogram' +# } +# } +# +# def execute +# ... +# end +# end +# +# Each call to `#execute` increments `importer_counter` as well as +# measures `#execute` duration and reports histogram `importer_histogram` +module Gitlab + module Import + module Metrics + def self.measure(method_name, metrics:) + define_method "#{method_name}" do |*args| + start_time = Time.zone.now + + result = super(*args) + + end_time = Time.zone.now + + report_measurement_metrics(metrics, end_time - start_time) + + result + end + end + + def report_measurement_metrics(metrics, duration) + metrics.each do |metric_name, metric_value| + case metric_value[:type] + when :counter + Gitlab::Metrics.counter(metric_name, metric_value[:description]).increment + when :histogram + Gitlab::Metrics.histogram(metric_name, metric_value[:description]).observe(metric_value[:labels], duration) + else + nil + end + end + end + end + end +end |