module Codingapi::Moveimp

Public Instance Methods

get_all_coding_repo(username:nil, token:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 31
def get_all_coding_repo(username:nil, token:nil)

    puts username
    puts token
    api = Codinginterface.new(username:username, token:token)
    puts  api.username
    page_szie = 2
    res = api.get_all_project(page:0, page_szie:page_szie)

    coding_info_json = []

    for item in res['data']['list'] do
        newitem = {}
        newitem['name'] = item['name']
        newitem['ssh_url'] = item['ssh_url']
        newitem['https_url'] = item['https_url']
        newitem['owner_user_name'] = item['owner_user_name']
        puts newitem['name']
        puts newitem['https_url']
        coding_info_json.push(newitem)
    end

    totalPage = res['data']['totalPage']
    index = 1

    while index < totalPage + 1  do
        # get_coding_repo(username:username, token:token, page:index, page_szie:page_szie)
        index = index + 1
    end

    return coding_info_json

end
get_coding_repo(username:nil, token:nil, page:0, page_szie:10) click to toggle source
# File lib/codingapi/moveimp.rb, line 12
def get_coding_repo(username:nil, token:nil, page:0, page_szie:10)

    coding_sub_info = []
    api = Codinginterface.new(username:username, token:token)
    res = api.get_all_project(page:0, page_szie:10)

    for item in res['data']['list'] do
        newitem = {}
        newitem['name'] = item['name']
        newitem['ssh_url'] = item['ssh_url']
        newitem['https_url'] = item['https_url']
        newitem['owner_user_name'] = item['owner_user_name']
        puts newitem['name']
        puts newitem['https_url']
        coding_sub_info.push(newitem)
    end
    return coding_sub_info;
end
modify_git_repo_exe(username:nil, token:nil, item_json:nil, path:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 162
def modify_git_repo_exe(username:nil, token:nil, item_json:nil, path:nil)

    gitee_team = item_json['gitee_team']
    git_name = item_json['name']
    gitee_ssh_url = item_json['gitee_ssh_url']
    

    puts "modify_git_repo_exe +++0"

    repo_dir = getcode_to_dir(repo_name:git_name, remote_url:gitee_ssh_url, path: path, new_branch:"master")
    
    api = Giteeinterface.new(username:username, token:token)      
    branch_list = api.get_repo_breanch_info(owner:gitee_team, repo_name:git_name)

    puts "modify_git_repo_exe +++1"
    if branch_list.length > 0
        for branch_info in branch_list do
            branch_name =branch_info['name']
            
            repo_dir = getcode_to_dir(repo_name:git_name, remote_url:gitee_ssh_url, path: path, new_branch:branch_name)
            puts "modify_podflie +++ beging"
            modify_podflie(project_path:repo_dir)
            puts "modify_podflie +++ end"

            message = branch_name + " modify podfile  pod_lib_lint pod_repo_push"

            git_addpush_repo(path:repo_dir, message:message)           
        end
    end
    
    puts "modify_git_repo_exe +++3"

    return true;
end
modify_podflie(project_path:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 138
def modify_podflie(project_path:nil)
    pod_file = File.join(project_path, "Podfile")
    pod_lib_lint = File.join(project_path, "pod_lib_lint.sh")
    pod_repo_push = File.join(project_path, "pod_repo_push.sh")

    puts "modify_podflie +++0"

    puts pod_file
    if File.exist?(pod_file)
        replace_file_text(filename:pod_file, origin_text:'git.coding.net', new_txt:'gitee.com')
    end

    puts pod_lib_lint
    if File.exist?(pod_lib_lint)
        replace_file_text(filename:pod_lib_lint, origin_text:'git.coding.net', new_txt:'gitee.com')
    end

    puts pod_repo_push
    if File.exist?(pod_repo_push)
        replace_file_text(filename:pod_repo_push, origin_text:'git.coding.net', new_txt:'gitee.com')
    end
    puts "modify_podflie +++1"
end
move_git_repo_exe(username:nil, token:nil, item_json:nil, path:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 104
def move_git_repo_exe(username:nil, token:nil, item_json:nil, path:nil)

    gitee_team = item_json['gitee_team']
    git_name = item_json['name']

    ssh_url = item_json['ssh_url']
    gitee_ssh_url = item_json['gitee_ssh_url']
    
    puts "move_git_repo_exe +++0"
    repo_dir = getbaregit_to_dir(repo_name:git_name, remote_url:ssh_url, path:path)
    api = Giteeinterface.new(username:username, token:token)
    puts "move_git_repo_exe +++1"
    status = api.create_repo(owner:gitee_team, repo_name:git_name)
    puts "move_git_repo_exe +++2"
    # if status == 200
        puts "move_git_repo_exe +++3"
      repo_info = api.get_repo_info(owner:gitee_team, repo_name:git_name)
      if repo_info['ssh_url'] == gitee_ssh_url
        puts "move_git_repo_exe +++4"
        git_pushmirror_repo(path:repo_dir, new_remote_url:gitee_ssh_url)
        puts "move_git_repo_exe +++5"
        return true;
      end
    # end
    return false;
end
produce_gitee_info(origin_josn:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 65
def produce_gitee_info(origin_josn:nil)
    gitee_json = []

    for item in origin_josn do
        newitem = {}
        newitem['name'] = item['name']
        newitem['ssh_url'] = item['ssh_url']
        newitem['https_url'] = item['https_url']
        newitem['owner_user_name'] = item['owner_user_name']
        newitem['gitee_team'] = item['owner_user_name']
  
        if item['owner_user_name'] == "GXDeploy"
            newitem['gitee_team'] = "iosdeploy"
        end


        # if item['owner_user_name'] == "PinssibleGX_iOSPod"
        #     newitem['gitee_team'] = "pinpods"
        # elsif item['owner_user_name'] == "Gxthird"
        #     newitem['gitee_team'] = "pinpods"
        # elsif item['owner_user_name'] == "GXIdeaApp"
        #     newitem['gitee_team'] = "iosideaapp"
        # elsif item['owner_user_name'] == "GX-iOS"
        #     newitem['gitee_team'] = "gxios"
        # elsif item['owner_user_name'] == "GXDeploy"
        #     newitem['gitee_team'] = "iosdeploy"
        # else
        #     newitem['gitee_team'] = "gxios"
        # end

        newitem['gitee_ssh_url'] = "git@gitee.com:" + newitem['gitee_team'] + "/" + newitem['name'] + ".git"
        newitem['gitee_https_url'] = "https://gitee.com/" + newitem['gitee_team'] + "/" + newitem['name'] + ".git"

        gitee_json.push(newitem)
    end

    return gitee_json
end
replace_file_text(filename:nil, origin_text:nil, new_txt:nil) click to toggle source
# File lib/codingapi/moveimp.rb, line 131
def replace_file_text(filename:nil, origin_text:nil, new_txt:nil)
    
    text = File.read(filename)
    new_contents = text.gsub!(/#{origin_text}/, new_txt)
    File.open(filename, "w") {|file| file.puts new_contents }
end