Пример #1
0
def get_branch_list(request):
    # 项目id
    project_id = request.POST.get('project_id', '')
    if len(project_id) == 0:
        return function.ajax_return_exit('项目id不能为空', -1)

    # 获取项目数据
    data = Project.objects.filter(project_id=project_id).first()
    if data != None:
        # 获取项目名称
        git_dir_address = function.get_git_address(
            function.get_project_handle_temp_dir(), data.git_ssh_address,
            data.git_alias)

        if os.path.exists(git_dir_address) == False:
            return function.ajax_return_exit('项目路径地址不存在', -2)

        # 同步远程分支
        ret = git.fetch(git_dir_address)
        if ret != True:
            return function.json_exit(ret)

        # 获取版本列表
        return function.json_exit(git.get_branch(git_dir_address, '-a'))
    else:
        return function.ajax_return_exit('没有找到相关的项目', -3)
Пример #2
0
def get_version_list(request):
    # 项目id
    project_id = request.POST.get('project_id', '')
    if len(project_id) == 0:
        return function.ajax_return_exit('项目id不能为空', -1)

    # 分支名称
    branch = request.POST.get('branch')
    if len(branch) == 0:
        return function.ajax_return_exit('请选择项目分支', -2)

    # 获取项目数据
    data = Project.objects.filter(project_id=project_id).first()
    if data != None:
        # 获取项目名称
        git_dir_address = function.get_git_address(
            function.get_project_handle_temp_dir(), data.git_ssh_address,
            data.git_alias)
        if os.path.exists(git_dir_address) == False:
            return function.ajax_return_exit('项目路径地址不存在', -1)

        # 清除当前项目改动项
        ret = git.clean(git_dir_address)
        if ret != True:
            return function.json_exit(ret)

        # 拉取远程分支最新代码
        ret = git.fetch(git_dir_address, branch)
        if ret != True:
            return function.json_exit(ret)

        # 分支切换
        ret = git.checkout(git_dir_address, branch)
        if ret != True:
            return function.json_exit(ret)

        # 拉取分支最新代码到本地分支
        ret = git.pull(git_dir_address, branch)
        if ret != True:
            return function.json_exit(ret)

        # 获取版本列表
        return function.json_exit(git.log(git_dir_address, 30))
    else:
        return function.ajax_return_exit('没有找到相关的项目', -3)
Пример #3
0
def save(request):
    # 项目id
    project_id = request.POST.get('project_id', '')

    # 等于0则添加
    if len(project_id) == 0:
        # 临时操作地址
        project_temp_dir = function.get_project_handle_temp_dir()

        # 项目原始名称
        project_git_name = function.get_git_ssh_name(
            request.POST['git_ssh_address'])

        # git别名
        git_alias = request.POST.get('git_alias', '')

        # 获取项目地址
        git_dir_address = function.get_git_address(
            request.POST['dir_address'], request.POST['git_ssh_address'])

        # git别名地址
        git_git_alias_address = function.get_git_address(
            request.POST['dir_address'], '', git_alias)

        # 项目实际地址-目录不存在则创建
        ret = function.mg_mkdir(request.POST['dir_address'])
        if ret != True:
            return function.json_exit(ret)

        # 临时操作地址-目录不存在则创建
        ret = function.mg_mkdir(project_temp_dir)
        if ret != True:
            return function.json_exit(ret)

        # 项目实际地址-克隆代码
        if os.path.exists(git_dir_address) == False:
            ret = git.clone(request.POST['dir_address'],
                            request.POST['git_ssh_address'])
            if ret != True:
                return function.json_exit(ret)

        # 临时操作地址-克隆代码
        if os.path.exists(project_temp_dir + '/' + project_git_name) == False:
            ret = git.clone(project_temp_dir, request.POST['git_ssh_address'])
            if ret != True:
                return function.json_exit(ret)

        # 项目别名处理
        if len(git_alias) > 0 and git_alias != project_git_name:
            ret = git_alias_rename(git_dir_address, project_git_name,
                                   project_temp_dir, git_alias,
                                   git_git_alias_address)
            if ret != True:
                return function.json_exit(ret)

        # 数据添加
        Project(project_name=request.POST['project_name'],
                git_ssh_address=request.POST['git_ssh_address'],
                git_alias=request.POST['git_alias'],
                dir_address=request.POST['dir_address'],
                is_cluster=request.POST['is_cluster'],
                describe=request.POST['describe']).save()
    else:
        # 数据更新
        Project.objects.filter(project_id=project_id).update(
            project_name=request.POST['project_name'],
            git_ssh_address=request.POST['git_ssh_address'],
            git_alias=request.POST['git_alias'],
            dir_address=request.POST['dir_address'],
            is_cluster=request.POST['is_cluster'],
            describe=request.POST['describe'])

    # 返回数据
    return function.ajax_return_exit('操作成功')