Example #1
0
def project(cc):
    user_git_repo_list = [i for i in cc.values_json('repo_json')]

    names = []
    repos = []
    version = []
    repo = {}
    create_msg = cc.value('project', 'create_message')
    # TODO: max lenght for each column + 2
    for r in user_git_repo_list:
        for k, v in r.items():
            n = display_string.format(v["name"], v["version"], v["path"])
            names.append(n)
    names.append(create_msg)

    lns = cc.value('project', 'branch') + "\n"
    lns += display_string.format("    Project", "    Tag", "Path")
    name = cutie.select_propmt(lns, names)
    name = name[:PROJECT_SPACE - 1].strip()
    if name == create_msg:
        repo = create_project(cc)
    elif name.lower() in ('exit', 'cancel'):
        cutie.get_exit()
        return None
    else:
        for r in user_git_repo_list:
            for k, v in r.items():
                if name == k:
                    repo = v
                    branches.pick_branch(cc, repo)
                    cc.save_json('repo_json', repo["name"], repo)
    return repo
Example #2
0
def main():
    cc = config.conf('.git_talk.ini')
    cutie.cprint('info', cc.value('git-talk', 'welcome'))

    if not cc.value('access', 'git_api'):
        cutie.cprint('blank', '')
        git_api = cutie.get_input(cc.value('git-talk', 'git_api_message'))
        if not git_api:
            git_api = 'https://github.com.au/api/v3'
        cutie.cprint('alarm', cc.value('git-talk', 'token_help_message'))
        cutie.cprint('', '')
        token = cutie.get_input(cc.value('git-talk', 'token_message'))
        g = github_api.GitHubAPI(git_api=git_api, token=token)
        if g is not None:
            cc.save("access", "git_api", git_api)
            cc.save("access", "token", token)
        else:
            cutie.cprint('error', "invalid api or token.")
            if cutie.get_exit(value='Exit', ex=True, message=m):
                exit()
    repo = {}
    user_git_repo_list = [i for i in cc.values_json('repo_json')]
    for r in user_git_repo_list:
        for k, v in r.items():
            if k == cc.value("access", "current_repo"):
                repo = v
    if not repo:
        repo = projects.create_project(cc)

    # g.init(repo)

    while True:
        names = cc.value('git-talk', 'steps').split(',')
        b, status = stts.current_status(cc, repo)
        if status == 1:
            break
        repo["branch"] = b
        msg = cc.value('git-talk', 'message').format(repo["name"], b, status)
        name = cutie.select_propmt(msg, names, exit='Exit')
        #name = cutie.select_propmt(cc.value('git-talk','message'),names)
        #names = cc.value('git-talk','steps').split(',')
        if name == names[0]:
            graph.git_simple(cc, repo)
        elif name == names[1]:
            r = projects.project(cc)
            if r is not None:
                repo = r
        elif name == names[2]:
            rebase.rebase(cc, repo)
        elif name == names[3]:
            pr_tag_release(cc, repo)
        elif name == names[4]:
            branches.pick_branch(cc, repo)
        elif name == names[5]:
            commit.commit(cc, repo)
        elif name == names[6]:
            m = 'Exit git-talk CLI gracefully!'
            if cutie.get_exit(value=name, ex=True, message=m):
                break
Example #3
0
def pr(cc, repo):
    # squash commit, list from and into branches (both local and remote). if need, notify codereviewer.
    base = ''
    cutie.cprint('wait', (cc.value('git-talk', 'wait')))
    cutie.cprint('', '')
    tt = cc.value('access', 'token')
    if len(tt) < 5:
        cutie.cprint(
            'error', 'invalid token, please config in .git_talk.ini correctly')
        return
    gh = github_api.GitHubAPI(cc.value('access', 'git_api'),
                              cc.value('access', 'token'))
    gh.set_repo(repo['url'])
    current_b, status = stts.current_status(cc, repo)
    command = [['git', 'branch']]
    b, _ = gfunc.subprocess_cmd(repo['path'], command)
    # b = gfunc.execute_git_command(repo['path'], 'branch')
    br_list = b[0].split("\n")
    head = cutie.select_propmt(cc.value('pr', 'head'),
                               br_list).replace('*', '')
    head = head.strip()
    if head.startswith(repo["task"]):
        base = 'dev'
    elif head.startswith(repo["hotfix"]):
        base = 'master'

    #elif head == 'dev':
    #    base = 'release'
    #elif head == 'release':
    #    base = 'master'
    #else:
    #    base = ''
    #base = cutie.select_propmt(cc.value('pr','base'),b).replace('*','')
    base = base.strip()
    if head == base or base == '':
        cutie.cprint('error', (cc.value('git-talk', 'error')))
    else:
        title = cutie.get_input(cc.value('pr', 'title'))
        #summary = cutie.get_input(cc.value('pr','summary'))
        detail = cutie.get_input(cc.value('pr', 'detail'))
        #detail = summary.upper() + '\n' + detail
        pr = gh.pull_request(title, detail, head, base)
        if pr is None:
            cutie.cprint('error', (cc.value('git-talk', 'error')))
        else:
            cutie.cprint('info', (cc.value('pr', 'done').format(base, head)))

    b = gfunc.subprocess_cmd(repo['path'], [["git", "checkout", current_b]])
