From 4610e18c2e4af3aaeda5a90cf3d3ffe7efaccd02 Mon Sep 17 00:00:00 2001 From: James Nutt Date: Wed, 6 Nov 2024 14:12:33 +0000 Subject: [PATCH] Add missing fields to BBS representations This MR adds missing fields to the representation objects from Bitbucket Server data. These fields will be used in a follow-up MR for adding improved user contribution mapping to Bitbucket Server import. Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/466356 Changelog: other --- .../rspec/example_without_description.yml | 1 - .rubocop_todo/rspec/named_subject.yml | 1 - .../rspec/repeated_example_group_body.yml | 1 - .../representation/activity.rb | 20 +++++++++ .../representation/comment.rb | 5 +++ .../representation/activity_spec.rb | 8 ++++ .../representation/comment_spec.rb | 43 +++++++++++-------- 7 files changed, 57 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo/rspec/example_without_description.yml b/.rubocop_todo/rspec/example_without_description.yml index 1af8550cf0b960..bbafdd169e58dd 100644 --- a/.rubocop_todo/rspec/example_without_description.yml +++ b/.rubocop_todo/rspec/example_without_description.yml @@ -299,7 +299,6 @@ RSpec/ExampleWithoutDescription: - 'spec/lib/bitbucket/representation/issue_spec.rb' - 'spec/lib/bitbucket/representation/pull_request_spec.rb' - 'spec/lib/bitbucket_server/representation/activity_spec.rb' - - 'spec/lib/bitbucket_server/representation/comment_spec.rb' - 'spec/lib/bitbucket_server/representation/pull_request_comment_spec.rb' - 'spec/lib/bitbucket_server/representation/pull_request_spec.rb' - 'spec/lib/bulk_imports/groups/pipelines/group_attributes_pipeline_spec.rb' diff --git a/.rubocop_todo/rspec/named_subject.yml b/.rubocop_todo/rspec/named_subject.yml index 5ce0500d6de9aa..5db9836a80a017 100644 --- a/.rubocop_todo/rspec/named_subject.yml +++ b/.rubocop_todo/rspec/named_subject.yml @@ -1586,7 +1586,6 @@ RSpec/NamedSubject: - 'spec/lib/bitbucket_server/collection_spec.rb' - 'spec/lib/bitbucket_server/connection_spec.rb' - 'spec/lib/bitbucket_server/representation/activity_spec.rb' - - 'spec/lib/bitbucket_server/representation/comment_spec.rb' - 'spec/lib/bitbucket_server/representation/pull_request_comment_spec.rb' - 'spec/lib/bitbucket_server/representation/pull_request_spec.rb' - 'spec/lib/bitbucket_server/representation/repo_spec.rb' diff --git a/.rubocop_todo/rspec/repeated_example_group_body.yml b/.rubocop_todo/rspec/repeated_example_group_body.yml index d6cd19cf67a531..f434e14b24a36c 100644 --- a/.rubocop_todo/rspec/repeated_example_group_body.yml +++ b/.rubocop_todo/rspec/repeated_example_group_body.yml @@ -27,7 +27,6 @@ RSpec/RepeatedExampleGroupBody: - 'spec/lib/api/entities/application_setting_spec.rb' - 'spec/lib/banzai/filter/references/commit_range_reference_filter_spec.rb' - 'spec/lib/banzai/filter/references/commit_reference_filter_spec.rb' - - 'spec/lib/bitbucket_server/representation/comment_spec.rb' - 'spec/lib/gitlab/blob_helper_spec.rb' - 'spec/lib/gitlab/ci/config/entry/release_spec.rb' - 'spec/lib/gitlab/ci/pipeline/seed/build_spec.rb' diff --git a/lib/bitbucket_server/representation/activity.rb b/lib/bitbucket_server/representation/activity.rb index 98126bfaa2dd57..df77fd0d026d30 100644 --- a/lib/bitbucket_server/representation/activity.rb +++ b/lib/bitbucket_server/representation/activity.rb @@ -35,6 +35,14 @@ def committer_user commit.dig('committer', 'displayName') end + def committer_name + commit.dig('committer', 'displayName') + end + + def committer_username + commit.dig('committer', 'slug') + end + def committer_email commit.dig('committer', 'emailAddress') end @@ -53,6 +61,10 @@ def approved_event? action == 'APPROVED' end + def approver_name + raw.dig('user', 'displayName') + end + def approver_username raw.dig('user', 'slug') end @@ -65,6 +77,10 @@ def declined_event? action == 'DECLINED' end + def decliner_name + raw.dig('user', 'displayName') + end + def decliner_username raw.dig('user', 'slug') end @@ -80,12 +96,16 @@ def created_at def to_hash { id: id, + committer_name: committer_user, committer_user: committer_user, + committer_username: committer_username, committer_email: committer_email, merge_timestamp: merge_timestamp, merge_commit: merge_commit, + approver_name: approver_name, approver_username: approver_username, approver_email: approver_email, + decliner_name: decliner_name, decliner_username: decliner_username, decliner_email: decliner_email, created_at: created_at diff --git a/lib/bitbucket_server/representation/comment.rb b/lib/bitbucket_server/representation/comment.rb index a8452b9467e6f3..d2b0a42b9e6086 100644 --- a/lib/bitbucket_server/representation/comment.rb +++ b/lib/bitbucket_server/representation/comment.rb @@ -37,6 +37,10 @@ def id raw_comment['id'] end + def author_name + author['displayName'] + end + def author_username author['username'] || author['slug'] || @@ -81,6 +85,7 @@ def to_hash { id: id, + author_name: author_name, author_email: author_email, author_username: author_username, note: note, diff --git a/spec/lib/bitbucket_server/representation/activity_spec.rb b/spec/lib/bitbucket_server/representation/activity_spec.rb index 7be0a058f6e50f..32899050a04a6f 100644 --- a/spec/lib/bitbucket_server/representation/activity_spec.rb +++ b/spec/lib/bitbucket_server/representation/activity_spec.rb @@ -49,6 +49,8 @@ it { expect(subject.comment?).to be_falsey } it { expect(subject.inline_comment?).to be_falsey } it { expect(subject.committer_user).to eq('root') } + it { expect(subject.committer_name).to eq('root') } + it { expect(subject.committer_username).to eq('slug') } it { expect(subject.committer_email).to eq('test.user@example.com') } it { expect(subject.merge_timestamp).to be_a(Time) } it { expect(subject.created_at).to be_a(Time) } @@ -60,6 +62,8 @@ a_hash_including( id: 7, committer_user: 'root', + committer_name: 'root', + committer_username: 'slug', committer_email: 'test.user@example.com', merge_commit: '839fa9a2d434eb697815b8fcafaecc51accfdbbc' ) @@ -76,6 +80,7 @@ it { expect(subject.inline_comment?).to be_falsey } it { expect(subject.merge_event?).to be_falsey } it { expect(subject.approved_event?).to be_truthy } + it { expect(subject.approver_name).to eq('root') } it { expect(subject.approver_username).to eq('slug') } it { expect(subject.approver_email).to eq('test.user@example.com') } it { expect(subject.created_at).to be_a(Time) } @@ -85,6 +90,7 @@ expect(subject.to_hash).to match( a_hash_including( id: 15, + approver_name: 'root', approver_username: 'slug', approver_email: 'test.user@example.com' ) @@ -101,6 +107,7 @@ it { expect(subject.inline_comment?).to be_falsey } it { expect(subject.merge_event?).to be_falsey } it { expect(subject.declined_event?).to be_truthy } + it { expect(subject.decliner_name).to eq('root') } it { expect(subject.decliner_username).to eq('slug') } it { expect(subject.decliner_email).to eq('test.user@example.com') } it { expect(subject.created_at).to be_a(Time) } @@ -110,6 +117,7 @@ expect(subject.to_hash).to match( a_hash_including( id: 18, + decliner_name: 'root', decliner_username: 'slug', decliner_email: 'test.user@example.com' ) diff --git a/spec/lib/bitbucket_server/representation/comment_spec.rb b/spec/lib/bitbucket_server/representation/comment_spec.rb index 25404a4c081fc4..7e32da8a7f7b0a 100644 --- a/spec/lib/bitbucket_server/representation/comment_spec.rb +++ b/spec/lib/bitbucket_server/representation/comment_spec.rb @@ -6,15 +6,19 @@ let(:activities) { Gitlab::Json.parse(fixture_file('importers/bitbucket_server/activities.json'))['values'] } let(:comment) { activities.first } - subject { described_class.new(comment) } + subject(:comment_representation) { described_class.new(comment) } describe '#id' do - it { expect(subject.id).to eq(9) } + it { expect(comment_representation.id).to eq(9) } + end + + describe '#author_name' do + it { expect(comment_representation.author_name).to eq('root') } end describe '#author_username' do it 'returns username' do - expect(subject.author_username).to eq('username') + expect(comment_representation.author_username).to eq('username') end context 'when username is absent' do @@ -23,7 +27,7 @@ end it 'returns slug' do - expect(subject.author_username).to eq('slug') + expect(comment_representation.author_username).to eq('slug') end end @@ -34,55 +38,56 @@ end it 'returns displayName' do - expect(subject.author_username).to eq('root') + expect(comment_representation.author_username).to eq('root') end end end describe '#author_email' do - it { expect(subject.author_email).to eq('test.user@example.com') } + it { expect(comment_representation.author_email).to eq('test.user@example.com') } end describe '#note' do - it { expect(subject.note).to eq('is this a new line?') } + it { expect(comment_representation.note).to eq('is this a new line?') } end describe '#created_at' do - it { expect(subject.created_at).to be_a(Time) } + it { expect(comment_representation.created_at).to be_a(Time) } end describe '#updated_at' do - it { expect(subject.created_at).to be_a(Time) } + it { expect(comment_representation.updated_at).to be_a(Time) } end describe '#comments' do - it { expect(subject.comments.count).to eq(4) } - it { expect(subject.comments).to all(be_a(described_class)) } - it { expect(subject.comments.map(&:note)).to match_array(["Hello world", "Ok", "hello", "hi"]) } + it { expect(comment_representation.comments.count).to eq(4) } + it { expect(comment_representation.comments).to all(be_a(described_class)) } + it { expect(comment_representation.comments.map(&:note)).to match_array(["Hello world", "Ok", "hello", "hi"]) } # The thread should look like: # - # is this a new line? (subject) + # is this a new line? (comment_representation) # -> Hello world (first) # -> Ok (third) # -> Hi (fourth) # -> hello (second) it 'comments have the right parent' do - first, second, third, fourth = subject.comments[0..4] + first, second, third, fourth = comment_representation.comments[0..4] - expect(subject.parent_comment).to be_nil - expect(first.parent_comment).to eq(subject) - expect(second.parent_comment).to eq(subject) + expect(comment_representation.parent_comment).to be_nil + expect(first.parent_comment).to eq(comment_representation) + expect(second.parent_comment).to eq(comment_representation) expect(third.parent_comment).to eq(first) expect(fourth.parent_comment).to eq(first) end end describe '#to_hash' do - it do - expect(subject.to_hash).to match( + specify do + expect(comment_representation.to_hash).to match( a_hash_including( id: 9, + author_name: 'root', author_email: 'test.user@example.com', author_username: 'username', note: 'is this a new line?', -- GitLab