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
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)
let(:project) { create(:project, :public, :repository) }
allow(project.team).to receive(:contributor?).with(user).and_return(true)
context 'when user is a member of project' do
let(:user) { create(:user) }
expect(described_class.new(project).contributor?(user)).to eq(true)
before do
project.add_developer(user)
end
it "returns true if a user isn't a contributor" do
user = build_stubbed(:author)
it { expect(described_class.new(project).contributor?(user)).to eq(false) }
end
allow(project.team).to receive(:contributor?).with(user).and_return(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
expect(described_class.new(project).contributor?(user)).to eq(false)
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