예제 #1
0
파일: Release.py 프로젝트: rec/grit
def _pull_request(pull, working_branch):
    if pull.user == Settings.USER:
        nickname = 'origin'
    else:
        try:
            nickname = Remote.inverse()[pull.user]
        except KeyError:
            Remote.add_remote(pull.user, pull.user)
            nickname = pull.user

    keywords = {
        'nickname': nickname,
        'pull_branch': pull.branch,
        'working_branch': working_branch,
        'print': print if ARGS.verbose else None,
    }

    Call.runlines(
        """git fetch {nickname} {pull_branch}
           git checkout {nickname}/{pull_branch}
           git rebase --preserve-merges {working_branch}""",
        **keywords)

    # Store the commit ID at this point so we can merge back to it.
    keywords['commit_id'] = Git.commit_id()
    Call.runlines(
        """git checkout {working_branch}
           git merge --ff-only {commit_id}""",
        **keywords)

    _check_vcxproj()
예제 #2
0
파일: Import.py 프로젝트: rec/grit
def run_import(branch, **kwds):
    user, branch = parse_branch(branch)
    if branch not in Git.branch1es(user):
        raise ValueError(_BRANCH_ERROR.format(**locals()))
    if user == Settings.USER:
        Git.git('checkout', branch)
    else:
        Remote.remote(user, **kwds)
        Git.git('fetch', user, branch)
        Git.git('checkout', '-b', '/'.join([user, branch]))
예제 #3
0
파일: Start.py 프로젝트: rec/grit
def clone(directory):
    settings = Project.settings("clone")
    branch = settings.get("base_branch", "develop")

    root = GitRoot.root(os.getcwd())
    if root:
        directory = directory or os.path.basename(root)
        root = os.path.dirname(root)
    else:
        directory = directory or Settings.PROJECT
        root = os.getcwd()

    directory = File.next_version(os.path.join(root, directory))
    settings.update(branch=branch, directory=directory, project=Settings.PROJECT, user=Settings.USER)
    # Call git clone.
    if Git.git(*_CLONE.format(**settings).split(), cwd=root):
        raise ValueError("Failed to start new directory")

    Remote.remote("all", cwd=directory)
    Remote.remote("upstream", Settings.PROJECT, directory)
    Git.git("pull", "upstream", branch)
    banner("Created", branch + ", directory", directory)
    return directory
예제 #4
0
파일: Slack.py 프로젝트: rec/grit
def slack(days=2):
    days = int(days)
    inverse = Remote.inverse()
    slack_names = Project.settings('slack')
    def slack(user):
        return '@' + slack_names[user]

    label_names = dict((v, k) for (k, v) in Project.settings('labels').items())

    def labels_to_names(labels):
        return ' '.join(
            slack(label_names[i]) for i in labels if i in label_names)

    previous = get_previous_business_day(days)
    def match(issue):
        if issue['updated_at'] >= previous:
            # print('too new:', issue['number'], issue['updated_at'], previous)
            return False
        for label in issue['labels']:
            if label['name'] in ('Passed', 'Hold'):
                # print('passed:', issue['number'])
                return False
        # print('slack:', issue['number'])
        return True

    if False:
        import json
        json.dump(Git.issues(), open('/tmp/git-issues.json', 'w'),
                  sort_keys=True, indent=4, separators=(',', ': '))
    slackers = [i for i in Git.issues() if match(i)]
    if not slackers:
        return;
    print('\nPull requests that are over %d business day%s stale:' % (
          days, '' if days == 1 else 's'))

    labels = Git.labels()
    for issue in sorted(slackers, key=operator.itemgetter('updated_at')):
        try:
            user = slack(inverse[issue['user']['login']]) + ':'
            update = issue['updated_at'][:10]
            url = Open.get_url(str(issue['number']))
            lab = labels_to_names(labels[issue['number']])
            print('  %s (%s): %s (%s)' % (url, update, user, lab))
        except Exception as e:
            print('ERROR:', e)
            raise
    print()
예제 #5
0
def get_url(name='', user=''):
    if not platform.system() in _OPEN_COMMANDS:
        raise ValueError("Can't open a URL for platform.system() = " + plat)

    if user and 'upstream'.startswith(user):
        user = Settings.PROJECT_USER
    elif name and 'upstream'.startswith(name):
        user = Settings.PROJECT_USER
        name = ''
    elif user:
        for nickname, account in Remote.remote():
            if nickname == account:
                user = account
                break
    else:
        user = Settings.USER

    context = get_context(user)
    fmt = get_format_string(name, user, context)
    return fmt.format(**context)