Project

General

Profile

Feature #1837 ยป autocreate_repo.patch

patch - paul k, 2008-09-01 11:13

View differences:

app/controllers/repositories_controller.rb (working copy)
33 33
  rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
34 34
  
35 35
  def edit
36
    logger.debug("In RepositoryController.edit")
36 37
    @repository = @project.repository
37 38
    if !@repository
38 39
      @repository = Repository.factory(params[:repository_scm])
39 40
      @repository.project = @project if @repository
40 41
    end
41 42
    if request.post? && @repository
42
      @repository.attributes = params[:repository]
43
      url = login = password = nil
44
      repo_script_success = true
45
      if @repository.url != params[:repository][:url]
46
        #repo url has changed. Call the auto_create_repo script....
47
        if (Setting[:auto_create_repo] != 0) && (Setting[:autorepo_scriptpath] != ""):
48
          logger.debug("Repository URL changed, running auto_create_repo script")
49
          script = Setting[:autorepo_scriptpath]
50
          id = @project.identifier
51
          scm = params[:repository_scm]
52
          url = params[:repository][:url]
53
          begin
54
            File.open("#{script}") #check if the script exists
55
            IO.popen("#{script} #{scm} #{id}") { |p| 
56
              ret = p.gets 
57
              ret = ret.strip.split
58
              if $? && $?.exitstatus != 0
59
                repo_script_success = false
60
              end
61
              if ret.length == 3:
62
                 url, login, password = ret
63
              else
64
                 url = ret
65
              end
66
              }
67
          rescue Errno::ENOENT => e
68
            logger.info("Script #{Setting[:autorepo_scriptpath]} for creating repository for project #{id} not found: #{e}")
69
            #TODO: catch more possible errors
70
          end
71
        end
72
      end
73
      attrs = params[:repository]
74
      if repo_script_success
75
        attrs['url'] = url.to_s.strip
76
        attrs['login'] = login.to_s.strip
77
        attrs['password'] = password.to_s.strip
78
      end
79
      @repository.attributes = attrs
43 80
      @repository.save
44 81
    end
45 82
    render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
app/views/settings/_repositories.rhtml (working copy)
7 7
<p><label><%= l(:setting_sys_api_enabled) %></label>
8 8
<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p>
9 9

  
10
<p><label><%= l(:setting_auto_create_repo) %></label>
11
<%= check_box_tag 'settings[auto_create_repo]', 1, Setting.auto_create_repo?%><%= hidden_field_tag 'settings[auto_create_repo]', 0 %></p>
12
<p><label><%= l(:setting_autorepo_scriptpath) %></label>
13
<%= text_field_tag 'settings[autorepo_scriptpath]', Setting.autorepo_scriptpath, :size=>60 %>
14
<br /><em><%= l(:text_autorepo_explain) %>
15
</p>
16

  
10 17
<p><label><%= l(:setting_enabled_scm) %></label>
11 18
<% REDMINE_SUPPORTED_SCM.each do |scm| -%>
12 19
<%= check_box_tag 'settings[enabled_scm][]', scm, Setting.enabled_scm.include?(scm) %> <%= scm %>
lang/en.yml (working copy)
200 200
setting_feeds_limit: Feed content limit
201 201
setting_default_projects_public: New projects are public by default
202 202
setting_autofetch_changesets: Autofetch commits
203
setting_auto_create_repo: Automatically create repository
204
setting_autorepo_scriptpath: Absolute path to script for creating repository
203 205
setting_sys_api_enabled: Enable WS for repository management
204 206
setting_commit_ref_keywords: Referencing keywords
205 207
setting_commit_fix_keywords: Fixing keywords
......
609 611
text_enumeration_destroy_question: '%d objects are assigned to this value.'
610 612
text_enumeration_category_reassign_to: 'Reassign them to this value:'
611 613
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
612

  
614
text_autorepo_explain: "The script will receive the following parameters: SCM type (e.g. Subversion), project identifier. It sets the repository URL and username and password (if applicable)."
613 615
default_role_manager: Manager
614 616
default_role_developper: Developer
615 617
default_role_reporter: Reporter
    (1-1/1)