Exemple #1
0
def proxy_comments(number):
    '''XHR endpoint to get issues comments from GitHub, either as an authed
    user, or as one of our proxy bots.'''
    if request.method == 'POST':
        try:
            comment_data = json.loads(request.data)
            body = json.dumps({"body": comment_data['rawBody']})
            path = 'repos/{0}/{1}/comments'.format(REPO_URI, number)
            comment = github.raw_request('POST', path, data=body)
            return (json.dumps(comment.json()), comment.status_code,
                    {'content-type': JSON_MIME})
        except GitHubError as e:
            print('GitHubError: ', e.response.status_code)
            return (':(', e.response.status_code)
    else:
        if g.user:
            comments = github.raw_request('GET', 'repos/{0}/{1}/comments'.format(
                app.config['ISSUES_REPO_URI'], number))
        else:
            comments = proxy_request('get', '/{0}/comments'.format(number),
                                     token='commentbot')
        response = make_response(json.dumps(comments.json()))
        response.headers['etag'] = comments.headers.get('etag')
        response.headers['cache-control'] = comments.headers.get('cache-control')
        response.headers['content-type'] = JSON_MIME
        return response
Exemple #2
0
def proxy_comments(number):
    """XHR endpoint to get issues comments from GitHub.

    Either as an authed user, or as one of our proxy bots.
    """
    if request.method == "POST":
        try:
            comment_data = json.loads(request.data)
            body = json.dumps({"body": comment_data["rawBody"]})
            path = "repos/{0}/{1}/comments".format(ISSUES_PATH, number)
            comment = github.raw_request("POST", path, data=body)
            return (json.dumps(comment.json()), comment.status_code, {"content-type": JSON_MIME})
        except GitHubError as e:
            print("GitHubError: ", e.response.status_code)
            return (":(", e.response.status_code)
    else:
        request_headers = get_request_headers(g.request_headers)

        if g.user:
            comments = github.raw_request(
                "GET", "repos/{0}/{1}/comments".format(ISSUES_PATH, number), headers=request_headers
            )
        else:
            comments = proxy_request("get", "/{0}/comments".format(number), headers=request_headers)
        return (comments.content, comments.status_code, get_headers(comments))
Exemple #3
0
def proxy_comments(number):
    '''XHR endpoint to get issues comments from GitHub.

    Either as an authed user, or as one of our proxy bots.
    '''
    if request.method == 'POST':
        try:
            comment_data = json.loads(request.data)
            body = json.dumps({"body": comment_data['rawBody']})
            path = 'repos/{0}/{1}/comments'.format(REPO_URI, number)
            comment = github.raw_request('POST', path, data=body)
            return (json.dumps(comment.json()), comment.status_code, {
                'content-type': JSON_MIME
            })
        except GitHubError as e:
            print('GitHubError: ', e.response.status_code)
            return (':(', e.response.status_code)
    else:
        if g.user:
            comments = github.raw_request(
                'GET',
                'repos/{0}/{1}/comments'.format(app.config['ISSUES_REPO_URI'],
                                                number))
        else:
            comments = proxy_request('get', '/{0}/comments'.format(number))
        return (comments.content, comments.status_code, get_headers(comments))
def proxy_comments(number):
    '''XHR endpoint to get issues comments from GitHub.

    Either as an authed user, or as one of our proxy bots.
    '''
    if request.method == 'POST':
        try:
            comment_data = json.loads(request.data)
            body = json.dumps({"body": comment_data['rawBody']})
            path = 'repos/{0}/{1}/comments'.format(ISSUES_PATH, number)
            comment = github.raw_request('POST', path, data=body)
            return (json.dumps(comment.json()), comment.status_code,
                    {'content-type': JSON_MIME})
        except GitHubError as e:
            print('GitHubError: ', e.response.status_code)
            return (':(', e.response.status_code)
    else:
        if g.user:
            request_headers = get_request_headers(g.request_headers)
            comments = github.raw_request(
                'GET',
                'repos/{0}/{1}/comments'.format(
                    ISSUES_PATH, number),
                headers=request_headers
                )
        else:
            comments = proxy_request('get', '/{0}/comments'.format(number))
        return (comments.content, comments.status_code, get_headers(comments))
