Example #1
0
def start(project_name, analyser_access_token, email_sender=None):
    app = current_app._get_current_object()

    analyse_github = GitHub(app)

    @analyse_github.access_token_getter
    def token_getter():
        # print("another place %s" % analyser_access_token)
        return analyser_access_token

    try:
        analyse_github.get('repos/%s' % project_name)
    except:
        return False

    Thread(target=start_analyse,
           args=[app, project_name, analyse_github, email_sender]).start()
    return True
Example #2
0
def check_repo(repo, access_token):
    """ Check repo existence.
        Args:
            repo(full name), access_token
        Returns:
            None for not found,
            json result for found.
    """
    app = current_app._get_current_object()
    github_api_caller = GitHub(app)

    @github_api_caller.access_token_getter
    def token_getter():
        return access_token

    try:
        result = github_api_caller.get('repos/%s' % repo)
    except:
        return None
    return result
Example #3
0
def start_analyse(repo, access_token):
    """ Start analyse on repo using github_api_caller(contains personal access token)
        Args:
            app context, repo, github_api_caller
        Returns:
            None
    """
    app = current_app._get_current_object()
    github_api_caller = GitHub(app)

    @github_api_caller.access_token_getter
    def token_getter():
        return access_token

    print("-----start analysing for %s-----" % repo)

    repo_info = github_api_caller.get('repos/%s' % repo)
    print('finish fetch repo info for %s' % repo)

    # Save forks' list into local
    forks_list_path = current_app.config[
        'LOCAL_DATA_PATH'] + "/" + repo + '/forks_list.json'
    if current_app.config['USE_LOCAL_FORKS_LIST'] and os.path.exists(
            forks_list_path):
        with open(forks_list_path) as read_file:
            repo_forks_list = json.load(read_file)
    else:
        repo_forks_list = github_api_caller.request('GET',
                                                    'repos/%s/forks' % repo,
                                                    True)
        localfile_tool.write_to_file(forks_list_path, repo_forks_list)

    print('finish fetch fork list for %s' % repo)

    project_updater.start_update(repo, repo_info, repo_forks_list)

    send_mail_for_repo_finish(repo)

    print("-----finish analysing for %s-----" % repo)