Exemplo n.º 1
0
def _compare_custom_fields(custom_fields_payload, custom_fields_issuetracker):
    """Validate custom fields on payload and from third party server.

  Args:
    - custom_fields_payload: custom_fields on Issue Tracker Payload
    - custom_fields_issuetracker: custom_fields from Issue Tracker

  Returns:
    tuple with bool objects (due_dates_equals, remove_custom_fields)

    due_dates_equals: bool object with validate or not indicator (True/False)

    remove_custom_fields: bool object that indicate to remove "custom_fields"
    from payload
  """
    if any(custom_fields_payload):
        due_date_payload = _extract_date(
            custom_fields_payload[0]["value"].strip())
    else:
        due_date_payload = None

    if any(custom_fields_issuetracker):
        due_date_raw = sync_utils.parse_due_date(custom_fields_issuetracker)
        if due_date_raw is None:
            # due date is empty after processing,
            # in that case we shouldn't synchronize custom fields
            return True, True
        else:
            due_date_issuetracker = _extract_date(due_date_raw)
    else:
        # custom fields is empty from issue tracker,
        # in that case we shouldn't synchronize custom fields
        return True, True

    return due_date_payload == due_date_issuetracker, False
Exemplo n.º 2
0
def sync_issue_attributes():
  """Synchronizes issue tracker ticket attrs with the Issue object attrs.

  Synchronize issue status and email list (Primary contacts and Admins).
  """
  issuetracker_issues = sync_utils.collect_issue_tracker_info(
      "Issue",
      include_object=True
  )

  if not issuetracker_issues:
    return

  assignees_role = all_models.AccessControlRole.query.filter_by(
      object_type=all_models.Issue.__name__, name="Primary Contacts"
  ).first()

  admin_role = all_models.AccessControlRole.query.filter_by(
      object_type=all_models.Issue.__name__, name="Admin"
  ).first()

  processed_ids = set()
  for batch in sync_utils.iter_issue_batches(issuetracker_issues.keys(),
                                             include_emails=True):
    for issue_id, issuetracker_state in batch.iteritems():
      issue_id = str(issue_id)
      issue_info = issuetracker_issues.get(issue_id)
      if not issue_info:
        logger.warning(
            "Got an unexpected issue from Issue Tracker: %s", issue_id)
        continue

      processed_ids.add(issue_id)
      sync_object = issue_info["object"]

      # Sync attributes.
      sync_statuses(issuetracker_state, sync_object)
      sync_assignee_email(issuetracker_state, sync_object, assignees_role)
      sync_verifier_email(issuetracker_state, sync_object, admin_role)

      custom_fields = {
          constants.CUSTOM_FIELDS_DUE_DATE: sync_utils.parse_due_date(
              issuetracker_state.get("custom_fields", [])
          )
      }
      sync_due_date(custom_fields, sync_object)

  db.session.commit()
  logger.debug("Sync is done, %d issue(s) were processed.", len(processed_ids))

  missing_ids = set(issuetracker_issues) - processed_ids
  if missing_ids:
    logger.warning(
        "Some issues are linked to Issue "
        "but were not found in Issue Tracker: %s",
        ", ".join(str(i) for i in missing_ids)
    )
Exemplo n.º 3
0
def sync_issue_attributes():
  """Synchronizes issue tracker ticket attrs with the Issue object attrs.

  Synchronize issue status and email list (Primary contacts and Admins).
  """
  issuetracker_issues = sync_utils.collect_issue_tracker_info(
      "Issue"
  )

  if not issuetracker_issues:
    return

  assignees_role = all_models.AccessControlRole.query.filter_by(
      object_type=all_models.Issue.__name__, name="Primary Contacts"
  ).first()

  admin_role = all_models.AccessControlRole.query.filter_by(
      object_type=all_models.Issue.__name__, name="Admin"
  ).first()

  processed_ids = set()
  for batch in sync_utils.iter_issue_batches(issuetracker_issues.keys()):
    for issue_id, issuetracker_state in batch.iteritems():
      issue_id = str(issue_id)
      issue_info = issuetracker_issues.get(issue_id)
      if not issue_info:
        logger.warning(
            "Got an unexpected issue from Issue Tracker: %s", issue_id)
        continue

      processed_ids.add(issue_id)
      sync_object = issue_info["object"]

      # Sync attributes.
      sync_statuses(issuetracker_state, sync_object)
      sync_assignee_email(issuetracker_state, sync_object, assignees_role)
      sync_verifier_email(issuetracker_state, sync_object, admin_role)

      custom_fields = {
          constants.CustomFields.DUE_DATE: sync_utils.parse_due_date(
              issuetracker_state.get("custom_fields", [])
          )
      }
      sync_due_date(custom_fields, sync_object)

  db.session.commit()
  logger.debug("Sync is done, %d issue(s) were processed.", len(processed_ids))

  missing_ids = set(issuetracker_issues) - processed_ids
  if missing_ids:
    logger.warning(
        "Some issues are linked to Issue "
        "but were not found in Issue Tracker: %s",
        ", ".join(str(i) for i in missing_ids)
    )
Exemplo n.º 4
0
def _compare_custom_fields(custom_fields_payload, custom_fields_issuetracker):
  """Validate custom fields on payload and from third party server.

  Args:
    - custom_fields_payload: custom_fields on Issue Tracker Payload
    - custom_fields_issuetracker: custom_fields from Issue Tracker

  Returns:
    tuple with bool objects (due_dates_equals, remove_custom_fields)

    due_dates_equals: bool object with validate or not indicator (True/False)

    remove_custom_fields: bool object that indicate to remove "custom_fields"
    from payload
  """
  if any(custom_fields_payload):
    due_date_payload = _extract_date(
        custom_fields_payload[0]["value"].strip()
    )
  else:
    due_date_payload = None

  if any(custom_fields_issuetracker):
    due_date_raw = sync_utils.parse_due_date(
        custom_fields_issuetracker
    )
    if due_date_raw is None:
      # due date is empty after processing,
      # in that case we shouldn't synchronize custom fields
      return True, True
    else:
      due_date_issuetracker = _extract_date(due_date_raw)
  else:
    # custom fields is empty from issue tracker,
    # in that case we shouldn't synchronize custom fields
    return True, True

  return due_date_payload == due_date_issuetracker, False