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