def get_search_results(query_string=None):
    '''XHR endpoint to get results from GitHub's Search API.

    We're specifically searching "issues" here, which seems to make the most
    sense. Note that the rate limit is different for Search: 30 requests per
    minute.

    If a user hits the rate limit, the Flask Limiter extension will send a
    429. See @app.error_handler(429) in views.py.

    This method can take a query_string argument, to be called from other
    endpoints, or the query_string can be passed in via the Request object.

    Not cached.
    '''
    search_uri = 'https://api.github.com/search/issues'
    # TODO: handle sort and order parameters.
    params = request.args.copy()

    if query_string is None:
        query_string = params.get('q')
        # restrict results to our repo.
    query_string += " repo:{0}".format(REPO_PATH)
    params['q'] = query_string

    if g.user:
        request_headers = get_request_headers(g.request_headers)
        results = github.raw_request('GET', 'search/issues', params=params,
                                     headers=request_headers)
    else:
        results = proxy_request('get', params=params, uri=search_uri)
    return (results.content, results.status_code, get_headers(results))
Exemple #6
0
def get_search_results(query_string=None, params=None):
    """XHR endpoint to get results from GitHub's Search API.

    We're specifically searching "issues" here, which seems to make the most
    sense. Note that the rate limit is different for Search: 30 requests per
    minute.

    If a user hits the rate limit, the Flask Limiter extension will send a
    429. See @app.error_handler(429) in views.py.

    This method can take a query_string argument, to be called from other
    endpoints, or the query_string can be passed in via the Request object.

    Not cached.
    """
    params = params or request.args.copy()
    query_string = query_string or params.get("q")
    search_uri = "https://api.github.com/search/issues"

    # restrict results to our repo.
    query_string += " repo:{0}".format(REPO_PATH)
    params["q"] = query_string

    # convert issues api to search api params here.
    params = normalize_api_params(params)
    request_headers = get_request_headers(g.request_headers)

    if g.user:
        results = github.raw_request("GET", "search/issues", params=params, headers=request_headers)
    else:
        results = proxy_request("get", params=params, uri=search_uri, headers=request_headers)
    return (results.content, results.status_code, get_headers(results))
Exemple #7
0
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of x types:
    * new
    * contactready
    * needsdiagnosis
    * sitewait
    '''
    category_list = [
        'contactready', 'needscontact', 'needsdiagnosis', 'sitewait'
    ]
    issues_path = 'repos/{0}'.format(ISSUES_PATH)
    params = request.args.copy()

    if issue_category in category_list:
        # add "status-" before the filter param to match the naming scheme
        # of the repo labels.
        params['labels'] = 'status-' + issue_category
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    # Note that 'new' here is primarily used on the hompage.
    # For paginated results on the /issues page, see /issues/search/new.
    elif issue_category == 'new':
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
        # Do not send random JSON to filter_new
        if issues.status_code == 200:
            return (filter_new(json.loads(issues.content)), issues.status_code,
                    get_headers(issues))
        else:
            return ({}, issues.status_code, get_headers(issues))
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #8
0
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of x types:
    * new
    * contactready
    * needsdiagnosis
    * sitewait
    '''
    category_list = ['contactready', 'needscontact',
                     'needsdiagnosis', 'sitewait']
    issues_path = 'repos/{0}'.format(ISSUES_PATH)
    params = request.args.copy()

    if issue_category in category_list:
        # add "status-" before the filter param to match the naming scheme
        # of the repo labels.
        params['labels'] = 'status-' + issue_category
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    # Note that 'new' here is primarily used on the homepage.
    # For paginated results on the /issues page, see /issues/search/new.
    elif issue_category == 'new':
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
        # Do not send random JSON to filter_new
        if issues.status_code == 200:
            return (filter_new(json.loads(issues.content)),
                    issues.status_code, get_headers(issues))
        else:
            return ({}, issues.status_code, get_headers(issues))
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #9
0
def user_issues():
    """API endpoint to return issues filed by the logged in user.

    Not cached.
    """
    get_user_info()
    path = "repos/{0}?creator={1}&state=all".format(ISSUES_PATH, session["username"])
    request_headers = get_request_headers(g.request_headers)
    issues = github.raw_request("GET", path, headers=request_headers)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #10
