Exemplo n.º 1
0
def _UpdateFlakeIssueWithMonorailIssue(flake_issue, monorail_issue):
    """Updates a FlakeIssue with its corresponding Monorail issue."""
    issue_id = flake_issue.issue_id
    monorail_project = flake_issue.monorail_project
    issue_link = FlakeIssue.GetLinkForIssue(monorail_project, issue_id)

    if not monorail_issue:
        # Possible reason: Findit doesn't have access to the monorail issue.
        return

    assert monorail_issue.status is not None, (
        'Failed to get issue.status from {}'.format(issue_link))
    assert monorail_issue.updated or monorail_issue.closed, (
        'Failed to get updated time from {}'.format(issue_link))

    if monorail_issue.status == 'Duplicate':
        # Impacted |merge_destination_key|s need to be updated.
        merged_monorail_issue = monorail_util.GetMergedDestinationIssueForId(
            issue_id, monorail_project)
        if not merged_monorail_issue.id:
            logging.warning('Failed to get merged monorail issue %s',
                            issue_link)

        _UpdateMergeDestinationAndIssueLeaves(flake_issue,
                                              merged_monorail_issue)

    flake_issue.Update(
        status=monorail_issue.status,
        labels=monorail_issue.labels,
        last_updated_time_in_monorail=(monorail_issue.closed
                                       or monorail_issue.updated),
        create_time_in_monorail=monorail_issue.created)
Exemplo n.º 2
0
    def testGetMergedDestinationIssueWithMergeInCircle(self, mock_api):
        issue = Issue({'id': 12345, 'mergedInto': {'issueId': 56789}})

        another_issue = Issue({'id': 56789, 'mergedInto': {'issueId': 12345}})

        def _return_issue(issue_id):
            if issue_id == 12345:
                return issue

            if issue_id == 56789:
                return another_issue

            return None

        mock_api.return_value.getIssue.side_effect = _return_issue
        self.assertEqual(issue,
                         monorail_util.GetMergedDestinationIssueForId(12345))
Exemplo n.º 3
0
def GetAndUpdateMergedIssue(flake_issue):
    """Gets the most up-to-date merged issue and update data in data store.

  Args:
    flake_issue (FlakeIssue): FlakeIssue to check its merge destination and
       update.

  Returns:
    merged_issue (monorail_api.Issue): Merge destination of the flake_issue.
  """
    monorail_project = flake_issue.monorail_project
    merged_issue = monorail_util.GetMergedDestinationIssueForId(
        flake_issue.issue_id, monorail_project)
    if merged_issue and flake_issue.issue_id != merged_issue.id:
        logging.info(
            'Flake issue %s was merged to %s, updates this issue and'
            ' all issues were merged into it.',
            FlakeIssue.GetLinkForIssue(monorail_project, flake_issue.issue_id),
            FlakeIssue.GetLinkForIssue(monorail_project, merged_issue.id))
        _UpdateMergeDestinationAndIssueLeaves(flake_issue, merged_issue)

    return merged_issue
Exemplo n.º 4
0
 def testGetMergedDestinationIssueWithoutMergeInto(self, mock_api):
     issue = Issue({'id': 12345})
     mock_api.return_value.getIssue.return_value = issue
     self.assertEqual(issue,
                      monorail_util.GetMergedDestinationIssueForId(12345))