def query_gerrit(name, count, project, quiet=False):
    """Query gerrit and fetch the comments."""
    # Include review messages in query
    search = "reviewer:\"%s\"" % name
    if project:
        search = search + (" AND project:\"%s\"" % project)
    query = ("https://review.openstack.org/changes/?q=%s&"
             "o=MESSAGES&o=DETAILED_ACCOUNTS" % search)
    r = requests.get(query)
    try:
        changes = json.loads(r.text[4:])
    except ValueError:
        if not quiet:
            print("query: '%s' failed with:\n%s" % (query, r.text))
        return []

    comments = []
    for change in changes:
        for date, message in comment.get_comments(change, name):
            if date is None:
                # no comments from reviewer yet. This can happen since
                # 'Uploaded patch set X.' is considered a comment.
                continue
            comments.append(
                comment.Comment(date, change['_number'], change['subject'],
                                message))
    return sorted(comments, key=lambda comment: comment.date,
                  reverse=True)[0:count]
Beispiel #2
0
    def get(self):
        """Handle user request

        The edit item HTML page would list all items in category
        """
        category_name = self.request.get('category_name')
        item_name = self.request.get('item_name')
        if not item_name:
            self.redirect('/{path}?'.format(path=add_edit_delete_page_path) +
                          urllib.urlencode({'category_name': category_name, 'method': 'Edit', 'select_item': 'Nothing'}))
            return

        user = users.get_current_user()
        url = users.create_logout_url(self.request.uri)
        comments = comment.get_comments(category_key='{author}/{category}'.format(author=user, category=category_name), item_name=item_name)
        invalid_name = self.request.get('invalid_name')

        template_values = {
            'category_name': category_name,
            'item_name': item_name,
            'comments': comments,
            'url': url,
            'user': user,
            'invalid_name': invalid_name,
        }
        template =jinja_environment.get_template('{path}.html'.format(path=edit_page_path))
        self.response.out.write(template.render(template_values))
def query_gerrit(name, count, project, quiet=False):
    """Query gerrit and fetch the comments."""
    # Include review messages in query
    search = "reviewer:\"%s\"" % name
    if project:
        search = search + (" AND project:\"%s\"" % project)
    query = ("https://review.openstack.org/changes/?q=%s&"
             "o=MESSAGES&o=DETAILED_ACCOUNTS" % search)
    r = requests.get(query)
    try:
        changes = json.loads(r.text[4:])
    except ValueError:
        if not quiet:
            print("query: '%s' failed with:\n%s" % (query, r.text))
        return []

    comments = []
    for change in changes:
        for date, message in comment.get_comments(change, name):
            if date is None:
                # no comments from reviewer yet. This can happen since
                # 'Uploaded patch set X.' is considered a comment.
                continue
            comments.append(comment.Comment(date, change['_number'],
                                            change['subject'], message))
    return sorted(comments, key=lambda comment: comment.date,
                  reverse=True)[0:count]
Beispiel #4
0
def reserve_all_items(author, new_category_name, old_category_name):
    """Reserve all items as well as comments belonging to when its
       ancestor category name changed

    When update the category name, all items belonging to as well as its
    all comments would be reserved automatically
    :param author the specified author
    :param new_category_name the specified new category name
    :param old_category_name the specified old category name
    """
    old_items = get_items(author=author, category_name=old_category_name)

    for old_item in old_items:
        new_item = rankdata.Item(key_name='{author}/{category}/{item}'.format(author=author, category=new_category_name, item=old_item.name),
                                 parent=get_ancestor_key(author=author, category_name=new_category_name),
                                 name=old_item.name, create_time=old_item.create_time,
                                 number_of_win=old_item.number_of_win, number_of_lose=old_item.number_of_lose,
                                 percentage=old_item.percentage)
        new_item.put()

        old_comments = comment.get_comments(category_key='{author}/{category}'.format(author=author, category=old_category_name), item_name=old_item.name)
        for old_comment in old_comments:
            new_comment = rankdata.Comment(key_name='{author}/{category}/{item}/{commenter}'.format(author=author,
                                                                                                    category=new_category_name,
                                                                                                    item=old_item.name,
                                                                                                    commenter=old_comment.commenter),
                                           parent=comment.get_ancestor_key(category_key='{author}/{category}'.format(author=author, category=new_category_name),
                                                                           item_name=old_item.name),
                                           commenter=old_comment.commenter, content=old_comment.content, submit_time=old_comment.submit_time)
            db.delete(old_comment)
            new_comment.put()

        db.delete(old_item)
Beispiel #5
0
def get_comments(post_id):

    comments = comment.get_comments(post_id)

    return jsonify(comments)