示例#1
0
def create_git_template_symlinks():
    """
    Constructs absolute path symlinks in the template directory to the CI
    git hook handler.
    """

    hook = get_relative_file("git_hook.py")
    hook_dir = get_relative_file("templates", "hooks")
    

    for action in ALLOWED_HOOKS:
        hook_link = os.path.join(hook_dir, action)
        try:
            os.symlink(hook, hook_link)
        except OSError as e:
            if e.errno == os.errno.EEXIST:
                os.unlink(hook_link)
                os.symlink(hook, hook_link)
            else:
                raise
示例#2
0
def git_config():
    """
    Sets name and email address in global config.  We don't want any anonymous
    commits.  Also copies standard git config aliases to global config.
    """
    print "configure git"
    g = git.Git()

    params = dict()

    #gather template params
    try:
        params['name'] = g.config('--global', 'user.name')
    except git.GitCommandError:
        params['name'] = raw_input("Enter your name: ")

    try:
        params['email'] = g.config('--global', 'user.email')
    except git.GitCommandError:
        params['email'] = raw_input("Enter your email address: ")

    try:
        params['jira_server'] = g.config('--global', 'jira.server')
    except git.GitCommandError:
        params['jira_server'] = raw_input("Please enter your JIRA server: ")

    try:
        params['jira_user_name'] = g.config('--global', 'jira.username')
    except git.GitCommandError:
        params['jira_user_name'] = raw_input("Please enter your JIRA user name: ")

    try:
        params['jira_password'] = g.config('--global', 'jira.password')
    except git.GitCommandError:
        params['jira_password'] = getpass("Please enter your JIRA password " +
            "(will be stored in plaintext, leave blank for a runtime prompt): ")

    params['template_dir'] = "templates"
    params['pwd'] = os.path.dirname(os.path.realpath(__file__))
    template_file = get_relative_file("jinja_templates", "global.conf")
    
    with open(template_file) as f:
        template = Template(f.read())
        source_config = StringIO(template.render(params))

    #hack to make git config parser happy ... it expects a name for the file
    source_config.name = "tmp"
    git_merge_global_config(source_config)
示例#3
0
def prepare_commit_msg(repo, commit_file, *args):

    params = {}
    template_file = get_relative_file("jinja_templates", "commit_template.txt")

    with open(template_file) as f:
        template = Template(f.read())
        source_config = StringIO(template.render(params))

    # save the configured template
    with open(commit_file, 'r+') as f:
        # TODO: Handle template, merge, squash, and commit as well?
        if len(args) > 0 and args[0] == "message": # commit -m
            # Just use the message provided
            # Otherwise the commented lines
            # show up in the commit message
            pass
        else: # commit (editor)
            orig_content = StringIO(f.read())
            f.seek(0)
            f.write("\n") #Leave a blank line for the commit message
            f.write(source_config.getvalue())
            f.write(orig_content.getvalue())