2014-09-17 13:08:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::ClosingIssueExtractor, lib: true do
|
2015-05-21 16:35:15 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-12-02 12:48:39 -05:00
|
|
|
let(:project2) { create(:project) }
|
2015-05-21 16:35:15 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
2015-12-02 12:48:39 -05:00
|
|
|
let(:issue2) { create(:issue, project: project2) }
|
2015-05-21 16:35:15 -04:00
|
|
|
let(:reference) { issue.to_reference }
|
2015-12-02 12:48:39 -05:00
|
|
|
let(:cross_reference) { issue2.to_reference(project) }
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
subject { described_class.new(project, project.creator) }
|
|
|
|
|
2015-12-02 12:48:39 -05:00
|
|
|
before do
|
2016-03-17 16:39:50 -04:00
|
|
|
project.team << [project.creator, :developer]
|
2015-12-02 12:48:39 -05:00
|
|
|
project2.team << [project.creator, :master]
|
|
|
|
end
|
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
describe "#closed_by_message" do
|
2014-09-17 13:08:35 -04:00
|
|
|
context 'with a single reference' do
|
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (Closes #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (Closes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2014-09-17 13:08:35 -04:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (closes #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (closes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2014-09-17 13:08:35 -04:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Closed #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "closed #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "closed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Closing #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Closing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "closing #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "closing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Close #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Close: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "close #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "close: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (Fixes #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (Fixes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2014-09-17 13:08:35 -04:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (fixes #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (Fixes: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2014-09-17 13:08:35 -04:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Fixed #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Fixed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "fixed #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "fixed: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Fixing #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Fixing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "fixing #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "fixing: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Fix #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Fix: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "fix #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "fix: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (Resolves #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (Resolves: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (resolves #{reference})"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Awesome commit (resolves: #{reference})"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Resolved #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Resolved: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "resolved #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "resolved: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Resolving #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Resolving: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "resolving #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "resolving: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Resolve #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2015-02-05 16:04:49 -05:00
|
|
|
end
|
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "Resolve: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2015-02-05 16:04:49 -05:00
|
|
|
it do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "resolve #{reference}"
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
2016-01-25 11:27:03 -05:00
|
|
|
|
2016-04-07 08:47:29 -04:00
|
|
|
it do
|
|
|
|
message = "resolve: #{reference}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue])
|
|
|
|
end
|
|
|
|
|
2016-01-25 11:27:03 -05:00
|
|
|
context 'with an external issue tracker reference' do
|
|
|
|
it 'extracts the referenced issue' do
|
|
|
|
jira_project = create(:jira_project, name: 'JIRA_EXT1')
|
|
|
|
jira_issue = ExternalIssue.new("#{jira_project.name}-1", project: jira_project)
|
|
|
|
closing_issue_extractor = described_class.new jira_project
|
|
|
|
message = "Resolve #{jira_issue.to_reference}"
|
|
|
|
|
|
|
|
expect(closing_issue_extractor.closed_by_message(message)).to eq([jira_issue])
|
|
|
|
end
|
|
|
|
end
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
2015-12-02 12:48:39 -05:00
|
|
|
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
|
2015-12-03 08:00:00 -05:00
|
|
|
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)}"
|
2015-12-02 12:48:39 -05:00
|
|
|
expect(subject.closed_by_message(message)).to eq([issue2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an invalid URL" do
|
|
|
|
it do
|
2015-12-03 08:00:00 -05:00
|
|
|
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)}"
|
2015-12-02 12:48:39 -05:00
|
|
|
expect(subject.closed_by_message(message)).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-17 13:08:35 -04:00
|
|
|
context 'with multiple references' do
|
|
|
|
let(:other_issue) { create(:issue, project: project) }
|
|
|
|
let(:third_issue) { create(:issue, project: project) }
|
2015-05-21 16:35:15 -04:00
|
|
|
let(:reference2) { other_issue.to_reference }
|
|
|
|
let(:reference3) { third_issue.to_reference }
|
2014-09-17 13:08:35 -04:00
|
|
|
|
|
|
|
it 'fetches issues in single line message' do
|
2015-05-26 15:55:26 -04:00
|
|
|
message = "Closes #{reference} and fix #{reference2}"
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-14 07:46:17 -04:00
|
|
|
to match_array([issue, other_issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches comma-separated issues references in single line message' do
|
2015-05-26 15:55:26 -04:00
|
|
|
message = "Closes #{reference}, closes #{reference2}"
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-14 07:46:17 -04:00
|
|
|
to match_array([issue, other_issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches comma-separated issues numbers in single line message' do
|
2015-05-26 15:55:26 -04:00
|
|
|
message = "Closes #{reference}, #{reference2} and #{reference3}"
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-14 07:46:17 -04:00
|
|
|
to match_array([issue, other_issue, third_issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches issues in multi-line message' do
|
2015-05-26 15:55:26 -04:00
|
|
|
message = "Awesome commit (closes #{reference})\nAlso fixes #{reference2}"
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-14 07:46:17 -04:00
|
|
|
to match_array([issue, other_issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches issues in hybrid message' do
|
2015-05-21 16:35:15 -04:00
|
|
|
message = "Awesome commit (closes #{reference})\n"\
|
2015-05-26 15:55:26 -04:00
|
|
|
"Also fixing issues #{reference2}, #{reference3} and #4"
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-14 07:46:17 -04:00
|
|
|
to match_array([issue, other_issue, third_issue])
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
2015-12-02 12:48:39 -05:00
|
|
|
|
|
|
|
it "fetches cross-project references" do
|
|
|
|
message = "Closes #{reference} and #{cross_reference}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue, issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fetches cross-project URL references" do
|
2015-12-03 08:00:00 -05:00
|
|
|
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
|
2015-12-02 12:48:39 -05:00
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue, issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores invalid cross-project URL references" do
|
2015-12-03 08:00:00 -05:00
|
|
|
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
|
2015-12-02 12:48:39 -05:00
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue])
|
|
|
|
end
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|
|
|
|
end
|
2015-12-03 08:00:00 -05:00
|
|
|
|
|
|
|
def urls
|
2016-03-24 12:00:26 -04:00
|
|
|
Gitlab::Routing.url_helpers
|
2015-12-03 08:00:00 -05:00
|
|
|
end
|
2014-09-17 13:08:35 -04:00
|
|
|
end
|