Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
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))
Esempio n. 4
0
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of N types:
    * new
    * closed
    * contactready
    * needscontact
    * 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.add('labels', 'status-' + issue_category)
        # Turns out the GitHub API considers &labels=x&labels=y an OR query
        # &labels=x,y is an AND query. Join the labels with a comma
        params['labels'] = ','.join(params.getlist('labels'))
        return api_request('get', issues_path, params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        return api_request('get', issues_path, 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':
        issues = api_request('get', issues_path, params=params)
        # api_request returns a tuple of format:
        #       (content, status_code, response_headers)
        # So we make a dict here for improved readability
        content, status_code, response_headers = issues
        if status_code != 304:
            content = filter_new(json.loads(content))
        return (content, status_code, response_headers)
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
Esempio n. 5
0
 def test_issues_new(self):
     '''Test that the new filtering is correct.'''
     issues = [{
         u'labels': [{
             u'name': u'bug'
         }, {
             u'name': u'help wanted'
         }],
         u'title': u"fake bug 0",
         u'id': 0
     }, {
         u'labels': [],
         u'title': u"fake bug 1",
         u'id': 1
     }, {
         u'labels': [{
             u'name': u'status-contactready'
         }],
         u'title': u"fake bug 2",
         u'id': 2
     }, {
         u'labels': [{
             u'name': u'status-needsdiagnosis'
         }],
         u'title': u"fake bug 3",
         u'id': 3
     }, {
         u'labels': [{
             u'name': u'status-needscontact'
         }],
         u'title': u"fake bug 4",
         u'id': 4
     }, {
         u'labels': [{
             u'name': u'status-sitewait'
         }],
         u'title': u"fake bug 5",
         u'id': 5
     }]
     result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]'  # nopep8
     self.assertEqual(filter_new(issues), result)
Esempio n. 6
0
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of N types:
    * new
    * closed
    * contactready
    * needscontact
    * 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
        return api_request('get', issues_path, params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        return api_request('get', issues_path, 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':
        issues = api_request('get', issues_path, params=params)
        # api_request returns a tuple of format:
        #       (content, status_code, response_headers)
        # So we make a dict here for improved readability
        new_issues = {
            'content': filter_new(json.loads(issues[0])),
            'status_code': issues[1],
            'response_headers': issues[2]
        }
        return (new_issues['content'], new_issues['status_code'],
                new_issues['response_headers'])
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
Esempio n. 7
0
def get_issue_category(issue_category):
    '''Return all issues for a specific category.

    issue_category can be of N types:
    * new
    * closed
    * contactready
    * needscontact
    * 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.add('labels', 'status-' + issue_category)
        # Turns out the GitHub API considers &labels=x&labels=y an OR query
        # &labels=x,y is an AND query. Join the labels with a comma
        params['labels'] = ','.join(params.getlist('labels'))
        return api_request('get', issues_path, params=params)
    elif issue_category == 'closed':
        params['state'] = 'closed'
        return api_request('get', issues_path, 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':
        issues = api_request('get', issues_path, params=params)
        # api_request returns a tuple of format:
        #       (content, status_code, response_headers)
        # So we make a dict here for improved readability
        content, status_code, response_headers = issues
        if status_code != 304:
            content = filter_new(json.loads(content))
        return (content, status_code, response_headers)
    else:
        # The path doesn’t exist. 404 Not Found.
        abort(404)
Esempio n. 8
0
 def test_issues_new(self):
     '''Test that the new filtering is correct.'''
     issues = [
         {u'labels': [{u'name': u'bug'}, {u'name': u'help wanted'}],
          u'title': u"fake bug 0",
          u'id': 0},
         {u'labels': [],
          u'title': u"fake bug 1",
          u'id': 1},
         {u'labels': [{u'name': u'status-contactready'}],
          u'title': u"fake bug 2",
          u'id': 2},
         {u'labels': [{u'name': u'status-needsdiagnosis'}],
          u'title': u"fake bug 3",
          u'id': 3},
         {u'labels': [{u'name': u'status-needscontact'}],
          u'title': u"fake bug 4",
          u'id': 4},
         {u'labels': [{u'name': u'status-sitewait'}],
          u'title': u"fake bug 5",
          u'id': 5}]
     result = '[{"labels": [{"name": "bug"}, {"name": "help wanted"}], "id": 0, "title": "fake bug 0"}, {"labels": [], "id": 1, "title": "fake bug 1"}]'
     self.assertEqual(filter_new(issues), result)