2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe Gitlab::ClosingIssueExtractor, lib: true do
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:project) { create(:project) }
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:project2) { create(:project) }
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:issue2) { create(:issue, project: project2) }
|
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) }
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
before do
|
|
|
|
project2.team << [project.creator, :master]
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
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
|
|
|
|
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([issue2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an invalid URL" do
|
|
|
|
it do
|
|
|
|
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)}"
|
|
|
|
expect(subject.closed_by_message(message)).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
context 'with multiple references' do
|
|
|
|
let(:other_issue) { create(:issue, project: project) }
|
|
|
|
let(:third_issue) { create(:issue, project: project) }
|
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
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-24 18:46:33 +05:30
|
|
|
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
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-24 18:46:33 +05:30
|
|
|
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
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-24 18:46:33 +05:30
|
|
|
to match_array([issue, other_issue, third_issue])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-24 18:46:33 +05:30
|
|
|
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
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
2015-10-24 18:46:33 +05:30
|
|
|
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}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue, issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fetches cross-project URL references" do
|
|
|
|
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue, issue2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores invalid cross-project URL references" do
|
|
|
|
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
|
|
|
|
|
|
|
|
expect(subject.closed_by_message(message)).
|
|
|
|
to match_array([issue])
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
def urls
|
|
|
|
Gitlab::Application.routes.url_helpers
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|