Commit aff9dadf authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'bug/jira_issue_closing' into 'master'

Fix JIRA issue closing bug
parents 2b9a9d4c e496b147
v 7.0.0
- Fix bug in JIRA Issue closing triggered by commit messages
v 6.9.3 v 6.9.3
- Fix check CI status only when CI service is enabled(Daniel Aquino) - Fix check CI status only when CI service is enabled(Daniel Aquino)
......
...@@ -42,4 +42,8 @@ module MergeRequestsHelper ...@@ -42,4 +42,8 @@ module MergeRequestsHelper
"Branches: #{@merge_request.source_branch} #{separator} #{@merge_request.target_branch}" "Branches: #{@merge_request.source_branch} #{separator} #{@merge_request.target_branch}"
end end
end end
def issues_sentence(issues)
issues.map { |i| "##{i.iid}" }.to_sentence
end
end end
class JiraIssue
def initialize(issue_identifier)
@issue_identifier = issue_identifier
end
def to_s
@issue_identifier.to_s
end
def id
@issue_identifier.to_s
end
def iid
@issue_identifier.to_s
end
def ==(other)
other.is_a?(self.class) && (to_s == other.to_s)
end
end
...@@ -37,5 +37,5 @@ ...@@ -37,5 +37,5 @@
%i.icon-ok %i.icon-ok
Accepting this merge request will close #{@closes_issues.size == 1 ? 'issue' : 'issues'} Accepting this merge request will close #{@closes_issues.size == 1 ? 'issue' : 'issues'}
= succeed '.' do = succeed '.' do
!= gfm(@closes_issues.map { |i| "##{i.iid}" }.to_sentence) != gfm(issues_sentence(@closes_issues))
...@@ -24,7 +24,9 @@ module Gitlab ...@@ -24,7 +24,9 @@ module Gitlab
def issues_for project def issues_for project
if project.jira_tracker? if project.jira_tracker?
issues.uniq issues.uniq.map do |jira_identifier|
JiraIssue.new(jira_identifier)
end
else else
issues.map do |identifier| issues.map do |identifier|
project.issues.where(iid: identifier).first project.issues.where(iid: identifier).first
......
require 'spec_helper'
describe MergeRequestsHelper do
describe :issues_sentence do
subject { issues_sentence(issues) }
let(:issues) do
[build(:issue, iid: 1), build(:issue, iid: 2), build(:issue, iid: 3)]
end
it { should eq('#1, #2, and #3') }
context 'for JIRA issues' do
let(:issues) do
[JiraIssue.new('JIRA-123'), JiraIssue.new('JIRA-456'), JiraIssue.new('FOOBAR-7890')]
end
it { should eq('#JIRA-123, #JIRA-456, and #FOOBAR-7890') }
end
end
end
...@@ -71,6 +71,15 @@ describe Gitlab::ReferenceExtractor do ...@@ -71,6 +71,15 @@ describe Gitlab::ReferenceExtractor do
subject.issues_for(project).should == [@i0, @i1] subject.issues_for(project).should == [@i0, @i1]
end end
it 'returns JIRA issues for a JIRA-integrated project' do
project.stub(jira_tracker?: true)
subject.analyze('JIRA-123 and FOOBAR-4567')
subject.issues_for(project).should eq(
[JiraIssue.new('JIRA-123'), JiraIssue.new('FOOBAR-4567')]
)
end
it 'accesses valid merge requests' do it 'accesses valid merge requests' do
@m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'aaa') @m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'aaa')
@m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb') @m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb')
......
require 'spec_helper'
describe JiraIssue do
subject { JiraIssue.new('JIRA-123') }
its(:id) { should eq('JIRA-123') }
its(:iid) { should eq('JIRA-123') }
its(:to_s) { should eq('JIRA-123') }
describe :== do
specify { subject.should eq(JiraIssue.new('JIRA-123')) }
specify { subject.should_not eq(JiraIssue.new('JIRA-124')) }
it 'only compares with JiraIssues' do
subject.should_not eq('JIRA-123')
end
end
end
...@@ -50,7 +50,7 @@ describe JiraService, models: true do ...@@ -50,7 +50,7 @@ describe JiraService, models: true do
end end
it "should call JIRA API" do it "should call JIRA API" do
@jira_service.execute(@sample_data, "JIRA-123") @jira_service.execute(@sample_data, JiraIssue.new("JIRA-123"))
WebMock.should have_requested(:post, @api_url).with( WebMock.should have_requested(:post, @api_url).with(
body: /Issue solved with/ body: /Issue solved with/
).once ).once
......
...@@ -124,6 +124,17 @@ describe MergeRequest do ...@@ -124,6 +124,17 @@ describe MergeRequest do
subject.closes_issues.should be_empty subject.closes_issues.should be_empty
end end
context 'for a project with JIRA integration' do
let(:issue0) { JiraIssue.new('JIRA-123') }
let(:issue1) { JiraIssue.new('FOOBAR-4567') }
it 'returns sorted JiraIssues' do
subject.project.stub(default_branch: subject.target_branch)
subject.closes_issues.should eq([issue1, issue0])
end
end
end end
it_behaves_like 'an editable mentionable' do it_behaves_like 'an editable mentionable' do
......
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