Merge branch 'gitlab_guange' of http://repository.trustie.net/xianbo/trustie2 into gitlab_guange
This commit is contained in:
commit
64fa435a3a
|
@ -32,9 +32,9 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
|
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
|
||||||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo]
|
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab]
|
||||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork]
|
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab]
|
||||||
accept_rss_auth :revisions
|
accept_rss_auth :revisions
|
||||||
# hidden repositories filter // 隐藏代码过滤器
|
# hidden repositories filter // 隐藏代码过滤器
|
||||||
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
|
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
|
||||||
|
@ -247,6 +247,16 @@ update
|
||||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_gitlab
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
|
@repository = Repository.find(params[:id])
|
||||||
|
s = Trustie::Gitlab::Sync.new
|
||||||
|
s.sync_project(@project, path: params[:repo_name], import_url: @repository.url)
|
||||||
|
@repository.type = 'Repository::Gitlab'
|
||||||
|
@repository.save
|
||||||
|
redirect_to :controller => 'repositories', :action => 'show', :id => @project.id, to: 'gitlab'
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
## TODO: the below will move to filter, done.
|
## TODO: the below will move to filter, done.
|
||||||
if !User.current.member_of?(@project)
|
if !User.current.member_of?(@project)
|
||||||
|
@ -256,16 +266,22 @@ update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless @repository && @repository.type == 'Repository::Gitlab'
|
||||||
|
# redirect_to to_gitlab_project_repository_path(@project, @repository)
|
||||||
|
render :to_gitlab
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
#if( !User.current.member_of?(@project) || @project.hidden_repo)
|
#if( !User.current.member_of?(@project) || @project.hidden_repo)
|
||||||
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||||
|
|
||||||
g = Gitlab.client
|
#g = Gitlab.client
|
||||||
project = g.project(11)
|
#project = g.project(11)
|
||||||
# rr = g.trees(project.id, @path)
|
# rr = g.trees(project.id, @path)
|
||||||
# r = g.get ("/projects/#{@project}/repository/tree")
|
# r = g.get ("/projects/#{@project}/repository/tree")
|
||||||
# :name, :path, :kind, :size, :lastrev, :changeset
|
# :name, :path, :kind, :size, :lastrev, :changeset
|
||||||
# @entries = @repository.entries(@path, @rev)
|
@entries = @repository.entries(@path, @rev)
|
||||||
@entries = g.trees(project.id, @path)
|
#@entries = g.trees(project.id, @path)
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
|
|
||||||
#@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
#@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<%= form_for(@repository, url: to_gitlab_project_repository_path(@project, @repository)) do |f| %>
|
||||||
|
<input type="text" name="repo_name"/>
|
||||||
|
<button type="submit">转换到新版本</button>
|
||||||
|
<% end %>
|
|
@ -2,7 +2,7 @@ Gitlab.configure do |config|
|
||||||
# config.endpoint = 'http://192.168.41.130:3000/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
# config.endpoint = 'http://192.168.41.130:3000/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
||||||
# config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
# config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
||||||
config.endpoint = 'http://git.trustie.net/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
config.endpoint = 'http://git.trustie.net/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
||||||
config.private_token = 'fxm19wjRAs4REgTJwgtn' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
config.private_token = 'fPc_gBmEiSANve8TCfxW' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
||||||
# Optional
|
# Optional
|
||||||
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
||||||
# config.sudo = 'user' # username for sudo mode, default: nil
|
# config.sudo = 'user' # username for sudo mode, default: nil
|
||||||
|
|
|
@ -533,6 +533,7 @@ RedmineApp::Application.routes.draw do
|
||||||
resources :repositories, :except => [:index, :show] do
|
resources :repositories, :except => [:index, :show] do
|
||||||
member do
|
member do
|
||||||
get 'newrepo', :via => [:get, :post]
|
get 'newrepo', :via => [:get, :post]
|
||||||
|
put 'to_gitlab'
|
||||||
# get 'create', :via=>[:get, :post]
|
# get 'create', :via=>[:get, :post]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
<<<<<<< HEAD
|
|
||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
# This file is auto-generated from the current state of the database. Instead
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
# of editing this file, please use the migrations feature of Active Record to
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
@ -1313,9 +1312,9 @@ ActiveRecord::Schema.define(:version => 20151013023237) do
|
||||||
|
|
||||||
create_table "student_work_tests", :force => true do |t|
|
create_table "student_work_tests", :force => true do |t|
|
||||||
t.integer "student_work_id"
|
t.integer "student_work_id"
|
||||||
|
t.integer "status"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
t.integer "status", :default => 9
|
|
||||||
t.text "results"
|
t.text "results"
|
||||||
t.text "src"
|
t.text "src"
|
||||||
end
|
end
|
||||||
|
@ -3443,4 +3442,3 @@ ActiveRecord::Schema.define(:version => 20151014023806) do
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
>>>>>>> szzh
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Redmine
|
||||||
def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
|
def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
|
||||||
super
|
super
|
||||||
@g = Gitlab.client
|
@g = Gitlab.client
|
||||||
@project = 11
|
@project = Repository.find_by_url(url).project.gpid
|
||||||
@path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
|
@path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,80 +1,42 @@
|
||||||
|
require 'trustie/gitlab/sync'
|
||||||
|
|
||||||
namespace :gitlab do
|
namespace :gitlab do
|
||||||
namespace :sync do
|
namespace :sync do
|
||||||
|
|
||||||
module Helper
|
|
||||||
def self.change_password(uid, en_pwd, salt)
|
|
||||||
g = Gitlab.client
|
|
||||||
options = {:encrypted_password=>en_pwd, :password_salt=>salt}
|
|
||||||
g.put("/users/ext/#{uid}", :body => options)
|
|
||||||
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
desc "sync users to gitlab"
|
desc "sync users to gitlab"
|
||||||
task :users => :environment do
|
task :users => :environment do
|
||||||
# User.where(username: 'root').find_each do |user|
|
# User.where(username: 'root').find_each do |user|
|
||||||
User.where(login: 'guange1').find_each do |user|
|
s = Trustie::Gitlab::Sync.new
|
||||||
begin
|
User.find_each do |user|
|
||||||
g = Gitlab.client
|
s.sync_user(user)
|
||||||
u = g.get("/users?search=#{user.mail}").first
|
|
||||||
unless u
|
|
||||||
u = g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login, confirm: "true")
|
|
||||||
user.gid = u.id
|
|
||||||
user.save!
|
|
||||||
puts "create user #{user.login}"
|
|
||||||
end
|
|
||||||
Helper.change_password(u.id, user.hashed_password, user.salt)
|
|
||||||
rescue => e
|
|
||||||
puts e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "update user password"
|
desc "update user password"
|
||||||
task :password => :environment do
|
task :password => :environment do
|
||||||
Helper.change_password(1,'5188b7a65acf294ee7deceb397b6f9c62214ea50','dcb8d9fffabec60c2d0d1030b679fbbb')
|
s = Trustie::Gitlab::Sync.new
|
||||||
|
s.change_password(1,'5188b7a65acf294ee7deceb397b6f9c62214ea50','dcb8d9fffabec60c2d0d1030b679fbbb')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
desc "sync projects to gitlab"
|
desc "sync projects to gitlab"
|
||||||
task :projects => :environment do
|
task :projects => :environment do
|
||||||
Project.where(id: 505).find_each do |project|
|
s = Trustie::Gitlab::Sync.new
|
||||||
|
Project.where(id: ENV["PROJECT_ID"]).find_each do |project|
|
||||||
|
s.sync_project(project, path: ENV["REP_NAME"], import_url: project.repository.url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "remove all projects"
|
||||||
|
task :remove_all_projects => :environment do
|
||||||
g = Gitlab.client
|
g = Gitlab.client
|
||||||
gid = project.owner.gid
|
100.times do
|
||||||
raise "unknow gid" unless gid
|
g.projects(scope: 'all').each do |p|
|
||||||
path = project.repositories.where(:is_default => true).first.root_url.split('/').last
|
puts p.id
|
||||||
path = path.split('.').first
|
begin
|
||||||
raise "unknow path" unless path
|
g.delete_project(p.id)
|
||||||
|
rescue => e
|
||||||
# import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git
|
puts e
|
||||||
# can use password
|
end
|
||||||
gproject = g.create_project(project.identifier,
|
|
||||||
path: path,
|
|
||||||
description: project.description,
|
|
||||||
wiki_enabled: false,
|
|
||||||
wall_enabled: false,
|
|
||||||
issues_enabled: false,
|
|
||||||
snippets_enabled: false,
|
|
||||||
public: false,
|
|
||||||
user_id: gid,
|
|
||||||
import_url: 'https://github.com/gitlabhq/gitlab-cli.git'
|
|
||||||
)
|
|
||||||
project.gpid = gproject.id
|
|
||||||
project.save!
|
|
||||||
puts "Successfully created #{project.name}"
|
|
||||||
# add team members
|
|
||||||
#
|
|
||||||
GUEST = 10
|
|
||||||
REPORTER = 20
|
|
||||||
DEVELOPER = 30
|
|
||||||
MASTER = 40
|
|
||||||
OWNER = 50
|
|
||||||
|
|
||||||
project.members.each do |m|
|
|
||||||
g.add_team_member(gproject.id, m.user.gid, DEVELOPER)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
module Trustie
|
||||||
|
module Gitlab
|
||||||
|
module UserLevel
|
||||||
|
GUEST = 10
|
||||||
|
REPORTER = 20
|
||||||
|
DEVELOPER = 30
|
||||||
|
MASTER = 40
|
||||||
|
OWNER = 50
|
||||||
|
end
|
||||||
|
|
||||||
|
class Sync
|
||||||
|
attr :g
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@g = ::Gitlab.client
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_password(uid, en_pwd, salt)
|
||||||
|
options = {:encrypted_password=>en_pwd, :password_salt=>salt}
|
||||||
|
self.g.put("/users/ext/#{uid}", :body => options)
|
||||||
|
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_user(user)
|
||||||
|
begin
|
||||||
|
u = self.g.get("/users?search=#{user.mail}").first
|
||||||
|
unless u
|
||||||
|
u = self.g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login, confirm: "true")
|
||||||
|
user.gid = u.id
|
||||||
|
user.save!
|
||||||
|
puts "create user #{user.login}"
|
||||||
|
end
|
||||||
|
change_password(u.id, user.hashed_password, user.salt)
|
||||||
|
rescue => e
|
||||||
|
puts e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def sync_project(project, opt={})
|
||||||
|
gid = project.owner.gid
|
||||||
|
raise "unknow gid" unless gid
|
||||||
|
path = opt[:path]
|
||||||
|
raise "unknow path" unless path
|
||||||
|
import_url = opt[:import_url]
|
||||||
|
raise "unknow import_url" unless import_url
|
||||||
|
|
||||||
|
if opt[:password]
|
||||||
|
import_url.sub('@', ":#{opt[:password]}@")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git
|
||||||
|
# can use password
|
||||||
|
gproject = self.g.create_project(path,
|
||||||
|
path: path,
|
||||||
|
description: project.description,
|
||||||
|
wiki_enabled: false,
|
||||||
|
wall_enabled: false,
|
||||||
|
issues_enabled: false,
|
||||||
|
snippets_enabled: false,
|
||||||
|
public: false,
|
||||||
|
user_id: gid,
|
||||||
|
import_url: import_url
|
||||||
|
)
|
||||||
|
project.gpid = gproject.id
|
||||||
|
project.save!
|
||||||
|
puts "Successfully created #{project.name}"
|
||||||
|
# add team members
|
||||||
|
#
|
||||||
|
|
||||||
|
project.members.each do |m|
|
||||||
|
begin
|
||||||
|
self.g.add_team_member(gproject.id, m.user.gid, UserLevel::DEVELOPER)
|
||||||
|
rescue => e
|
||||||
|
puts e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_project
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue