Commit f5c920ca authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'fix-changelog-contributor' into 'master'

Fix contributors detection in changelog generation

See merge request gitlab-org/gitlab!68938
parents 1ba7aa96 35d6b799
......@@ -89,7 +89,7 @@ module Gitlab
end
def contributor?(user)
@project.team.contributor?(user)
@project.team.contributor?(user&.id)
end
def category(name)
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Gitlab::Changelog::Config do
include ProjectForksHelper
let(:project) { build_stubbed(:project) }
describe '.from_git' do
......@@ -66,20 +68,33 @@ RSpec.describe Gitlab::Changelog::Config do
end
describe '#contributor?' do
it 'returns true if a user is a contributor' do
user = build_stubbed(:author)
allow(project.team).to receive(:contributor?).with(user).and_return(true)
let(:project) { create(:project, :public, :repository) }
expect(described_class.new(project).contributor?(user)).to eq(true)
end
context 'when user is a member of project' do
let(:user) { create(:user) }
it "returns true if a user isn't a contributor" do
user = build_stubbed(:author)
before do
project.add_developer(user)
end
allow(project.team).to receive(:contributor?).with(user).and_return(false)
it { expect(described_class.new(project).contributor?(user)).to eq(false) }
end
expect(described_class.new(project).contributor?(user)).to eq(false)
context 'when user has at least one merge request merged into default_branch' do
let(:contributor) { create(:user) }
let(:user_without_access) { create(:user) }
let(:user_fork) { fork_project(project, contributor, repository: true) }
before do
create(:merge_request, :merged,
author: contributor,
target_project: project,
source_project: user_fork,
target_branch: project.default_branch.to_s)
end
it { expect(described_class.new(project).contributor?(contributor)).to eq(true) }
it { expect(described_class.new(project).contributor?(user_without_access)).to eq(false) }
end
end
......
......@@ -76,7 +76,7 @@ RSpec.describe Repositories::ChangelogService do
recorder = ActiveRecord::QueryRecorder.new { service.execute }
changelog = project.repository.blob_at('master', 'CHANGELOG.md')&.data
expect(recorder.count).to eq(11)
expect(recorder.count).to eq(9)
expect(changelog).to include('Title 1', 'Title 2')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment