| 26 |
26 |
|
| 27 |
27 |
# Original function
|
| 28 |
28 |
#def create
|
| 29 |
|
# attrs = pickup_extra_info
|
| 30 |
|
# @repository = Repository.factory(params[:repository_scm])
|
| 31 |
|
# @repository.safe_attributes = params[:repository]
|
| 32 |
|
# if attrs[:attrs_extra].keys.any?
|
| 33 |
|
# @repository.merge_extra_info(attrs[:attrs_extra])
|
| 34 |
|
# end
|
| 35 |
|
# @repository.project = @project
|
| 36 |
|
# if request.post? && @repository.save
|
| 37 |
|
# redirect_to settings_project_path(@project, :tab => 'repositories')
|
| 38 |
|
# else
|
| 39 |
|
# render :action => 'new'
|
| 40 |
|
# end
|
|
29 |
# if @repository.save
|
|
30 |
# redirect_to settings_project_path(@project, :tab => 'repositories')
|
|
31 |
# else
|
|
32 |
# render :action => 'new'
|
|
33 |
# end
|
| 41 |
34 |
#end
|
| 42 |
35 |
|
| 43 |
36 |
def create_with_scm
|
| ... | ... | |
| 47 |
40 |
((params[:operation].present? && params[:operation] == 'add') || ScmConfig['only_creator'])) ||
|
| 48 |
41 |
!ScmConfig['allow_add_local']
|
| 49 |
42 |
|
| 50 |
|
attrs = pickup_extra_info
|
| 51 |
|
|
| 52 |
43 |
if params[:operation].present? && params[:operation] == 'add'
|
| 53 |
|
attrs[:attrs] = interface.sanitize(attrs[:attrs])
|
| 54 |
|
end
|
| 55 |
|
|
| 56 |
|
@repository = Repository.factory(params[:repository_scm])
|
| 57 |
|
@repository.safe_attributes = params[:repository]
|
| 58 |
|
if attrs[:attrs_extra].keys.any?
|
| 59 |
|
@repository.merge_extra_info(attrs[:attrs_extra])
|
|
44 |
@repository.safe_attributes = interface.sanitize(@repository.attributes)
|
| 60 |
45 |
end
|
| 61 |
46 |
|
| 62 |
|
@repository.project = @project
|
| 63 |
|
|
| 64 |
47 |
if @repository.valid? && params[:operation].present? && params[:operation] == 'add'
|
| 65 |
48 |
if !ScmConfig['max_repos'] || ScmConfig['max_repos'].to_i == 0 ||
|
| 66 |
49 |
@project.repositories.select{ |r| r.created_with_scm }.size < ScmConfig['max_repos'].to_i
|
| 67 |
|
scm_create_repository(@repository, interface, attrs[:attrs]['url'])
|
|
50 |
scm_create_repository(@repository, interface)
|
| 68 |
51 |
else
|
| 69 |
52 |
@repository.errors.add(:base, :scm_repositories_maximum_count_exceeded, :max => ScmConfig['max_repos'].to_i)
|
| 70 |
53 |
end
|
| ... | ... | |
| 73 |
56 |
if ScmConfig['only_creator'] && request.post? && @repository.errors.empty? && !@repository.created_with_scm
|
| 74 |
57 |
@repository.errors.add(:base, :scm_only_creator)
|
| 75 |
58 |
elsif !ScmConfig['allow_add_local'] && request.post? && @repository.errors.empty? && !@repository.created_with_scm &&
|
| 76 |
|
attrs[:attrs]['url'] =~ %r{\A(file://|([a-z]:)?\.*[\\/])}i
|
|
59 |
@repository.url =~ %r{\A(file://|([a-z]:)?\.*[\\/])}i
|
| 77 |
60 |
@repository.errors.add(:base, :scm_local_repositories_denied)
|
| 78 |
61 |
end
|
| 79 |
62 |
|
| ... | ... | |
| 92 |
75 |
update_without_scm
|
| 93 |
76 |
|
| 94 |
77 |
if @repository.is_a?(Repository::Github) && # special case for Github
|
| 95 |
|
params[:repository][:extra_register_hook] == '1' && !@repository.extra_hook_registered
|
|
78 |
params[:repository][:register_hook] == '1' && !@repository.extra_hook_registered
|
| 96 |
79 |
flash[:warning] = l(:warning_github_hook_registration_failed)
|
| 97 |
80 |
end
|
| 98 |
81 |
end
|
| ... | ... | |
| 113 |
96 |
|
| 114 |
97 |
private
|
| 115 |
98 |
|
| 116 |
|
def scm_create_repository(repository, interface, url)
|
| 117 |
|
name = interface.repository_name(url)
|
|
99 |
def scm_create_repository(repository, interface)
|
|
100 |
name = interface.repository_name(repository.url)
|
| 118 |
101 |
if name
|
| 119 |
102 |
path = interface.default_path(name)
|
| 120 |
103 |
if interface.repository_exists?(name)
|