def fetch(store):
    issues, comments = bitbucket.stores(store)
    get = bitbucket.get_getter(store)
    current_issues = bitbucket.iter_issues(get)
    for elem in utils.gprocess(current_issues, label="Fetching Issues"):
        eid = elem['local_id']
        issues[eid] = elem
        existing = comments.get(eid)
        comments[eid] = bitbucket.get_comments(get, elem, existing)
def fetch(store):
    issues, comments = bitbucket.stores(store)
    get = bitbucket.get_getter(store)
    current_issues = bitbucket.iter_issues(get)
    for elem in utils.gprocess(current_issues, label="Fetching Issues"):
        eid = elem['local_id']
        issues[eid] = elem
        existing = comments.get(eid)
        comments[eid] = bitbucket.get_comments(get, elem, existing)
def convert(store, usermap=None):
    issues, comments = bitbucket.stores(store)

    simple_store = FileStore.ensure(store.path / 'github_uploads')

    repo = store['repos']['bitbucket']
    items = issues.items()
    usermap = usermap or store.get('users', {})
    for key, issue in gprocess(items, label='Preparing Import Requests'):
        issue['comments'] = comments[key]
        simplified = bitbucket.simplify_issue(bb_issue=issue,
                                              repo=repo,
                                              usermap=usermap)
        simple_store[key] = simplified
def convert(store):
    issues, comments = bitbucket.stores(store)

    simple_store = FileStore.ensure(store.path / 'github_uploads')

    repo = store['repos']['bitbucket']
    items = issues.items()
    for key, issue in gprocess(items, label='Preparing Import Requests'):
        issue['comments'] = comments[key]
        simplified = bitbucket.simplify_issue(
                bb_issue=issue,
                repo=repo,
                usermap=store.get('users', {}))
        simple_store[key] = simplified
def extract_users(store, usermap=None):
    """extract username list from authormap"""

    issues, comments = bitbucket.stores(store)

    usermap = usermap or store.get('users', {})
    for item in gprocess(issues, label='Extracting usermap'):
        issue = issues[item]
        comment_list = comments[item] or []  # accounts for None

        authors = utils.contributors(issue, comment_list)

        for author in authors:
            if author not in usermap:
                usermap[author] = None
    store['users'] = usermap
def extract_users(store):
    """extract username list from authormap"""

    issues, comments = bitbucket.stores(store)

    usermap = store.get('users', {})
    for item in gprocess(issues,
                         label='Extracting usermap'):
        issue = issues[item]
        comment_list = comments[item] or []  # accounts for None

        authors = utils.contributors(issue, comment_list)

        for author in authors:
            if author not in usermap:
                usermap[author] = None
    store['users'] = usermap
def upload_github_issues(store, token):
    from wait_for import wait_for
    post = get_github_issue_poster(store, token)
    simple_store = FileStore.ensure(store.path / 'github_uploads')
    for issue in gprocess(sorted(simple_store, key=int),
                          label='Uploading Import Requests'):
        response = post.get_issue(issue)
        if response.status_code == 200:
            raise ValueError(issue)
        post(simple_store.raw_data(issue))

        def failure_check(response):
            print(repr(response.status_code), response.url)
            return response.status_code != 200

        wait_for(post.get_issue, (issue, ),
                 fail_condition=failure_check,
                 timeout=500)
def upload_github_issues(store, token):
    from wait_for import wait_for
    post = get_github_issue_poster(store, token)
    simple_store = FileStore.ensure(store.path / 'github_uploads')
    for issue in gprocess(sorted(simple_store, key=int),
                          label='Uploading Import Requests'):
        response = post.get_issue(issue)
        if response.status_code == 200:
            raise ValueError(issue)
        post(simple_store.raw_data(issue))

        def failure_check(response):
            print(repr(response.status_code), response.url)
            return response.status_code != 200
        wait_for(
            post.get_issue, (issue,),
            fail_condition=failure_check,
            timeout=500)
def user_stats(store, usermap=None, only_unmapped=False):
    """extract username list from authormap"""

    issues, comments = bitbucket.stores(store)

    users = store.get('users', {})
    usermap = usermap or {}
    for item in gprocess(issues, label='Extracting usermap'):
        issue = issues[item]
        comment_list = comments[item] or []  # accounts for None

        authors = utils.contributors(issue, comment_list, include_date=True)

        for (author, last_updated) in authors:
            if only_unmapped and users.get(author) is not None:
                continue
            infos = usermap.setdefault(author, {})
            infos['count'] = infos.get('count', 0) + 1
            infos['last_updated'] = max(last_updated,
                                        infos.get('last_updated', ''))
            infos.setdefault('status', set()).add(issue['status'])
    max_author_len = max(len(x) for x in usermap)
    max_count_len = len("%d" % max(x['count'] for x in usermap.values()))
    usermap_items = list(dict(author=k, **v) for k, v in usermap.items())
    usermap_items = sorted(usermap_items,
                           key=operator.itemgetter('count', 'last_updated'))
    for info in usermap_items:
        print("{author:{max_author_len}} "
              "{count:>{max_count_len}}  "
              "{last_updated}  {status}".format(
                  author=info['author'],
                  count=info['count'],
                  last_updated=info['last_updated'],
                  status=info['status'],
                  max_author_len=max_author_len,
                  max_count_len=max_count_len))
def upload_github_issues(store, token):
    post = get_github_issue_poster(store, token)
    simple_store = FileStore.ensure(store.path / 'github_uploads')
    for issue in gprocess(simple_store, label='Uploading Import Requests'):
        post(simple_store.raw_data(issue))