Commit b88e01ac authored by ng's avatar ng

fix #5 - make sure we really find the project, even if we have more projects...

fix #5 - make sure we really find the project, even if we have more projects with a name like the chosen one that fit on one pagination
parent f1179dd1
Pipeline #23004 passed with stage
in 1 minute and 29 seconds
......@@ -127,7 +127,19 @@ module SchleuderGitlabTicketing
end
def project
@project ||= gitlab.search_projects(@config['project']).find{|p| p.namespace.name == @config['namespace'] && p.name == @config['project'] }
@project ||= begin
p = nil
# do a first lookup via group, otherwise it might be also in another namespace and thus
# we must do a more expensive lookup
group = gitlab.groups(name: @config['namespace']).find{|g| g.name == @config['namespace'] }
if group
p = gitlab.group_projects(group.id).find{|p| p.namespace.name == @config['namespace'] && p.name == @config['project'] }
end
unless p
p = gitlab.search_projects(@config['project']).auto_paginate.find{|p| p.namespace.name == @config['namespace'] && p.name == @config['project'] }
end
p
end
rescue Gitlab::Error::NotFound => e
nil
end
......
......@@ -44,9 +44,15 @@ describe SchleuderGitlabTicketing::List do
list2_project = double
allow(list2_project).to receive(:name).and_return('testing')
allow(list2_project).to receive_message_chain(:namespace,:name).and_return('support')
allow(gitlab).to receive(:search_projects).with('tickets').and_return([list1_project])
allow(gitlab).to receive(:search_projects).with('testing').and_return([list2_project])
allow(gitlab).to receive(:search_projects).with('tickets2').and_return([list2_project])
support_group = double
allow(support_group).to receive(:name).and_return('support')
allow(support_group).to receive(:id).and_return(123)
allow(gitlab).to receive(:groups).with(name: 'support').and_return([support_group])
allow(gitlab).to receive(:group_projects).with(123).and_return([list1_project])
res = double
allow(res).to receive(:auto_paginate).and_return([list2_project])
allow(gitlab).to receive(:search_projects).with('testing').and_return(res)
allow(gitlab).to receive(:search_projects).with('tickets2').and_return(res)
allow_any_instance_of(Gitlab::Error::NotFound).to receive(:build_error_message).and_return('bla')
allow(gitlab).to receive(:search_projects).with('tickets3').and_raise(Gitlab::Error::NotFound,'bla')
end
......@@ -74,7 +80,11 @@ describe SchleuderGitlabTicketing::List do
allow(list1_project).to receive(:id).and_return(123)
allow(list1_project).to receive_message_chain(:namespace,:name).and_return('support')
allow(list1_project).to receive_message_chain(:namespace,:id).and_return(91)
allow(gitlab).to receive(:search_projects).with('tickets').and_return([list1_project])
group = double
allow(group).to receive(:name).and_return('support')
allow(group).to receive(:id).and_return(987)
allow(gitlab).to receive(:groups).with(name: 'support').and_return([group])
allow(gitlab).to receive(:group_projects).with(987).and_return([list1_project])
end
context 'ignores spam' do
it 'drops spam' do
......
......@@ -17,7 +17,10 @@ describe Schleuder::Filters do
allow(list1_project).to receive(:name).and_return('tickets')
allow(list1_project).to receive(:id).and_return(123)
allow(list1_project).to receive_message_chain(:namespace,:name).and_return('support')
allow(gitlab).to receive(:search_projects).with('tickets').and_return([list1_project])
allow(gitlab).to receive(:groups).with(name: 'support').and_return([])
res = double
allow(res).to receive(:auto_paginate).and_return([list1_project])
allow(gitlab).to receive(:search_projects).with('tickets').and_return(res)
end
context 'with processing' do
before(:each) 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