Commit 35d6b799 authored by Alessio Caiazza's avatar Alessio Caiazza

Fix contributors detection in changelog generation

The Changelog generation API provides a template that identifies if
the commit author is project member or a contributor.

This flag was never reporting an author as a contributor, regardless
of his or her project membership.

Changelog: fixed
parent 3ee03d28
...@@ -89,7 +89,7 @@ module Gitlab ...@@ -89,7 +89,7 @@ module Gitlab
end end
def contributor?(user) def contributor?(user)
@project.team.contributor?(user) @project.team.contributor?(user&.id)
end end
def category(name) def category(name)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Changelog::Config do RSpec.describe Gitlab::Changelog::Config do
include ProjectForksHelper
let(:project) { build_stubbed(:project) } let(:project) { build_stubbed(:project) }
describe '.from_git' do describe '.from_git' do
...@@ -66,20 +68,33 @@ RSpec.describe Gitlab::Changelog::Config do ...@@ -66,20 +68,33 @@ RSpec.describe Gitlab::Changelog::Config do
end end
describe '#contributor?' do describe '#contributor?' do
it 'returns true if a user is a contributor' do let(:project) { create(:project, :public, :repository) }
user = build_stubbed(:author)
allow(project.team).to receive(:contributor?).with(user).and_return(true)
expect(described_class.new(project).contributor?(user)).to eq(true) context 'when user is a member of project' do
end let(:user) { create(:user) }
it "returns true if a user isn't a contributor" do before do
user = build_stubbed(:author) 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
end end
......
...@@ -76,7 +76,7 @@ RSpec.describe Repositories::ChangelogService do ...@@ -76,7 +76,7 @@ RSpec.describe Repositories::ChangelogService do
recorder = ActiveRecord::QueryRecorder.new { service.execute } recorder = ActiveRecord::QueryRecorder.new { service.execute }
changelog = project.repository.blob_at('master', 'CHANGELOG.md')&.data 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') expect(changelog).to include('Title 1', 'Title 2')
end 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