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/gitlab/bitbucket_import | |
parent | 5d32a7a175fd1a7a6c97019a022c11434ea637dc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/bitbucket_import')
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 114 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/metrics.rb | 41 |
2 files changed, 103 insertions, 52 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 |