0
def user_issues():
    '''API endpoint to return issues filed by the logged in user.

    Not cached.
    '''
    get_user_info()
    path = 'repos/{0}?creator={1}&state=all'.format(REPO_URI,
                                                    session['username'])
    issues = github.raw_request('GET', path)
    return (issues.content, issues.status_code, get_headers(issues))
def proxy_issues():
    '''API endpoint to list all issues from GitHub.'''
    params = request.args.copy()

    if g.user:
        issues = github.raw_request('GET', 'repos/{0}'.format(ISSUES_PATH),
                                    params=params)
    else:
        issues = proxy_request('get', params=params)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #12
0
def get_issue_category(issue_category):
    """Return all issues for a specific category.

    issue_category can be of x types:
    * new
    * contactready
    * needsdiagnosis
    * sitewait
    """
    category_list = ["contactready", "needscontact", "needsdiagnosis", "sitewait"]
    issues_path = "repos/{0}".format(ISSUES_PATH)
    params = request.args.copy()

    if issue_category in category_list:
        # add "status-" before the filter param to match the naming scheme
        # of the repo labels.
        params["labels"] = "status-" + issue_category
        if g.user:
            issues = github.raw_request("GET", issues_path, params=params)
        else:
            issues = proxy_request("get", params=params)
    elif issue_category == "closed":
        params["state"] = "closed"
        if g.user:
            issues = github.raw_request("GET", issues_path, params=params)
        else:
            issues = proxy_request("get", params=params)
    # Note that 'new' here is primarily used on the hompage.
    # For paginated results on the /issues page, see /issues/search/new.
    elif issue_category == "new":
        if g.user:
            issues = github.raw_request("GET", issues_path, params=params)
        else:
            issues = proxy_request("get", params=params)
        # Do not send random JSON to filter_new
        if issues.status_code == 200:
            return (filter_new(json.loads(issues.content)), issues.status_code, get_headers(issues))
        else:
            return ({}, issues.status_code, get_headers(issues))
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
    return (issues.content, issues.status_code, get_headers(issues))
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of x types:
    * untriaged (We take care in case there’s no bug)
    * contactready
    * needsdiagnosis
    * sitewait
    '''
    category_list = ['contactready', 'needsdiagnosis', 'sitewait']
    issues_path = 'repos/{0}'.format(ISSUES_PATH)
    params = request.args.copy()

    if issue_category in category_list:
        params['labels'] = issue_category
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
    # Note that 'untriaged' here is primarily used on the hompage.
    # For paginated results on the /issues page, see /issues/search/untriaged.
    elif issue_category == 'untriaged':
        if g.user:
            issues = github.raw_request('GET', issues_path, params=params)
        else:
            issues = proxy_request('get', params=params)
        # Do not send random JSON to filter_untriaged
        if issues.status_code == 200:
            return (filter_untriaged(json.loads(issues.content)),
                    issues.status_code, get_headers(issues))
        else:
            return ({}, issues.status_code, get_headers(issues))
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #14
0
def proxy_issue(number):
    """XHR endpoint to get issue data from GitHub.

    either as an authed user, or as one of our proxy bots.
    """
    request_headers = get_request_headers(g.request_headers)
    if g.user:
        issue = github.raw_request("GET", "repos/{0}/{1}".format(ISSUES_PATH, number), headers=request_headers)
    else:
        issue = proxy_request("get", "/{0}".format(number), headers=request_headers)
    return (issue.content, issue.status_code, get_headers(issue))
Exemple #15
0
def proxy_issue(number):
    '''XHR endpoint to get issue data from GitHub.

    either as an authed user, or as one of our proxy bots.
    '''
    if g.user:
        issue = github.raw_request('GET', 'repos/{0}/{1}'.format(
            app.config['ISSUES_REPO_URI'], number))
    else:
        issue = proxy_request('get', '/{0}'.format(number))
    return (issue.content, issue.status_code, get_headers(issue))
Exemple #16
0
def get_sitewait():
    '''Return all issues with a "sitewait" label.

    Cached for 5 minutes.
    '''
    if g.user:
        path = 'repos/{0}?labels=sitewait'.format(REPO_URI)
        issues = github.raw_request('GET', path)
    else:
        issues = proxy_request('get', '?labels=sitewait')
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #17
0
def user_issues():
    '''API endpoint to return issues filed by the logged in user.

    Not cached.
    '''
    get_user_info()
    path = 'repos/{0}?creator={1}&state=all'.format(
        REPO_URI, session['username']
    )
    issues = github.raw_request('GET', path)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #18
0
def get_rate_limit():
    '''Endpoint to display the current GitHub API rate limit.

    Will display for the logged in user, or webcompat-bot if not logged in.
    See https://developer.github.com/v3/rate_limit/.
    '''
    if g.user:
        rl = github.raw_request('GET', 'rate_limit')
    else:
        rl = proxy_request('get', uri='https://api.github.com/rate_limit')
    return rl.content
Exemple #19
0
def get_sitewait():
    '''Return all issues with a "sitewait" label.

    Cached for 5 minutes.
    '''
    if g.user:
        path = 'repos/{0}?labels=sitewait'.format(REPO_URI)
        issues = github.raw_request('GET', path)
    else:
        issues = proxy_request('get', '?labels=sitewait')
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #20
0
def get_rate_limit():
    '''Endpoint to display the current GitHub API rate limit.

    Will display for the logged in user, or webcompat-bot if not logged in.
    See https://developer.github.com/v3/rate_limit/.
    '''
    if g.user:
        rl = github.raw_request('GET', 'rate_limit')
    else:
        rl = proxy_request('get', uri='https://api.github.com/rate_limit')
    return rl.content
Exemple #21
0
def proxy_issue(number):
    '''XHR endpoint to get issue data from GitHub.

    either as an authed user, or as one of our proxy bots.
    '''
    if g.user:
        issue = github.raw_request(
            'GET', 'repos/{0}/{1}'.format(app.config['ISSUES_REPO_URI'],
                                          number))
    else:
        issue = proxy_request('get', '/{0}'.format(number))
    return (issue.content, issue.status_code, get_headers(issue))
Exemple #22
0
def get_untriaged():
    '''Return all issues that are "untriaged". Essentially all unclosed issues
    with no activity. Cached for five minutes.'''
    if g.user:
        issues = github.raw_request('GET', 'repos/{0}'.format(REPO_URI))
    else:
        issues = proxy_request('get')
    response = make_response(json.dumps(filter_untriaged(issues.json())))
    response.headers['etag'] = issues.headers.get('etag')
    response.headers['cache-control'] = issues.headers.get('cache-control')
    response.headers['content-type'] = JSON_MIME
    return response
Exemple #23
0
def get_contactready():
    '''Return all issues with a "contactready" label. Cached for five
    minutes.'''
    if g.user:
        uri = 'repos/{0}?labels=contactready'.format(REPO_URI)
        issues = github.raw_request('GET', uri)
    else:
        issues = proxy_request('get', '?labels=contactready')
    response = make_response(json.dumps(issues.json()))
    response.headers['etag'] = issues.headers.get('etag')
    response.headers['cache-control'] = issues.headers.get('cache-control')
    response.headers['content-type'] = JSON_MIME
    return response
def get_repo_labels():
    '''XHR endpoint to get all possible labels in a repo.

    Cached for 10 minutes.
    '''
    if g.user:
        request_headers = get_request_headers(g.request_headers)
        path = 'repos/{0}/labels'.format(REPO_PATH)
        labels = github.raw_request('GET', path, headers=request_headers)
        return (labels.content, labels.status_code, get_headers(labels))
    else:
        # only authed users should be hitting this endpoint
        abort(401)
Exemple #25
0
def get_repo_labels():
    '''XHR endpoint to get all possible labels in a repo.

    Cached for 10 minutes.
    '''
    if g.user:
        request_headers = get_request_headers(g.request_headers)
        path = 'repos/{0}/labels'.format(REPO_PATH)
        labels = github.raw_request('GET', path, headers=request_headers)
        return (labels.content, labels.status_code, get_headers(labels))
    else:
        # only authed users should be hitting this endpoint
        abort(401)
Exemple #26
0
def proxy_issue(number):
    '''XHR endpoint to get issue data from GitHub, either as an authed
    user, or as one of our proxy bots.'''
    if g.user:
        issue = github.raw_request('GET', 'repos/{0}/{1}'.format(
            app.config['ISSUES_REPO_URI'], number))
    else:
        issue = proxy_request('get', '/{0}'.format(number))
    response = make_response(json.dumps(issue.json()))
    response.headers['etag'] = issue.headers.get('etag')
    response.headers['cache-control'] = issue.headers.get('cache-control')
    response.headers['last-modified'] = issue.headers.get('last-modified')
    response.headers['content-type'] = JSON_MIME
    return response
Exemple #27
0
def get_repo_labels():
    '''XHR endpoint to get all possible labels in a repo.

    Cached for 10 minutes.
    '''
    # Chop off /issues. Someone feel free to refactor the ISSUES_REPO_URI.
    labels_path = app.config['ISSUES_REPO_URI'][:-7]
    if g.user:
        path = 'repos/{0}/labels'.format(labels_path)
        labels = github.raw_request('GET', path)
        return (labels.content, labels.status_code, get_headers(labels))
    else:
        # only authed users should be hitting this endpoint
        abort(401)
Exemple #28
0
def get_rate_limit():
    """Endpoint to display the current GitHub API rate limit.

    Will display for the logged in user, or webcompat-bot if not logged in.
    See https://developer.github.com/v3/rate_limit/.
    """

    rate_limit_uri = "https://api.github.com/rate_limit"
    request_headers = get_request_headers(g.request_headers)
    if g.user:
        rl = github.raw_request("GET", "rate_limit", headers=request_headers)
    else:
        rl = proxy_request("get", uri=rate_limit_uri, headers=request_headers)
    return rl.content
Exemple #29
0
def get_repo_labels():
    '''XHR endpoint to get all possible labels in a repo.

    Cached for 10 minutes.
    '''
    # Chop off /issues. Someone feel free to refactor the ISSUES_REPO_URI.
    labels_path = app.config['ISSUES_REPO_URI'][:-7]
    if g.user:
        path = 'repos/{0}/labels'.format(labels_path)
        labels = github.raw_request('GET', path)
        return (labels.content, labels.status_code, get_headers(labels))
    else:
        # only authed users should be hitting this endpoint
        abort(401)
Exemple #30
0
def proxy_issue(number):
    '''XHR endpoint to get issue data from GitHub.

    either as an authed user, or as one of our proxy bots.
    '''
    request_headers = get_request_headers(g.request_headers)
    if g.user:
        issue = github.raw_request('GET',
                                   'repos/{0}/{1}'.format(ISSUES_PATH, number),
                                   headers=request_headers)
    else:
        issue = proxy_request('get',
                              '/{0}'.format(number),
                              headers=request_headers)
    return (issue.content, issue.status_code, get_headers(issue))
Exemple #31
0
def get_repo_labels():
    '''XHR endpoint to get all possible labels in a repo. Cached for ten
    minutes.'''
    # Chop off /issues. Someone feel free to refactor the ISSUES_REPO_URI.
    labels_uri = app.config['ISSUES_REPO_URI'][:-7]
    if g.user:
        labels = github.raw_request('GET', 'repos/{0}/labels'.format(labels_uri))
        response = make_response(json.dumps(labels.json()))
        response.headers['etag'] = labels.headers.get('etag')
        response.headers['cache-control'] = labels.headers.get('cache-control')
        response.headers['content-type'] = JSON_MIME
        return response
    else:
        # only authed users should be hitting this endpoint
        abort(401)
Exemple #32
0
def get_untriaged():
    '''Return all issues that are "untriaged".

    Essentially all unclosed issues with no activity.
    Cached for 5 minutes.
    '''
    if g.user:
        issues = github.raw_request('GET', 'repos/{0}'.format(REPO_URI))
    else:
        issues = proxy_request('get')
    # Do not send random JSON to filter_untriaged
    if issues.status_code == 200:
        return (filter_untriaged(json.loads(issues.content)),
                issues.status_code, get_headers(issues))
    else:
        return ({}, issues.status_code, get_headers(issues))
Exemple #33
0
def get_untriaged():
    '''Return all issues that are "untriaged".

    Essentially all unclosed issues with no activity.
    Cached for 5 minutes.
    '''
    if g.user:
        issues = github.raw_request('GET', 'repos/{0}'.format(REPO_URI))
    else:
        issues = proxy_request('get')
    # Do not send random JSON to filter_untriaged
    if issues.status_code == 200:
        return (filter_untriaged(json.loads(issues.content)),
                issues.status_code, get_headers(issues))
    else:
        return ({}, issues.status_code, get_headers(issues))
Exemple #34
0
def proxy_issue(number):
    '''XHR endpoint to get issue data from GitHub.

    either as an authed user, or as one of our proxy bots.
    '''
    request_headers = get_request_headers(g.request_headers)
    if g.user:
        issue = github.raw_request('GET', 'repos/{0}/{1}'.format(
            ISSUES_PATH, number), headers=request_headers)
    else:
        issue = proxy_request('get', '/{0}'.format(number),
                              headers=request_headers)
    if issue.status_code != 404:
        return (issue.content, issue.status_code, get_headers(issue))
    else:
        # We may want in the future handle 500 type of errors.
        # This will return the JSON version of 404
        abort(404)
Exemple #35
0
def proxy_issues():
    """API endpoint to list all issues from GitHub."""
    params = request.args.copy()

    # If there's a q param, then we need to use the Search API
    # and load those results. For logged in users, we handle this at the
    # server level.
    if g.user and params.get("q"):
        return get_search_results(params.get("q"), params)
    # Non-authed users should never get here--the request is made to
    # GitHub client-side)--but return out of paranoia anyways.
    elif params.get("q"):
        abort(404)

    if g.user:
        issues = github.raw_request("GET", "repos/{0}".format(ISSUES_PATH), params=params)
    else:
        issues = proxy_request("get", params=params)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #36
0
def proxy_issues():
    '''API endpoint to list all issues from GitHub.'''
    params = request.args.copy()

    # If there's a q param, then we need to use the Search API
    # and load those results. For logged in users, we handle this at the
    # server level.
    if g.user and params.get('q'):
        return get_search_results(params.get('q'), params)
    # Non-authed users should never get here--the request is made to
    # GitHub client-side)--but return out of paranoia anyways.
    elif params.get('q'):
        abort(404)

    if g.user:
        issues = github.raw_request('GET',
                                    'repos/{0}'.format(ISSUES_PATH),
                                    params=params)
    else:
        issues = proxy_request('get', params=params)
    return (issues.content, issues.status_code, get_headers(issues))
Exemple #37
0
def get_search_results(query_string=None, params=None):
    '''XHR endpoint to get results from GitHub's Search API.

    We're specifically searching "issues" here, which seems to make the most
    sense. Note that the rate limit is different for Search: 30 requests per
    minute.

    If a user hits the rate limit, the Flask Limiter extension will send a
    429. See @app.error_handler(429) in views.py.

    This method can take a query_string argument, to be called from other
    endpoints, or the query_string can be passed in via the Request object.

    Not cached.
    '''
    params = params or request.args.copy()
    query_string = query_string or params.get('q')
    search_uri = 'https://api.github.com/search/issues'

    # restrict results to our repo.
    query_string += " repo:{0}".format(REPO_PATH)
    params['q'] = query_string

    # convert issues api to search api params here.
    params = normalize_api_params(params)
    request_headers = get_request_headers(g.request_headers)

    if g.user:
        results = github.raw_request('GET',
                                     'search/issues',
                                     params=params,
                                     headers=request_headers)
    else:
        results = proxy_request('get',
                                params=params,
                                uri=search_uri,
                                headers=request_headers)
    return (results.content, results.status_code, get_headers(results))