Exemple #1
0
def save_issue_info(session, issue_dict, label_list):
    '''
        Save a dictionary of issue ingo to the datastore session.
        Return an app.Issue instance
    '''

    # Turn label lists into actual Label models
    labels = []
    for label_dict in label_list:
        new_label = Label(**label_dict)
        labels.append(new_label)
        session.add(new_label)

    # Select the current issue, filtering on title AND project_name.
    filter = Issue.title == issue_dict[
        'title'], Issue.project_id == issue_dict['project_id']
    existing_issue = session.query(Issue).filter(*filter).first()

    # If this is a new issue, save and return it.
    if not existing_issue:
        new_issue = Issue(**issue_dict)
        new_issue.labels = labels
        session.add(new_issue)
        return new_issue

    # Mark the existing issue for safekeeping.
    existing_issue.keep = True

    # Update existing issue details
    for (field, value) in issue_dict.items():
        setattr(existing_issue, field, value)
    existing_issue.labels = labels

    # Flush existing object, to prevent a sqlalchemy.orm.exc.StaleDataError.
    session.flush()

    return existing_issue
Exemple #2
0
def save_issue_info(session, issue_dict, label_list):
    '''
        Save a dictionary of issue ingo to the datastore session.
        Return an app.Issue instance
    '''

    # Turn label lists into actual Label models
    labels = []
    for label_dict in label_list:
        new_label = Label(**label_dict)
        labels.append(new_label)
        session.add(new_label)

    # Select the current issue, filtering on title AND project_name.
    filter = Issue.title == issue_dict['title'], Issue.project_id == issue_dict['project_id']
    existing_issue = session.query(Issue).filter(*filter).first()

    # If this is a new issue, save and return it.
    if not existing_issue:
        new_issue = Issue(**issue_dict)
        new_issue.labels = labels
        session.add(new_issue)
        return new_issue

    # Mark the existing issue for safekeeping.
    existing_issue.keep = True

    # Update existing issue details
    for (field, value) in issue_dict.items():
        setattr(existing_issue, field, value)
    existing_issue.labels = labels

    # Flush existing object, to prevent a sqlalchemy.orm.exc.StaleDataError.
    session.flush()

    return existing_issue
Exemple #3
0
def save_issue(session, issue):
    '''
        Save a dictionary of issue info to the datastore session.
        Return an app.Issue instance
    '''
    # Select the current issue, filtering on title AND project_id.
    filter = Issue.title == issue['title'], Issue.project_id == issue['project_id']
    existing_issue = session.query(Issue).filter(*filter).first()

    # If this is a new issue save it
    if not existing_issue:
        new_issue = Issue(**issue)
        session.add(new_issue)
    else:
        # Preserve the existing issue.
        # :::here (issue/true)
        existing_issue.keep = True
        # Update existing issue details
        existing_issue.title = issue['title']
        existing_issue.body = issue['body']
        existing_issue.html_url = issue['html_url']
        existing_issue.project_id = issue['project_id']