2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ClosingIssueExtractor do
|
2021-01-03 14:25:43 +05:30
|
|
|
let_it_be_with_reload(:project) { create(:project) }
|
2022-10-11 01:57:18 +05:30
|
|
|
let_it_be_with_reload(:project2) { create(:project) }
|
2021-01-03 14:25:43 +05:30
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
|
|
|
let_it_be(:issue2) { create(:issue, project: project2) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:reference) { issue.to_reference }
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:cross_reference) { issue2.to_reference(project) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
subject { described_class.new(project, project.creator) }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
before_all do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(project.creator)
|
|
|
|
project.add_developer(project2.creator)
|
2018-11-18 11:00:15 +05:30
|
|
|
project2.add_maintainer(project.creator)
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
describe "#closed_by_message" do
|
|
|
|
context 'with a single reference' do
|
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (Closes #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Awesome commit (Closes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (closes #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Awesome commit (closes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Closed #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "closed #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "closed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Closing #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Closing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "closing #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "closing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Close #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Close: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "close #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "close: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (Fixes #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
2020-04-22 19:07:51 +05:30
|
|
|
message = "Awesome commit (fixes: #{reference})"
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (fixes #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Awesome commit (Fixes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Fixed #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Fixed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "fixed #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "fixed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Fixing #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Fixing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "fixing #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "fixing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Fix #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Fix: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "fix #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "fix: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (Resolves #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Awesome commit (Resolves: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (resolves #{reference})"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Awesome commit (resolves: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Resolved #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Resolved: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "resolved #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "resolved: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Resolving #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Resolving: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "resolving #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "resolving: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Resolve #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "Resolve: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "resolve #{reference}"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it do
|
|
|
|
message = "resolve: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it do
|
|
|
|
message = "Implement: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "Implements: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "Implemented: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "Implementing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "implement: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "implements: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "implemented: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "implementing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'with an external issue tracker reference' do
|
|
|
|
it 'extracts the referenced issue' do
|
|
|
|
jira_project = create(:jira_project, name: 'JIRA_EXT1')
|
2018-11-18 11:00:15 +05:30
|
|
|
jira_project.add_maintainer(jira_project.creator)
|
2016-04-02 18:10:28 +05:30
|
|
|
jira_issue = ExternalIssue.new("#{jira_project.name}-1", project: jira_project)
|
2016-11-24 13:41:30 +05:30
|
|
|
closing_issue_extractor = described_class.new(jira_project, jira_project.creator)
|
2016-04-02 18:10:28 +05:30
|
|
|
message = "Resolve #{jira_issue.to_reference}"
|
|
|
|
|
|
|
|
expect(closing_issue_extractor.closed_by_message(message)).to eq([jira_issue])
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
context "with a cross-project reference" do
|
|
|
|
it do
|
|
|
|
message = "Closes #{cross_reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a cross-project URL" do
|
|
|
|
it do
|
2017-09-10 17:25:29 +05:30
|
|
|
message = "Closes #{urls.project_issue_url(issue2.project, issue2)}"
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([issue2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context "with a cross-project fork reference" do
|
2021-01-03 14:25:43 +05:30
|
|
|
let(:forked_project) { Projects::ForkService.new(project, project2.creator).execute }
|
|
|
|
let(:fork_cross_reference) { issue.to_reference(forked_project) }
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
subject { described_class.new(forked_project, forked_project.creator) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
message = "Closes #{fork_cross_reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when target project has autoclose issues disabled' do
|
|
|
|
before do
|
|
|
|
project2.update!(autoclose_referenced_issues: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'omits the issue reference' do
|
|
|
|
message = "Closes #{cross_reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
context "with an invalid URL" do
|
|
|
|
it do
|
2017-09-10 17:25:29 +05:30
|
|
|
message = "Closes https://google.com#{urls.project_issue_path(issue2.project, issue2)}"
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(subject.closed_by_message(message)).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context "with an invalid keyword such as suffix insted of fix" do
|
|
|
|
it do
|
|
|
|
message = "suffix #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
context 'with multiple references' do
|
2021-01-03 14:25:43 +05:30
|
|
|
let_it_be(:other_issue) { create(:issue, project: project) }
|
|
|
|
let_it_be(:third_issue) { create(:issue, project: project) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:reference2) { other_issue.to_reference }
|
|
|
|
let(:reference3) { third_issue.to_reference }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
it 'fetches issues in single line message' do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Closes #{reference} and fix #{reference2}"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches comma-separated issues references in single line message' do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Closes #{reference}, closes #{reference2}"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches comma-separated issues numbers in single line message' do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Closes #{reference}, #{reference2} and #{reference3}"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'allows oxford commas (comma before and) when referencing multiple issues' do
|
|
|
|
message = "Closes #{reference}, #{reference2}, and #{reference3}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows spaces before commas when referencing multiple issues' do
|
|
|
|
message = "Closes #{reference} , #{reference2} , and #{reference3}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
it 'allows non-comma-separated issue numbers in single line message' do
|
|
|
|
message = "Closes #{reference} #{reference2} #{reference3}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows mixed comma-separated and non-comma-separated issue numbers in single line message' do
|
2020-04-22 19:07:51 +05:30
|
|
|
message = "Closes #{reference}, #{reference2} #{reference3}"
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'fetches issues in multi-line message' do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (closes #{reference})\nAlso fixes #{reference2}"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches issues in hybrid message' do
|
2015-09-11 14:41:01 +05:30
|
|
|
message = "Awesome commit (closes #{reference})\n"\
|
|
|
|
"Also fixing issues #{reference2}, #{reference3} and #4"
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, other_issue, third_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
it "fetches cross-project references" do
|
|
|
|
message = "Closes #{reference} and #{cross_reference}"
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue, issue2])
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "fetches cross-project URL references" do
|
2018-03-17 18:26:18 +05:30
|
|
|
message = "Closes #{urls.project_issue_url(issue2.project, issue2)}, #{reference} and #{urls.project_issue_url(other_issue.project, other_issue)}"
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
2018-03-17 18:26:18 +05:30
|
|
|
.to match_array([issue, issue2, other_issue])
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores invalid cross-project URL references" do
|
2017-09-10 17:25:29 +05:30
|
|
|
message = "Closes https://google.com#{urls.project_issue_path(issue2.project, issue2)} and #{reference}"
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.closed_by_message(message))
|
|
|
|
.to match_array([issue])
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
context "with autoclose referenced issues disabled" do
|
2022-10-11 01:57:18 +05:30
|
|
|
before_all do
|
2020-03-13 15:44:24 +05:30
|
|
|
project.update!(autoclose_referenced_issues: false)
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'excludes same project references' do
|
2020-03-13 15:44:24 +05:30
|
|
|
message = "Awesome commit (Closes #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([])
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
it 'includes issues from other projects with autoclose enabled' do
|
|
|
|
message = "Closes #{cross_reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue2])
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
def urls
|
2016-06-02 11:05:42 +05:30
|
|
|
Gitlab::Routing.url_helpers
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|