From 9456b286c3e84d50dfb6bab23d9556c00480eaf0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 31 Jul 2023 14:21:47 +0000 Subject: Add latest changes from gitlab-org/gitlab@16-1-stable-ee --- .../importers/bitbucket_server/pull_request.json | 328 ++++++++++++--------- .../representation/pull_request_spec.rb | 8 + .../bitbucket_server_import/importer_spec.rb | 3 + .../importers/pull_request_importer_spec.rb | 17 ++ .../gitlab/import/merge_request_creator_spec.rb | 8 +- .../gitlab/import/merge_request_helpers_spec.rb | 22 ++ spec/support/helpers/repo_helpers.rb | 22 +- 7 files changed, 262 insertions(+), 146 deletions(-) (limited to 'spec') diff --git a/spec/fixtures/importers/bitbucket_server/pull_request.json b/spec/fixtures/importers/bitbucket_server/pull_request.json index 77f7eb330f5..262ea603dfe 100644 --- a/spec/fixtures/importers/bitbucket_server/pull_request.json +++ b/spec/fixtures/importers/bitbucket_server/pull_request.json @@ -1,147 +1,189 @@ { - "author":{ - "approved":false, - "role":"AUTHOR", - "status":"UNAPPROVED", - "user":{ - "active":true, - "displayName":"displayName", - "emailAddress":"joe.montana@49ers.com", - "username": "username", - "id":1, - "links":{ - "self":[ - { - "href":"http://localhost:7990/users/root" - } - ] - }, - "name":"root", - "slug":"slug", - "type":"NORMAL" + "author": { + "approved": false, + "role": "AUTHOR", + "status": "UNAPPROVED", + "user": { + "active": true, + "displayName": "displayName", + "emailAddress": "joe.montana@49ers.com", + "username": "username", + "id": 1, + "links": { + "self": [ + { + "href": "http://localhost:7990/users/root" + } + ] + }, + "name": "root", + "slug": "slug", + "type": "NORMAL" + } + }, + "closed": true, + "closedDate": 1530600648850, + "createdDate": 1530600635690, + "description": "Test", + "fromRef": { + "displayId": "root/CODE_OF_CONDUCTmd-1530600625006", + "id": "refs/heads/root/CODE_OF_CONDUCTmd-1530600625006", + "latestCommit": "074e2b4dddc5b99df1bf9d4a3f66cfc15481fdc8", + "repository": { + "forkable": true, + "id": 1, + "links": { + "clone": [ + { + "href": "http://root@localhost:7990/scm/test/rouge.git", + "name": "http" + }, + { + "href": "ssh://git@localhost:7999/test/rouge.git", + "name": "ssh" + } + ], + "self": [ + { + "href": "http://localhost:7990/projects/TEST/repos/rouge/browse" + } + ] + }, + "name": "rouge", + "project": { + "description": "Test", + "id": 1, + "key": "TEST", + "links": { + "self": [ + { + "href": "http://localhost:7990/projects/TEST" + } + ] + }, + "name": "test", + "public": false, + "type": "NORMAL" + }, + "public": false, + "scmId": "git", + "slug": "rouge", + "state": "AVAILABLE", + "statusMessage": "Available" + } + }, + "id": 7, + "links": { + "self": [ + { + "href": "http://localhost:7990/projects/TEST/repos/rouge/pull-requests/7" } - }, - "closed":true, - "closedDate":1530600648850, - "createdDate":1530600635690, - "description":"Test", - "fromRef":{ - "displayId":"root/CODE_OF_CONDUCTmd-1530600625006", - "id":"refs/heads/root/CODE_OF_CONDUCTmd-1530600625006", - "latestCommit":"074e2b4dddc5b99df1bf9d4a3f66cfc15481fdc8", - "repository":{ - "forkable":true, - "id":1, - "links":{ - "clone":[ - { - "href":"http://root@localhost:7990/scm/test/rouge.git", - "name":"http" - }, - { - "href":"ssh://git@localhost:7999/test/rouge.git", - "name":"ssh" - } - ], - "self":[ - { - "href":"http://localhost:7990/projects/TEST/repos/rouge/browse" - } - ] - }, - "name":"rouge", - "project":{ - "description":"Test", - "id":1, - "key":"TEST", - "links":{ - "self":[ - { - "href":"http://localhost:7990/projects/TEST" - } - ] - }, - "name":"test", - "public":false, - "type":"NORMAL" - }, - "public":false, - "scmId":"git", - "slug":"rouge", - "state":"AVAILABLE", - "statusMessage":"Available" - } - }, - "id":7, - "links":{ - "self":[ - { - "href":"http://localhost:7990/projects/TEST/repos/rouge/pull-requests/7" - } - ] - }, - "locked":false, - "open":false, - "participants":[ - - ], - "properties":{ - "commentCount":1, - "openTaskCount":0, - "resolvedTaskCount":0 - }, - "reviewers":[ + ] + }, + "locked": false, + "open": false, + "participants": [ - ], - "state":"MERGED", - "title":"Added a new line", - "toRef":{ - "displayId":"master", - "id":"refs/heads/master", - "latestCommit":"839fa9a2d434eb697815b8fcafaecc51accfdbbc", - "repository":{ - "forkable":true, - "id":1, - "links":{ - "clone":[ - { - "href":"http://root@localhost:7990/scm/test/rouge.git", - "name":"http" - }, - { - "href":"ssh://git@localhost:7999/test/rouge.git", - "name":"ssh" - } - ], - "self":[ - { - "href":"http://localhost:7990/projects/TEST/repos/rouge/browse" - } - ] - }, - "name":"rouge", - "project":{ - "description":"Test", - "id":1, - "key":"TEST", - "links":{ - "self":[ - { - "href":"http://localhost:7990/projects/TEST" - } - ] - }, - "name":"test", - "public":false, - "type":"NORMAL" - }, - "public":false, - "scmId":"git", - "slug":"rouge", - "state":"AVAILABLE", - "statusMessage":"Available" - } - }, - "updatedDate":1530600648850, - "version":2 + ], + "properties": { + "commentCount": 1, + "openTaskCount": 0, + "resolvedTaskCount": 0 + }, + "reviewers": [ + { + "user": { + "name": "Jane", + "emailAddress": "jane@doe.com", + "active": true, + "displayName": "Jane Doe", + "id": 3, + "slug": "jane_doe", + "type": "NORMAL", + "links": { + "self": [ + { + "href": "https://api.bitbucket.org/2.0/users/jane_doe" + } + ] + } + }, + "role": "REVIEWER", + "approved": false, + "status": "UNAPPROVED" + }, + { + "user": { + "name": "John", + "emailAddress": "john@smith.com", + "active": true, + "displayName": "John Smith", + "id": 2, + "slug": "john_smith", + "type": "NORMAL", + "links": { + "self": [ + { + "href": "https://api.bitbucket.org/2.0/users/john_smith" + } + ] + } + }, + "lastReviewedCommit": "38f1424ea696f5316907ad70b1f179b356b07d1b", + "role": "REVIEWER", + "approved": true, + "status": "APPROVED" + } + ], + "state": "MERGED", + "title": "Added a new line", + "toRef": { + "displayId": "master", + "id": "refs/heads/master", + "latestCommit": "839fa9a2d434eb697815b8fcafaecc51accfdbbc", + "repository": { + "forkable": true, + "id": 1, + "links": { + "clone": [ + { + "href": "http://root@localhost:7990/scm/test/rouge.git", + "name": "http" + }, + { + "href": "ssh://git@localhost:7999/test/rouge.git", + "name": "ssh" + } + ], + "self": [ + { + "href": "http://localhost:7990/projects/TEST/repos/rouge/browse" + } + ] + }, + "name": "rouge", + "project": { + "description": "Test", + "id": 1, + "key": "TEST", + "links": { + "self": [ + { + "href": "http://localhost:7990/projects/TEST" + } + ] + }, + "name": "test", + "public": false, + "type": "NORMAL" + }, + "public": false, + "scmId": "git", + "slug": "rouge", + "state": "AVAILABLE", + "statusMessage": "Available" + } + }, + "updatedDate": 1530600648850, + "version": 2 } diff --git a/spec/lib/bitbucket_server/representation/pull_request_spec.rb b/spec/lib/bitbucket_server/representation/pull_request_spec.rb index c5d0ee8908d..4d8bb3a4407 100644 --- a/spec/lib/bitbucket_server/representation/pull_request_spec.rb +++ b/spec/lib/bitbucket_server/representation/pull_request_spec.rb @@ -46,6 +46,10 @@ RSpec.describe BitbucketServer::Representation::PullRequest, feature_category: : it { expect(subject.description).to eq('Test') } end + describe '#reviewers' do + it { expect(subject.reviewers.count).to eq(2) } + end + describe '#iid' do it { expect(subject.iid).to eq(7) } end @@ -114,6 +118,10 @@ RSpec.describe BitbucketServer::Representation::PullRequest, feature_category: : author_username: "username", author: "root", description: "Test", + reviewers: contain_exactly( + hash_including('user' => hash_including('emailAddress' => 'jane@doe.com', 'slug' => 'jane_doe')), + hash_including('user' => hash_including('emailAddress' => 'john@smith.com', 'slug' => 'john_smith')) + ), source_branch_name: "refs/heads/root/CODE_OF_CONDUCTmd-1530600625006", source_branch_sha: "074e2b4dddc5b99df1bf9d4a3f66cfc15481fdc8", target_branch_name: "refs/heads/master", diff --git a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb index 3cff2411054..4ff61bf329c 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importer_spec.rb @@ -70,6 +70,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch, title: 'This is a title', description: 'This is a test pull request', + reviewers: [], state: 'merged', author: 'Test Author', author_email: pull_request_author.email, @@ -530,6 +531,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch, title: 'This is a title', description: 'This is a test pull request', + reviewers: sample.reviewers, state: 'merged', author: 'Test Author', author_email: pull_request_author.email, @@ -570,6 +572,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer, feature_category: :impor target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch, title: 'This is a title', description: 'This is a test pull request', + reviewers: [], state: 'merged', author: 'Test Author', author_email: project.owner.email, diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb index 012cdcdd260..3c84d888c92 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb @@ -6,6 +6,8 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe include AfterNextHelpers let_it_be(:project) { create(:project, :repository) } + let_it_be(:reviewer_1) { create(:user, username: 'john_smith', email: 'john@smith.com') } + let_it_be(:reviewer_2) { create(:user, username: 'jane_doe', email: 'jane@doe.com') } let(:pull_request_data) { Gitlab::Json.parse(fixture_file('importers/bitbucket_server/pull_request.json')) } let(:pull_request) { BitbucketServer::Representation::PullRequest.new(pull_request_data) } @@ -25,12 +27,27 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe title: pull_request.title, source_branch: 'root/CODE_OF_CONDUCTmd-1530600625006', target_branch: 'master', + reviewer_ids: match_array([reviewer_1.id, reviewer_2.id]), state: pull_request.state, author_id: project.creator_id, description: "*Created by: #{pull_request.author}*\n\n#{pull_request.description}" ) end + context 'when the `bitbucket_server_user_mapping_by_username` flag is disabled' do + before do + stub_feature_flags(bitbucket_server_user_mapping_by_username: false) + end + + it 'imports reviewers correctly' do + importer.execute + + merge_request = project.merge_requests.find_by_iid(pull_request.iid) + + expect(merge_request.reviewer_ids).to match_array([reviewer_1.id, reviewer_2.id]) + end + end + it 'logs its progress' do expect(Gitlab::BitbucketServerImport::Logger) .to receive(:info).with(include(message: 'starting', iid: pull_request.iid)).and_call_original diff --git a/spec/lib/gitlab/import/merge_request_creator_spec.rb b/spec/lib/gitlab/import/merge_request_creator_spec.rb index 8f502216294..95d7ba6d833 100644 --- a/spec/lib/gitlab/import/merge_request_creator_spec.rb +++ b/spec/lib/gitlab/import/merge_request_creator_spec.rb @@ -2,14 +2,17 @@ require 'spec_helper' -RSpec.describe Gitlab::Import::MergeRequestCreator do +RSpec.describe Gitlab::Import::MergeRequestCreator, feature_category: :importers do let(:project) { create(:project, :repository) } + let_it_be(:reviewer_user) { create(:user) } subject { described_class.new(project) } describe '#execute' do let(:attributes) do - HashWithIndifferentAccess.new(merge_request.attributes.except('merge_params', 'suggested_reviewers')) + HashWithIndifferentAccess.new( + merge_request.attributes.except('merge_params', 'suggested_reviewers').merge(reviewer_ids: [reviewer_user.id]) + ) end context 'merge request already exists' do @@ -26,6 +29,7 @@ RSpec.describe Gitlab::Import::MergeRequestCreator do merge_request.reload + expect(merge_request.reviewer_ids).to contain_exactly(reviewer_user.id) expect(merge_request.merge_request_diffs.count).to eq(1) expect(merge_request.merge_request_diffs.first.commits.count).to eq(commits_count) expect(merge_request.latest_merge_request_diff_id).to eq(merge_request.merge_request_diffs.first.id) diff --git a/spec/lib/gitlab/import/merge_request_helpers_spec.rb b/spec/lib/gitlab/import/merge_request_helpers_spec.rb index 9626b7b893f..35a88dacfd7 100644 --- a/spec/lib/gitlab/import/merge_request_helpers_spec.rb +++ b/spec/lib/gitlab/import/merge_request_helpers_spec.rb @@ -66,4 +66,26 @@ RSpec.describe Gitlab::Import::MergeRequestHelpers, type: :helper do end end end + + describe '.insert_merge_request_reviewers' do + let_it_be(:merge_request) { create(:merge_request) } + + subject { helper.insert_merge_request_reviewers(merge_request, reviewers) } + + context 'when reviewers are not present' do + let(:reviewers) { nil } + + it 'does not insert reviewers' do + expect { subject }.not_to change { MergeRequestReviewer.count } + end + end + + context 'when reviewers are present' do + let(:reviewers) { create_list(:user, 3).pluck(:id) } + + it 'inserts reviewers' do + expect { subject }.to change { MergeRequestReviewer.count }.by(3) + end + end + end end diff --git a/spec/support/helpers/repo_helpers.rb b/spec/support/helpers/repo_helpers.rb index 45467fb7099..d264356aa64 100644 --- a/spec/support/helpers/repo_helpers.rb +++ b/spec/support/helpers/repo_helpers.rb @@ -120,11 +120,31 @@ eos c1acaa58bbcbc3eafe538cb8274ba387047b69f8 ).reverse # last commit is recent one + reviewers = [ + { + "user" => { + "name" => "Jane", + "emailAddress" => "jane@doe.com", + "displayName" => "Jane Doe", + "slug" => "jane_doe" + } + }, + { + "user" => { + "name" => "John", + "emailAddress" => "john@smith.com", + "displayName" => "John Smith", + "slug" => "john_smith" + } + } + ] + OpenStruct.new( source_branch: 'master', target_branch: 'feature', changes: changes, - commits: commits + commits: commits, + reviewers: reviewers ) end -- cgit v1.2.3