/
project_controller.rb
1586 lines (1412 loc) · 53.8 KB
/
project_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Webui
class ProjectController < WebuiController
include HasComments
include Webui::WebuiHelper
include Webui::RequestHelper
include Webui::ProjectHelper
before_filter :load_project_info, :only => [:show]
before_filter :require_project, :except => [:repository_arch_list,
:autocomplete_projects, :autocomplete_incidents, :clear_failed_comment, :edit_comment_form, :index,
:list, :list_all, :list_public, :new, :package_buildresult, :save_new, :save_prjconf,
:rebuild_time_png, :new_incident, :show]
before_filter :require_login, :only => [:save_new, :toggle_watch, :delete, :new]
before_filter :require_available_architectures, :only => [:add_repository, :add_repository_from_default_list,
:edit_repository, :update_target]
before_filter :load_releasetargets, :only => [ :show, :incident_request_dialog, :release_repository_dialog ]
prepend_before_filter :lockout_spiders, :only => [:requests, :rebuild_time]
def index
redirect_to :action => 'list_public'
end
def list_all
list and return
end
def list_public
params['excludefilter'] = 'home:'
list and return
end
def all_projects
@important_projects = []
# return all projects and their title
ret = {}
atype = AttribType.find_by_namespace_and_name('OBS', 'VeryImportantProject')
important = {}
Project.find_by_attribute_type(atype).pluck("projects.id").each do |p|
important[p] = true
end
projects = Project.where("name <> ?", "deleted").pluck(:id, :name, :title)
projects.each do |id, name, title|
@important_projects << [name, title] if important[id]
ret[name] = title
end
ret
end
def list
@main_projects = []
@excl_projects = []
if params['excludefilter'] and params['excludefilter'] != 'undefined'
@excludefilter = params['excludefilter']
else
@excludefilter = nil
end
all_projects.each do |name, title|
if @excludefilter && name.start_with?(@excludefilter)
@excl_projects << [name, title]
else
@main_projects << [name, title]
end
end
# excl and main are sorted by datatable, but important need to be in order
@important_projects.sort! {|a,b| a[0] <=> b[0] }
if @spider_bot
render :list_simple, status: params[:nextstatus]
else
render :list, status: params[:nextstatus]
end
end
def autocomplete_projects
required_parameters :term
get_filtered_projectlist params[:term], ''
render :json => @projects
end
def autocomplete_incidents
required_parameters :term
get_filtered_projectlist params[:term], '', :only_incidents => true
render :json => @projects
end
def autocomplete_packages
required_parameters :term
if valid_package_name_read?( params[:term] ) or params[:term] == ''
render :json => @project.packages.select{|p| p.name.index(params[:term]) }.map{|p| p.name}
else
render :text => '[]'
end
end
def autocomplete_repositories
render :json => @project.repositories
end
def project_key(a)
a = a.downcase
if a[0..4] == 'home:'
a = 'zz' + a
end
return a
end
private :project_key
def get_filtered_projectlist(filterstring, excludefilter='', opts={})
opts = {:only_incidents => false}.merge(opts)
# remove illegal xpath characters
filterstring.gsub!(/[\[\]\n]/, '')
filterstring.gsub!(/[']/, ''')
filterstring.gsub!(/["]/, '"')
predicate = filterstring.empty? ? '' : "starts-with(@name, '#{filterstring}')"
predicate += ' and ' if !predicate.empty? and !excludefilter.blank?
predicate += "not(starts-with(@name,'#{excludefilter}'))" if !excludefilter.blank?
predicate += ' and ' if !predicate.empty?
if opts[:only_incidents]
predicate += "@kind='maintenance_incident')"
else
predicate += "not(@kind='maintenance_incident')" # Filter all maintenance incidents
end
result = Collection.find(:id, :what => 'project', :predicate => predicate)
@projects = Array.new
result.each { |p| @projects << p.name }
@projects = @projects.sort_by { |a| project_key a }
end
private :get_filtered_projectlist
def users
@users = @project.users
@groups = @project.groups
@roles = Role.local_roles
end
def subprojects
@subprojects = Hash.new
sub_names = Collection.find :id, :what => 'project', :predicate => "starts-with(@name,'#{@project}:')"
sub_names.each do |sub|
@subprojects[sub.name] = WebuiProject.find( sub.name )
end
@subprojects = @subprojects.sort # Sort by hash key for better display
@parentprojects = Hash.new
parent_names = @project.name.split ':'
parent_names.each_with_index do |parent, idx|
parent_name = parent_names.slice(0, idx+1).join(':')
unless [@project.name, 'home'].include?( parent_name )
parent_project = WebuiProject.find( parent_name )
@parentprojects[parent_name] = parent_project unless parent_project.blank?
end
end
@parentprojects = @parentprojects.sort # Sort by hash key for better display
end
def attributes
if @project.is_remote?
@attributes = nil
else
@attributes = Attribute.find(:project => @project.name)
end
end
def new
@namespace = params[:ns]
@project_name = params[:project]
if @namespace
begin
@project = WebuiProject.find(@namespace)
if @namespace == "home:#{User.current.login}" and not @project
@pagetitle = "Your home project doesn't exist yet. You can create it now"
@project_name = @namespace
end
rescue ActiveXML::Transport::Error
flash[:error] = "Invalid namespace name '#{@namespace}'"
redirect_back_or_to :controller => 'project', :action => 'list_public' and return
end
end
if @project_name =~ /home:(.+)/
@project_title = "#$1's Home Project"
else
@project_title = ''
end
end
def new_incident
required_parameters :ns
target_project = ''
begin
path = "/source/#{CGI.escape(params[:ns])}/?cmd=createmaintenanceincident"
result = ActiveXML::Node.new(frontend.transport.direct_http(URI(path), :method => 'POST', :data => ''))
result.each("/status/data[@name='targetproject']") { |n| target_project = n.text }
rescue ActiveXML::Transport::Error => e
flash[:error] = e.summary
redirect_to :action => 'show', :project => params[:ns] and return
end
flash[:success] = "Created maintenance incident project #{target_project}"
redirect_to :action => 'show', :project => target_project and return
end
def new_package
end
def new_package_branch
@remote_projects = Project.where.not(remoteurl: nil).pluck(:id, :name, :title)
end
def incident_request_dialog
#TODO: Currently no way to find out where to send until the project 'maintained' relationship
# is really used. The API will find out magically here though.
render_dialog
end
def new_incident_request
begin
req = BsRequest.new(:project => params[:project], :type => 'maintenance_incident', :description => params[:description])
req.save(create: true)
flash[:success] = 'Created maintenance release request'
rescue ActiveXML::Transport::NotFoundError, ActiveXML::Transport::Error => e
flash[:error] = e.summary
redirect_back_or_to :action => 'show', :project => params[:project] and return
end
redirect_to :action => 'show', :project => params[:project]
end
def release_request_dialog
render_dialog
end
def new_release_request
if params[:skiprequest]
# FIXME2.3: do it directly here, api function missing
else
begin
req = BsRequest.new(:project => params[:project], :type => 'maintenance_release', :description => params[:description])
req.save(create: true)
flash[:success] = "Created maintenance release request <a href='#{url_for(:controller => 'request', :action => 'show', :id => req.value('id'))}'>#{req.value('id')}</a>"
rescue ActiveXML::Transport::NotFoundError => e
flash[:error] = e.summary
redirect_to(:action => 'show', :project => params[:project]) and return
rescue ActiveXML::Transport::Error => e
flash[:error] = e.summary
redirect_back_or_to :action => 'show', :project => params[:project] and return
end
end
redirect_to :action => 'show', :project => params[:project]
end
def find_packages_info
ret = Array.new
packages=@pro.expand_all_packages
prj_names = Hash.new
Project.where(id: packages.map { |a| a[1] }.uniq).pluck(:id, :name).each do |id, name|
prj_names[id] = name
end
packages.each do |name, prj_id|
if prj_id==@pro.id
ret << [name, nil]
else
ret << [name, prj_names[prj_id]]
end
end
ret
end
def find_maintenance_infos
pm = @pro.maintenance_project
@project_maintenance_project = pm.name if pm
@is_maintenance_project = @pro.is_maintenance?
if @is_maintenance_project
mi = DbProjectType.find_by_name!('maintenance_incident')
subprojects = Project.where("projects.name like ?", @pro.name + ":%").
where(type_id: mi.id).joins(:repositories => :release_targets).
where("release_targets.trigger = 'maintenance'")
@open_maintenance_incidents = subprojects.pluck("projects.name").sort.uniq
@maintained_projects = []
@pro.maintained_projects.each do |mp|
@maintained_projects << mp.name
end
end
@is_incident_project = @pro.is_maintenance_incident?
if @is_incident_project
rel = BsRequestCollection.new(project: @pro.name, states: ['new', 'review'], types: ['maintenance_release'], roles: ['source'])
@open_release_requests = rel.ids
end
end
def find_nr_of_problems
begin
result = ActiveXML.backend.direct_http("/build/#{URI.escape(@pro.name)}/_result?view=status&code=failed&code=broken&code=unresolvable")
rescue ActiveXML::Transport::NotFoundError
return 0
end
ret = {}
Xmlhash.parse(result).elements('result') do |r|
r.elements('status') { |p| ret[p['package']] = 1 }
end
ret.keys.size
end
def load_project_info
return unless check_valid_project_name
@pro = Project.find_by_name(params[:project])
return render_project_missing unless @pro
find_maintenance_infos
@project = WebuiProject.new(@pro.to_axml)
@packages = find_packages_info.map { |p| p[0] }.sort
@linking_projects = @pro.find_linking_projects.map { |p| p.name }
reqs = @pro.request_ids_by_class
@requests = (reqs['reviews'] + reqs['targets'] + reqs['incidents'] + reqs['maintenance_release']).sort.uniq
@nr_of_problem_packages = find_nr_of_problems
end
def show
required_parameters :project
@bugowners_mail = []
@project.bugowners.each do |bugowner|
mail = bugowner.email
@bugowners_mail.push(mail.to_s) if mail
end unless @spider_bot
# An incident has a patchinfo if there is a package 'patchinfo' with file '_patchinfo', try to find that:
@has_patchinfo = false
@packages.each do |pkg_element|
if pkg_element == 'patchinfo'
Webui::Package.find(pkg_element, :project => @project).files.each do |pkg_file|
@has_patchinfo = true if pkg_file[:name] == '_patchinfo'
end
end
end
sort_comments(@project.api_obj.comments)
render :show, status: params[:nextstatus] if params[:nextstatus]
end
def comment_object
@project # used by HasComments mixin
end
def load_releasetargets
@releasetargets = []
@project.each_repository do |repo|
@releasetargets.push(repo.releasetarget.value('project') + '/' + repo.releasetarget.value('repository')) if repo.has_element?('releasetarget')
end
end
def linking_projects
# TODO: remove this ajax call and replace it with a jquery dialog
Rails.cache.delete('%s_linking_projects' % @project.name) if discard_cache?
@linking_projects = Rails.cache.fetch('%s_linking_projects' % @project.name, :expires_in => 30.minutes) do
@project.linking_projects
end
render_dialog
end
# TODO we need the architectures in api/distributions
def add_repository_from_default_list
@distributions = Distribution.find(:all)
if @distributions.all_vendors.length < 1
if User.current.is_admin?
flash.now[:notice] = "There are no distributions configured! Check out <a href=\"/configuration/connect_instance\">Configuration > Interconnect</a>"
else
redirect_to :controller => 'project', :action => 'add_repository', :project => @project
end
end
end
def add_repository
@torepository = params[:torepository]
end
def add_person
@roles = Role.local_roles
end
def add_group
@roles = Role.local_roles
end
def load_buildresult(cache = true)
unless cache
Buildresult.free_cache( :project => params[:project], :view => 'summary' )
end
unless @spider_bot
@buildresult = Buildresult.find(:project => params[:project], :view => 'summary')
end
@repohash = Hash.new
@statushash = Hash.new
@repostatushash = Hash.new
@packagenames = Array.new
@buildresult.to_hash.elements('result') do |result|
repo = result['repository']
arch = result['arch']
# repository status cache
@repostatushash[repo] ||= Hash.new
@repostatushash[repo][arch] = Hash.new
if result.has_key? 'state'
if result.has_key? 'dirty'
@repostatushash[repo][arch] = 'outdated_' + result['state']
else
@repostatushash[repo][arch] = result['state']
end
end
end if @buildresult
if @buildresult
@buildresult = @buildresult.to_a
else
@buildresult = Array.new
end
end
protected :load_buildresult
def buildresult
check_ajax
load_buildresult false
render :partial => 'buildstatus'
end
def delete_dialog
@linking_projects = @project.linking_projects
render_dialog
end
def delete
begin
if params[:force] == '1'
@project.delete :force => 1
else
@project.delete
end
Rails.cache.delete('%s_packages_mainpage' % @project)
Rails.cache.delete('%s_problem_packages' % @project)
flash[:notice] = "Project '#{@project}' was removed successfully"
rescue ActiveXML::Transport::Error => e
flash[:error] = e.summary
end
if @project.project_type != 'maintenance'
parent_projects = @project.parent_projects()
if parent_projects.present?
redirect_to :action => 'show', :project => parent_projects[parent_projects.length - 1][0]
else
redirect_to :action => 'list_public'
end
else
redirect_to :action => 'show', :project => @project
end
end
def repository_arch_list
@repository_arch_list = Hash.new
@project.each_repository do |repo|
@repository_arch_list[repo.name] = repo.archs.sort.uniq
end
return @repository_arch_list
end
private :repository_arch_list
def edit_repository
check_ajax
repo = @project.repository[params[:repository]]
redirect_back_or_to(:controller => 'project', :action => 'repositories', :project => @project) and return if not repo
# Merge project repo's arch list with currently available arches from API. This needed as you want
# to keep currently non-working arches in the project meta.
# Prepare a list of recommended architectures
@recommended_arch_list = @available_architectures.each.map{|arch| arch.name if arch.recommended == 'true'
}
@repository_arch_hash = Hash.new
@available_architectures.each {|arch| @repository_arch_hash[arch.name] = false }
repository_arch_list()[repo.name].each {|arch| @repository_arch_hash[arch] = true }
render(:partial => 'edit_repository', :locals => {:repository => repo, :error => nil})
end
def update_target
repo = @project.repository[params[:repo]]
if params[:arch]
repo.archs = params[:arch].keys
else
repo.archs = []
end
# Merge project repo's arch list with currently available arches from API. This needed as you want
# to keep currently non-working arches in the project meta.
@repository_arch_hash = Hash.new
@available_architectures.each {|arch| @repository_arch_hash[arch.name] = false }
repository_arch_list()[repo.name].each {|arch| @repository_arch_hash[arch] = true }
begin
@project.save
render :partial => 'edit_repository', :locals => { :repository => repo, :has_data => true }
rescue => e
render :partial => 'edit_repository', :locals => { :repository => repo, :error => "#{e.summary}" }
end
end
def repositories
if @project.is_remote?
# TODO support flagdetails for remote instances in the API
flash[:error] = "You can't show repositories for remote instances"
redirect_to :action => :show, :project => params[:project]
return
end
# overwrite @project with different view
# TODO to get this cached we need to make sure it gets purged on repo updates
@project = WebuiProject.find( params[:project], :view => :flagdetails )
end
def repository_state
# Get cycles of the repository build dependency information
#
@repocycles = Hash.new
@repositories = Array.new
if params[:repository]
@repositories << params[:repository]
elsif @project.has_element? :repository
@project.each_repository { |repository| @repositories << repository.name }
end
@project.each_repository do |repository|
next unless @repositories.include? repository.name
@repocycles[repository.name] = Hash.new
repository.each_arch do |arch|
cycles = Array.new
# skip all packages via package=- to speed up the api call, we only parse the cycles anyway
deps = BuilddepInfo.find(:project => @project.name, :package => '-', :repository => repository.name, :arch => arch)
nr_cycles = 0
if deps and deps.has_element? :cycle
packages = Hash.new
deps.each_cycle do |cycle|
current_cycles = Array.new
cycle.each_package do |p|
p = p.text
if packages.has_key? p
current_cycles << packages[p]
end
end
current_cycles.uniq!
if current_cycles.empty?
nr_cycles += 1
nr_cycle = nr_cycles
elsif current_cycles.length == 1
nr_cycle = current_cycles[0]
else
logger.debug "HELP! #{current_cycles.inspect}"
end
cycle.each_package do |p|
packages[p.text] = nr_cycle
end
end
end
cycles = Array.new
1.upto(nr_cycles) do |i|
list = Array.new
packages.each do |package,cycle|
list.push(package) if cycle == i
end
cycles << list.sort
end
@repocycles[repository.name][arch.text] = cycles unless cycles.empty?
end
end
end
def rebuild_time
required_parameters :repository, :arch
load_project_info
@repository = params[:repository]
@arch = params[:arch]
@hosts = begin Integer(params[:hosts] || '40') rescue 40 end
@scheduler = params[:scheduler] || 'needed'
unless ['fifo', 'lifo', 'random', 'btime', 'needed', 'neededb', 'longest_data', 'longested_triedread', 'longest'].include? @scheduler
flash[:error] = 'Invalid scheduler type, check mkdiststats docu - aehm, source'
redirect_to :action => :show, :project => @project
return
end
bdep = BuilddepInfo.find(:project => @project.name, :repository => @repository, :arch => @arch)
jobs = Jobhislist.find(:project => @project.name, :repository => @repository, :arch => @arch,
:limit => @packages.size * 3, :code => ['succeeded', 'unchanged'])
unless bdep and jobs
flash[:error] = "Could not collect infos about repository #{@repository}/#{@arch}"
redirect_to :action => :show, :project => @project
return
end
indir = Dir.mktmpdir
f = File.open(indir + '/_builddepinfo.xml', 'w')
f.write(bdep.dump_xml)
f.close
f = File.open(indir + '/_jobhistory.xml', 'w')
f.write(jobs.dump_xml)
f.close
outdir = Dir.mktmpdir
logger.debug "cd #{Rails.root.join('vendor', 'diststats').to_s} && perl ./mkdiststats --srcdir=#{indir} --destdir=#{outdir}
--outfmt=xml #{@project.name}/#{@repository}/#{@arch} --width=910
--buildhosts=#{@hosts} --scheduler=#{@scheduler}"
fork do
Dir.chdir(Rails.root.join('vendor', 'diststats'))
system('perl', './mkdiststats', "--srcdir=#{indir}", "--destdir=#{outdir}",
'--outfmt=xml', "#{@project.name}/#{@repository}/#{@arch}", '--width=910',
"--buildhosts=#{@hosts}", "--scheduler=#{@scheduler}")
end
Process.wait
f=File.open(outdir + '/rebuild.png')
png=f.read
f.close
@pngkey = Digest::MD5.hexdigest( params.to_s )
Rails.cache.write('rebuild-%s.png' % @pngkey, png)
f=File.open(outdir + '/longest.xml')
longest = ActiveXML::Node.new(f.read)
@timings = Hash.new
longest.timings.each_package do |p|
@timings[p.value(:name)] = [p.value(:buildtime), p.value(:finished)]
end
@rebuildtime = Integer(longest.value :rebuildtime)
f.close
@longestpaths = Array.new
longest.longestpath.each_path do |path|
currentpath = Array.new
path.each_package do |p|
currentpath << p.text
end
@longestpaths << currentpath
end
# we append 4 empty paths, so there are always at least 4 in the array
# to simplify the view code
4.times { @longestpaths << Array.new }
FileUtils.rm_rf indir
FileUtils.rm_rf outdir
end
def rebuild_time_png
required_parameters :key
key = params[:key]
png = Rails.cache.read('rebuild-%s.png' % key)
headers['Content-Type'] = 'image/png'
send_data(png, :type => 'image/png', :disposition => 'inline')
end
def packages
headers['Status'] = '301 Moved Permanently'
redirect_to :action => 'show', :project => @project
end
def requests
@requests = @project.request_ids_by_class
@default_request_type = params[:type] if params[:type]
@default_request_state = params[:state] if params[:state]
end
def save_new
if params[:name].blank? || !valid_project_name?( params[:name] )
flash[:error] = "Invalid project name '#{params[:name]}'."
redirect_to :action => 'new', :ns => params[:ns] and return
end
project_name = params[:name].strip
project_name = params[:ns].strip + ':' + project_name.strip if params[:ns]
if WebuiProject.exists? project_name
flash[:error] = "Project '#{project_name}' already exists."
redirect_to :action => 'new', :ns => params[:ns] and return
end
#store project
@project = WebuiProject.new(name: project_name)
@project.title.text = params[:title]
@project.description.text = params[:description]
@project.set_project_type('maintenance') if params[:maintenance_project]
if params[:remoteurl]
@project.add_element('remoteurl').text = params[:remoteurl]
end
if params[:access_protection]
@project.add_element 'access'
@project.access.add_element 'disable'
end
if params[:source_protection]
@project.add_element 'sourceaccess'
@project.sourceaccess.add_element 'disable'
end
if params[:disable_publishing]
@project.add_element 'publish'
@project.publish.add_element 'disable'
end
begin
if @project.save
flash[:notice] = "Project '#{@project}' was created successfully"
redirect_to :action => 'show', :project => project_name and return
else
flash[:error] = "Failed to save project '#{@project}'"
end
rescue ActiveXML::Transport::ForbiddenError
flash[:error] = "You lack the permission to create the project '#{@project}'. " +
'Please create it in your home:%s namespace' % User.current.login
redirect_to :action => 'new', :ns => 'home:' + User.current.login and return
end
redirect_to :action => 'new'
end
def save
if ( !params[:title] )
flash[:error] = 'Title must not be empty'
redirect_to :action => 'edit', :project => params[:project]
return
end
@project.title.text = params[:title]
@project.description.text = params[:description]
if @project.save
flash[:notice] = "Project '#{@project}' was saved successfully"
else
flash[:error] = "Failed to save project '#{@project}'"
end
redirect_to :action => :show, :project => @project
end
def save_targets
if params[:target_project].blank? and params[:torepository].blank? and
params[:repo].blank? and params[:target_repo].blank?
flash[:error] = 'Missing arguments for target project or repository'
redirect_to :action => 'add_repository_from_default_list', :project => @project and return
end
target_repo = params[:target_repo]
# extend an existing repository with a path
if params.has_key?(:torepository)
repo_path = "#{params[:target_project]}/#{target_repo}"
if @project.add_path_to_repository(:reponame => params[:torepository], :repo_path => repo_path)
@project.save
flash[:success] = "Path #{params['target_project']}/#{target_repo} added successfully"
redirect_to :action => 'repositories', :project => @project and return
else
flash[:error] = "Path #{params['target_project']}/#{target_repo} is already set for this repository"
redirect_to :action => 'add_repository', :project => @project, :torepository => params[:torepository] and return
end
elsif params.has_key?(:repo)
# add new repositories
repos = params[:repo]
# this interface is a mess
if repos.kind_of? String
repos=[repos]
end
repos.each do |repo|
if !valid_target_name? repo
flash[:error] = "Illegal target name #{repo}."
redirect_to :action => :add_repository_from_default_list, :project => @project and return
end
repo_path = params[repo + '_repo'] || "#{params[:target_project]}/#{target_repo}"
repo_archs = params[repo + '_arch'] || params[:arch]
logger.debug "Adding repo: #{repo_path}, archs: #{repo_archs}"
@project.add_repository(:reponame => repo, :repo_path => repo_path, :arch => repo_archs)
# FIXME: will be cleaned up after implementing FATE #308899
if repo == 'images'
prjconf = frontend.get_source(:project => params[:project], :filename => '_config')
unless prjconf =~ /^Type:/
prjconf = "%if \"%_repository\" == \"images\"\nType: kiwi\nRepotype: none\nPatterntype: none\n%endif\n" << prjconf
frontend.put_file(prjconf, :project => @project, :filename => '_config')
end
end
end
@project.save
flash[:success] = 'Build targets were added successfully'
redirect_to :action => 'repositories', :project => @project and return
end
rescue ActiveXML::Transport::Error => e
flash[:error] = 'Failed to add project or repository: ' + e.summary
redirect_back_or_to :action => 'repositories', :project => @project and return
end
def release_repository_dialog
@project = params[:project]
@repository = params[:repository]
render_dialog
end
def remove_target_request_dialog
@project = params[:project]
@repository = params[:repository]
render_dialog
end
def remove_target_request
begin
req = BsRequest.new(:type => 'delete', :targetproject => params[:project], :targetrepository => params[:repository], :description => params[:description])
req.save(create: true)
flash[:success] = "Created <a href='#{url_for(:controller => 'request', :action => 'show', :id => req.value('id'))}'>repository delete request #{req.value('id')}</a>"
rescue ActiveXML::Transport::NotFoundError => e
flash[:error] = e.summary
redirect_to :action => :repositories, :project => @project and return
rescue ActiveXML::Transport::Error => e
flash[:error] = e.summary
redirect_back_or_to :action => :repositories, :project => @project and return
end
redirect_to :controller => :request, :action => :show, :id => req.value('id')
end
def remove_target
if not params[:target]
flash[:error] = 'Target removal failed, no target selected!'
redirect_to :action => :show, :project => params[:project]
end
@project.remove_repository params[:target]
begin
if @project.save
flash[:notice] = "Target '#{params[:target]}' was removed"
else
flash[:error] = "Failed to remove target '#{params[:target]}'"
end
rescue ActiveXML::Transport::Error => e
flash[:error] = "Failed to remove target '#{params[:target]}' " + e.summary
end
redirect_to :action => :repositories, :project => @project
end
def release_repository
begin
@project.release_repository(params[:repository], params[:release_target])
flash[:notice] = "Repository '#{params[:repository]}' gets released"
rescue ActiveXML::Transport::Error => e
flash[:error] = "Failed to release repository '#{params[:repository]}' " + e.summary
end
redirect_to :action => :repositories, :project => @project
end
def remove_path_from_target
required_parameters :repository, :path_project, :path_repository
@project.remove_path_from_target( params[:repository], params[:path_project], params[:path_repository] )
@project.save
flash[:success] = "Removed path #{params['path_project']}/#{params['path_repository']} from #{params['repository']}"
redirect_to :action => :repositories, :project => @project
end
def move_path_up
required_parameters :repository, :path_project, :path_repository
@project.repository[params[:repository]].move_path(params[:path_project] + '/' + params[:path_repository], :up)
@project.save
redirect_to :action => :repositories, :project => @project
end
def move_path_down
required_parameters :repository, :path_project, :path_repository
@project.repository[params[:repository]].move_path(params[:path_project] + '/' + params[:path_repository], :down)
@project.save
redirect_to :action => :repositories, :project => @project
end
def load_obj
if login = params[:userid]
return User.get_by_login(login)
elsif title = params[:groupid]
return ::Group.get_by_title(title)
else
raise MissingParameterError, "Neither user nor group given"
end
end
def save_person
begin
@project.api_obj.add_role(load_obj, Role.find_by_title!(params[:role]))
@project.free_cache
rescue ApiDetails::TransportError, ApiDetails::NotFoundError, User::NotFound => e
flash[:error] = e.to_s
redirect_to action: :add_person, project: @project, role: params[:role], userid: params[:userid]
return
end
respond_to do |format|
format.js { render json: 'ok' }
format.html do
flash[:notice] = "Added user #{params[:userid]} with role #{params[:role]}"
redirect_to action: :users, project: @project
end
end
end
def save_group
begin
@project.api_obj.add_role(load_obj, Role.find_by_title!(params[:role]))
@project.free_cache
rescue ApiDetails::TransportError, ApiDetails::NotFoundError, ::Group::NotFound => e
flash[:error] = e.to_s
redirect_to action: :add_group, project: @project, role: params[:role], groupid: params[:groupid]
return
end
respond_to do |format|
format.js { render json: 'ok' }
format.html do
flash[:notice] = "Added group #{params[:groupid]} with role #{params[:role]} to project #{@project}"
redirect_to action: :users, project: @project
end
end
end
def remove_role
begin
@project.api_obj.remove_role(load_obj, Role.find_by_title(params[:role]))
@project.free_cache
rescue ApiDetails::TransportError, ApiDetails::NotFoundError, User::NotFound, ::Group::NotFound => e
flash[:error] = e.summary
end
respond_to do |format|
format.js { render json: 'ok' }
format.html do
if params[:userid]
flash[:notice] = "Removed user #{params[:userid]}"
else
flash[:notice] = "Removed group '#{params[:groupid]}'"
end
redirect_to action: :users, project: @project
end
end
end
def monitor
@name_filter = params[:pkgname]
@lastbuild_switch = params[:lastbuild]
if params[:defaults]
defaults = (Integer(params[:defaults]) rescue 1) > 0
else
defaults = true
end
params['expansionerror'] = 1 if params['unresolvable']
@avail_status_values = Buildresult.avail_status_values
@filter_out = ['disabled', 'excluded', 'unknown']
@status_filter = []
@avail_status_values.each { |s|
id=s.gsub(' ', '')
if params.has_key?(id)
next unless (Integer(params[id]) rescue 1) > 0
else
next unless defaults
end
next if defaults && @filter_out.include?(s)
@status_filter << s
}
@avail_arch_values = []
@avail_repo_values = []
@project.to_hash.elements('repository') { |r|
@avail_repo_values << r['name']
@avail_arch_values << r.elements('arch')
}
@avail_arch_values = @avail_arch_values.flatten.uniq.sort
@avail_repo_values = @avail_repo_values.flatten.uniq.sort
@arch_filter = []
@avail_arch_values.each { |s|
archid = valid_xml_id('arch_' + s)
if defaults || (params.has_key?(archid) && params[archid])
@arch_filter << s
end
}
@repo_filter = []
@avail_repo_values.each { |s|
repoid = valid_xml_id('repo_' + s)
if defaults || (params.has_key?(repoid) && params[repoid])
@repo_filter << s
end
}
find_opt = { :project => @project, :view => 'status', :code => @status_filter,
:arch => @arch_filter, :repo => @repo_filter }
find_opt[:lastbuild] = 1 unless @lastbuild_switch.blank?
@buildresult = Buildresult.find( find_opt )
unless @buildresult
flash[:error] = "No build results for project '#{@project}'"
redirect_to :action => :show, :project => params[:project]
return
end
@buildresult = @buildresult.to_hash
if not @buildresult.has_key? 'result'
@buildresult_unavailable = true
return
end
@repohash = Hash.new
@statushash = Hash.new
@repostatushash = Hash.new
@packagenames = Array.new
@buildresult.elements('result') do |result|
@resultvalue = result
repo = result['repository']
arch = result['arch']
next unless @repo_filter.include? repo