diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 2f1b53705..3cd194df8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -59,6 +59,9 @@ class RepositoriesController < ApplicationController def newrepo + # modify by nwb + # 查找当前用户的gitlab账号 + @gitlab_user = GitlabUser.find_by_user_id(User.current.id) scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first @repository = Repository.factory(scm) @repository.is_default = @project.repository.nil? @@ -244,7 +247,7 @@ class RepositoriesController < ApplicationController private :pickup_extra_info def committers - gitlab_project = GitlabProject.find_by_repository_url(@repository.url) + gitlab_project = GitlabProject.find_by_localfile_url(@repository.url) if gitlab_project # gitlab项目 @@ -279,7 +282,7 @@ class RepositoriesController < ApplicationController #system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" #system "rm -r "+@root_path+"htdocs/"+@repository_name - gitlabproject = GitlabProject.find_by_repository_url(@repository.url) + gitlabproject = GitlabProject.find_by_localfile_url(@repository.url) if gitlabproject gitlabproject.destroy end @@ -314,7 +317,7 @@ class RepositoriesController < ApplicationController @course_tag = params[:course] project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT ip = RepositoriesHelper::REPO_IP_ADDRESS - @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ + @repos_url = @repository.repos_url#"http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ @repository.url.slice(project_path_cut, @repository.url.length).to_s if @course_tag == 1 render :action => 'show', :layout => 'base_courses' diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb index 31fa574df..810ac7c5a 100644 --- a/app/helpers/gitlab_helper.rb +++ b/app/helpers/gitlab_helper.rb @@ -161,6 +161,7 @@ module GitlabHelper gituser.gitlab_user_id = git_user_id gituser.email = email gituser.password = password + gituser.login =loginname gituser.save return true else diff --git a/app/models/repository.rb b/app/models/repository.rb index 46e647f97..0fce323ab 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -138,7 +138,7 @@ class Repository < ActiveRecord::Base # 获取版本库地址 def repos_url if self.scm_name=="Git" - gitlabproject = GitlabProject.find_by_repository_url(self.url) + gitlabproject = GitlabProject.find_by_localfile_url(self.url) if gitlabproject.nil? # 兼容老git模式 ip = RepositoriesHelper::REPO_IP_ADDRESS diff --git a/app/views/repositories/_form_create.html.erb b/app/views/repositories/_form_create.html.erb index fc327f69a..2de7aab51 100644 --- a/app/views/repositories/_form_create.html.erb +++ b/app/views/repositories/_form_create.html.erb @@ -12,11 +12,10 @@ border:none

<%= label_tag('repository_scm', l(:label_scm)) %> - - <%= select_tag('repository_scm', - options_for_select(["Git"],@repository.class.name.demodulize), - :data => {:remote => true, :method => 'get'})%> - + <%= select_tag('repository_scm', + options_for_select(["Git"], @repository.class.name.demodulize), + :data => {:remote => true, :method => 'get'}) %> + <% if @repository && ! @repository.class.scm_available %> <%= l(:text_scm_command_not_available) %> <% end %> @@ -28,12 +27,27 @@ border:none <%= l(:text_repository_identifier_info).html_safe %> <% end %>

-

<%= f.text_field :gitlab_user, :required =>true, :label=> :field_account,:value=>User.current.login %> - <%= l(:label_gitlab_account)%>

-

<%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => User.current.mail %> - <%= l(:label_gitlab_email) %>

-

<%= f.password_field :upassword, :required =>true, :label=> :field_password %> - <%= l(:label_gitlab_password)%>

+ + <% if @gitlab_user %> +

<%= f.text_field :gitlab_user, :required => true, :label => :field_account, :value => @gitlab_user.login, :disabled =>true %> + <%= l(:label_gitlab_account) %>

+ +

<%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => @gitlab_user.email, :disabled =>true %> + <%= l(:label_gitlab_email) %>

+ +

<%= f.password_field :upassword, :required => true, :label => :field_password, :value => @gitlab_user.password, :disabled =>true %> + <%= l(:label_gitlab_password) %>

+ <% else %> +

<%= f.text_field :gitlab_user, :required => true, :label => :field_account, :value => User.current.login %> + <%= l(:label_gitlab_account) %>

+ +

<%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => User.current.mail %> + <%= l(:label_gitlab_email) %>

+ +

<%= f.password_field :upassword, :required => true, :label => :field_password %> + <%= l(:label_gitlab_password) %>

+ <% end %> +

<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save)) %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index ef93c8802..e434ac854 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1548,6 +1548,7 @@ zh: label_board_description: 七嘴八舌,汇聚众人智慧,为您排忧解难! label_create_course_description: 课程小社区,创建新课程,让我们共同分享多到想不到的公共资源! label_welcome_page_to: 参与了 %{project_count} 个项目! + label_repository_path: 版本库路径 label_repository_path_not_null: 库路径 不能为空字符 label_password_not_null: 密码不能设置为空。 label_exist_repository_path: 定义已有版本库URL路径,定义格式file:///, http://, https://, svn:// diff --git a/db/migrate/20140723012538_create_gitlab_projects.rb b/db/migrate/20140723012538_create_gitlab_projects.rb index 6c2c91696..ab531b57a 100644 --- a/db/migrate/20140723012538_create_gitlab_projects.rb +++ b/db/migrate/20140723012538_create_gitlab_projects.rb @@ -7,6 +7,8 @@ class CreateGitlabProjects < ActiveRecord::Migration t.string :repository_url #版本库web地址 t.string :web_url + #版本库本地地址 + t.string :localfile_url t.timestamps end diff --git a/db/migrate/20140723012553_create_gitlab_users.rb b/db/migrate/20140723012553_create_gitlab_users.rb index b5d645b43..89d1d06d7 100644 --- a/db/migrate/20140723012553_create_gitlab_users.rb +++ b/db/migrate/20140723012553_create_gitlab_users.rb @@ -9,7 +9,8 @@ class CreateGitlabUsers < ActiveRecord::Migration t.string :email # 登录gitlab所用的密码 t.string :password - + # 登录gitlab所用的账号 + t.string :login t.timestamps end end