Пример #1
0
def _detach_assessment(new_ticket_id, old_ticket_id):
    """Send to old IssueTracker ticket detachment comment."""
    builder = issue_tracker_params_builder.AssessmentParamsBuilder()
    params = builder.build_detach_comment(new_ticket_id)
    query = params.get_issue_tracker_params()
    try:
        issues.Client().update_issue(old_ticket_id, query)
    except integrations_errors.Error as error:
        logger.error("Unable to add detach comment to ticket issue ID=%d: %s",
                     old_ticket_id, error)
Пример #2
0
def prepare_issue_update_json(assmt, issue_tracker_info=None):
    """Prepare issuetracker issue json for Assessment object update."""
    if not issue_tracker_info:
        issue_tracker_info = assmt.issue_tracker

    integration_utils.set_values_for_missed_fields(assmt, issue_tracker_info)
    builder = issue_tracker_params_builder.AssessmentParamsBuilder()
    builder.handle_issue_tracker_info(assmt, issue_tracker_info)
    issue_tracker_params = builder.params
    params = issue_tracker_params.get_issue_tracker_params()
    return params
Пример #3
0
def _update_issuetracker_issue(
        assessment,
        issue_tracker_info,  # noqa
        initial_assessment,
        initial_info,
        request):
    """Collects information and sends a request to update external issue."""
    # pylint: disable=too-many-locals
    issue_id = issue_tracker_info.get('issue_id')
    if not issue_id:
        return

    comments = []

    # Handle switching of 'enabled' property.
    enabled = issue_tracker_info.get('enabled', False)
    if initial_info.get('enabled', False) != enabled:
        # Add comment about toggling feature and process further.
        comments.append(_ENABLED_TMPL if enabled else _DISABLED_TMPL)
    elif not enabled:
        # If feature remains in the same status which is 'disabled'.
        return

    integration_utils.normalize_issue_tracker_info(issue_tracker_info)

    issue_params = _handle_basic_props(issue_tracker_info, initial_info)

    # Handle status update.
    status_value, status_comment = _build_status_comment(
        assessment, initial_assessment)
    if status_value:
        issue_params['status'] = status_value
        comments.append(status_comment)

    # Attach user comments if any.
    comment_text, comment_author = _get_added_comment_text(request)
    if comment_text is not None:
        builder = issue_tracker_params_builder.AssessmentParamsBuilder()
        comments.append(
            builder.COMMENT_TMPL.format(author=comment_author,
                                        comment=comment_text,
                                        model=_ASSESSMENT_MODEL_NAME,
                                        link=_get_assessment_url(assessment)))

    if comments:
        issue_params['comment'] = '\n\n'.join(comments)

    # Handle hotlist ID update.
    hotlist_id = issue_tracker_info.get('hotlist_id')
    if hotlist_id is not None and hotlist_id != initial_info.get('hotlist_id'):
        issue_params['hotlist_ids'] = [hotlist_id] if hotlist_id else []

    # handle assignee and cc_list update
    assignee_email, cc_list = _collect_assessment_emails(assessment)
    del cc_list

    if assignee_email is not None:
        issue_tracker_info['assignee'] = assignee_email
        issue_params['assignee'] = assignee_email
        issue_params['verifier'] = assignee_email

    custom_fields = []

    # handle due_date update
    due_date = issue_tracker_info.get('due_date')
    if due_date:
        custom_fields.append({
            "name": constants.CUSTOM_FIELDS_DUE_DATE,
            "value": due_date.strftime("%Y-%m-%d"),
            "type": "DATE",
            "display_string": constants.CUSTOM_FIELDS_DUE_DATE
        })

    if custom_fields:
        issue_params['custom_fields'] = custom_fields

    if issue_params:
        # Resend all properties upon any change.
        issue_params = _fill_current_value(issue_params, assessment,
                                           initial_info)
        issues.Client().update_issue(issue_id, issue_params)
Пример #4
0
def prepare_comment_update_json(object_, comment, author):
    """Prepare json for adding comment to IssueTracker issue"""
    builder = issue_tracker_params_builder.AssessmentParamsBuilder()
    params = builder.build_params_for_comment(object_, comment, author)
    return params.get_issue_tracker_params()