finish join service

This commit is contained in:
nigel007 2019-06-07 13:55:14 +08:00
parent 8d2372cabc
commit 34daf5d94a
2 changed files with 35 additions and 18 deletions

View File

@ -59,21 +59,14 @@ module Mobile
post 'join' do
authenticate!
# 根据repo_git_url找到repository对应的项目
Rails.logger.info("!!!!!!!!!!!in the join function")
rs = RepositoriesService.new
rs.findProjectByRepoUrl(params[:repo_url])
# owner = User.find_by_login(params[:ownername])
# if owner
# project = Project.find_by_user_id_name(owner.id, params[:reponame])
# if project
# blockchain = Blockchain.find_by_project_id(project.id)
# {status:0, genesis_content:blockchain.genesis_content, network_id:blockchain.network_id, connect_ip:blockchain.connect_ip, port:blockchain.port, enode:blockchain.enode}
# else
# {status:-1, message: '该项目不存在' }
# end
# else
# {status:-1, message: '该项目不存在或已被删除' }
# end
status, project = rs.findProjectByRepoUrl(params[:repo_url])
if project
blockchain = Blockchain.find_by_project_id(project.id)
{status:status, genesis_content:blockchain.genesis_content, network_id:blockchain.network_id, connect_ip:blockchain.connect_ip, port:blockchain.port, enode:blockchain.enode}
else
{status:-1, message: '该项目不存在' }
end
end
desc "获取两次代码提交之间的区别"

View File

@ -45,13 +45,37 @@ class RepositoriesService
# 根据repo_url找到所属project
def findProjectByRepoUrl repo_url
status = -1
# 解析ownername
repo_url = repo_url[Redmine::Configuration['gitlab_address'].to_s.length + 1..repo_url.length - 1]
Rails.logger.info("!!!!!!!!!!" + repo_url)
gitlab_address = Redmine::Configuration['gitlab_address']
gitlab_address = gitlab_address[gitlab_address.index("//") + 2..gitlab_address.length - 1]
repo_url = repo_url[repo_url.index(gitlab_address) + gitlab_address.length + 1..repo_url.length - 1]
index_split = repo_url.index("/")
owner_name = repo_url[0..index_split - 1]
Rails.logger.info("!!!!!!!!!!this is the owner name")
Rails.logger.info(owner_name)
owner = User.find_by_login(owner_name)
if owner
projects = Project.find_all_by_user_id(owner.id)
if projects.length <= 0
return status, nil
else
projects.each do |project|
gpid = project.gpid
if gpid
http_url_to_repo = Gitlab.client.project(gpid).try(:http_url_to_repo)
if http_url_to_repo
if repo_url == http_url_to_repo
status = 0
return status, project # 表示找到了
end
end
end
end
return status, nil # 表示没找到
end
else
return status, nil # 表示数据库有问题没有对应的owner
end
end
end