Example #4
0
def pr_tag_release(cc, repo):
    while True:
        names = cc.value('pr-tag-release', 'steps').split(',')
        b, status = stts.current_status(cc, repo)
        if status == 1:
            break
        msg = cc.value('git-talk', 'message').format(repo["name"], b, status)
        name = cutie.select_propmt(msg, names)
        if name == names[0]:
            pr.pr(cc, repo)
        elif name == names[1]:
            branches.add_tag(cc, repo)
        # elif name == names[2]:
        #     pass
        #     #merge_tag_master(cc,repo)
        elif name == names[2]:
            m = 'back to upper menu'
            if cutie.get_exit(value=name, ex=False, message=m):
                break
Example #5
0
def commit(cc, repo, comment="", up_stream="origin"):
    if repo['branch'] in ('master'):
        cutie.cprint('alert',
                     (cc.value('commit', 'error').format(repo['branch'])))
    else:
        summary = ''
        names = cc.value('commit', 'commit_prefix').strip().split(",")
        while len(summary) < 1:
            summary = cutie.select_propmt(cc.value('commit', 'summary'), names)
            if summary.lower() in ('exit', 'cancel'):
                cutie.get_exit()
                return None
        while len(comment) < 1:
            comment = cutie.get_input(cc.value('commit', 'comment'))
        comment = summary + ': ' + comment
        cutie.cprint('wait', (cc.value('git-talk', 'wait')))
        path = repo['path']
        # git_path = "C:/Program Files/Git/cmd/git.exe"
        command = [["git", "add", "."], ["git", "commit", "-m", comment],
                   ["git", "pull", up_stream],
                   ["git", "push", "-u", up_stream, repo['branch'].strip()]]
        b, error = gfunc.subprocess_cmd(path, command)
Example #6
0
def pick_branch(cc, repo):
    
    path = repo['path']
    cc.save("access","current_repo", repo["name"])
    command =[['git','branch']]
    b,error = gfunc. subprocess_cmd(path, command)
    selected_branch = ''
    working_list = []
    for ib in b[0].split('\n'):
        if ib.strip():
            if ib.strip().startswith('*'):
                selected_branch = ib.strip().replace('*', '')
            if ib.strip().replace('*', '') not in ('master', 'dev', 'release'):
                working_list.append(ib)
    create_b = cc.value("branch", "create_branch")
    working_list.append(create_b)
    delete_b = cc.value("branch", "close_branch")
    working_list.append(delete_b)

    name = cutie.select_propmt(cc.value('project', 'branch'),
                         working_list).replace('*', '').strip()
    if not cutie.get_exit(name):
        # TODO: will config prefix_ ,created by xxxxx and linked issue or jira
        if name == create_b:
            br_type = {'feature': repo["task"], 'hotfix': repo["hotfix"]}
            ty = cutie.select_propmt(cc.value('branch', 'branch_type'), [
                               'feature', 'hotfix']).strip()
            if not cutie.get_exit(ty):
                if ty == 'hotfix':
                    nb_from = 'master'
                else:
                    nb_from = 'dev'

                nb = cutie.get_input(cc.value('branch', 'new_branch'))
                nb = br_type[ty] + nb
                cutie.cprint('info', 'creating {0} branch: {1}'.format(ty, nb))
                if nb not in b:
                    cmd_branch = [["git", "checkout", nb_from], [
                        "git", "pull"], ["git", "checkout", "-b", nb],["git","push","--set-upstream", "origin", nb]]
                    b, error = gfunc.subprocess_cmd(path, cmd_branch)
                    if error == 0:
                        selected_branch = nb
                    else:
                        cutie.cprint('error', cc.value('git-talk', 'error'))

                    # b = gfunc. subprocess_cmd(path, 'checkout {0}'.format(nb_from))
                    # b = gfunc. subprocess_cmd(path, 'checkout -b {0}'.format(nb))
                else:
                    cutie.cprint('alarm', cc.value(
                    'branch', 'existing_branch').fromat(nb))
        elif name == delete_b:
            command = [["git", "branch"]]
            b, error = gfunc.subprocess_cmd(repo['path'], command)
            if error == 0:
                ty = cutie.select_propmt(
                    cc.value('branch', 'close_picked'), b[0].split('\n')).strip()
                if not cutie.get_exit(ty):
                    if '*' in ty:
                        cutie.cprint('alarm', cc.value(
                            'branch', 'current_alarm'))
                    else:
                        b, error = gfunc.subprocess_cmd(repo['path'], [["git", "branch", "-d", ty]])
                        if error == 1 :
                            if cutie.prompt_yn(cc.value('branch', 'confirm_delete').format(ty)):
                                b, error = gfunc.subprocess_cmd(repo['path'], [["git", "branch", "-D", ty]])
                                if error == 0 :
                                    b, error = gfunc.subprocess_cmd(repo['path'], [["git", "push", "origin", "--delete",ty]])
                        else:
                            b, error = gfunc.subprocess_cmd(repo['path'], [["git", "push", "origin", "--delete",ty]])
        else:
            # checkout the branch
            if name != selected_branch:
                command =[['git','checkout', name]]
                bb,error = gfunc. subprocess_cmd(path,command )
                if error == 0:
                    cutie.cprint('info', cc.value(
                        'project', 'checkout').format(name))
                    selected_branch = name
                else:
                    cutie.cprint('error', bb + '------------\n error:', str(error))
                    cutie.cprint('info', cc.value('project', 'checkout_error').format(name))
                    cutie.cprint('error', cc.value('git-talk', 'error'))

    repo['branch'] = selected_branch
    cc.save_json("repo_json", repo["name"], repo)
    return repo