Beispiel #1
0
 def postComment(self, issue_id, comment, send_email=True):
   request = self.client.issues().comments().insert(
       projectId=self.project_name,
       issueId=issue_id,
       sendEmail=send_email,
       body={'content': comment})
   endpoints.retry_request(request)
Beispiel #2
0
 def test_fails_requests_with_unsupported_retry_errors(self):
   request = mock.Mock()
   request.execute.side_effect = [
       HttpError(mock.Mock(status=400), 'err'),
       'response'
   ]
   with self.assertRaises(HttpError):
     endpoints.retry_request(request)
Beispiel #3
0
  def update(self, issue, comment=None, send_email=True):
    if not issue.dirty and not comment:
      return issue

    updates = {}
    if 'summary' in issue.changed:
      updates['summary'] = issue.summary
    if 'status' in issue.changed:
      updates['status'] = issue.status
      if issue.status == 'Duplicate':
        updates['mergedInto'] = issue.merged_into
    if 'owner' in issue.changed:
      updates['owner'] = issue.owner
    if 'blocked_on' in issue.changed:
      updates['blockedOn'] = issue.blocked_on
    if issue.labels.isChanged():
      updates['labels'] = list(issue.labels.added)
      updates['labels'].extend('-%s' % label for label in issue.labels.removed)
    if issue.components.isChanged():
      updates['components'] = list(issue.components.added)
      updates['components'].extend('-%s' % comp
                                   for comp in issue.components.removed)
    if issue.cc.isChanged():
      updates['cc'] = list(issue.cc.added)
      updates['cc'].extend('-%s' % cc for cc in issue.cc.removed)

    if issue.field_values.isChanged():
      updates['fieldValues'] = [value.to_dict() for
                                value in issue.field_values.added]
      removed = [value for value in issue.field_values.removed]
      for value in removed:  # Change the operator for removed elements.
        value.operator = CustomizedField.OPERATOR_REMOVE
      removed_json = [value.to_dict() for value in removed]
      updates['fieldValues'].extend(removed_json)

    body = {'id': issue.id, 'updates': updates}

    if comment:
      body['content'] = comment

    request = self.client.issues().comments().insert(
        projectId=self.project_name,
        issueId=issue.id,
        sendEmail=send_email,
        body=body)
    endpoints.retry_request(request)

    if issue.owner == '----':
      issue.owner = ''

    issue.setClean()
    return issue
Beispiel #4
0
  def getComments(self, issue_id):
    rtn = []

    request = self.client.issues().comments().list(
        projectId=self.project_name, issueId=issue_id)
    feed = endpoints.retry_request(request)
    rtn.extend([Comment(entry) for entry in feed['items']])
    total_results = int(feed['totalResults'])

    while len(rtn) < total_results:
      request = self.client.issues().comments().list(
          projectId=self.project_name, issueId=issue_id, startIndex=len(rtn))
      feed = endpoints.retry_request(request)
      rtn.extend([Comment(entry) for entry in feed['items']])

    return rtn
Beispiel #5
0
  def create(self, issue, send_email=True):
    body = {}
    assert issue.summary
    body['summary'] = issue.summary
    if issue.description:
      body['description'] = issue.description
    if issue.status:
      body['status'] = issue.status
    if issue.owner:
      body['owner'] = {'name': issue.owner}
    if issue.labels:
      body['labels'] = issue.labels
    if issue.components:
      body['components'] = issue.components
    if issue.cc:
      body['cc'] = [{'name': user} for user in issue.cc]
    if issue.field_values:
      body['fieldValues'] = [field.to_dict() for
                             field in issue.field_values]

    body['projectId'] = self.project_name
    request = self.client.issues().insert(
        projectId=self.project_name, sendEmail=send_email, body=body)
    tmp = endpoints.retry_request(request)
    issue.id = tmp['id']
    issue.setClean()
    return issue
Beispiel #6
0
 def getIssue(self, issue_id, project_id=None):
   """Retrieve an issue in a project."""
   if project_id is None:
     project_id = self.project_name
   request = self.client.issues().get(projectId=project_id, issueId=issue_id)
   entry = endpoints.retry_request(request)
   return Issue(entry)
Beispiel #7
0
    def triggerFlakeSwarmingTask(self,
                                 master_name,
                                 builder_name,
                                 build_number,
                                 step_name,
                                 test_name,
                                 total_reruns=100):
        """Trigger a flake swarming rerun task with Findit

    Sends a request to Findit to schedule a test to be rerun. The response is
    is a dictionary. If the task has been scheduled and is waiting to run, the
    response contains 'queued' set to true. If the task is running, the response
    contains 'running' set to true. If the task has been completed, it contains
    other information: 'task_id' - the swarming task id of the triggered task,
    'completed', 'timeout_seconds', 'triggering_source' - what caused the rerun
    to be triggered, 'total_reruns', and 'fail_count' and 'pass_count' - number
    of times the test has failed and passed respectivly.
    """
        body = {}
        body['master_name'] = master_name
        body['builder_name'] = builder_name
        body['build_number'] = build_number
        body['step_name'] = step_name
        body['test_name'] = test_name
        body['total_reruns'] = total_reruns
        return endpoints.retry_request(
            self.client.flakeswarmingtask(body=body))
Beispiel #8
0
 def getCommentCount(self, issue_id):
   request = self.client.issues().comments().list(
       projectId=self.project_name,
       issueId=issue_id,
       startIndex=1,
       maxResults=0)
   feed = endpoints.retry_request(request)
   return feed.get('totalResults', '0')
Beispiel #9
0
 def test_retries_supported_errors_on_requests_with_exponential_delay(self):
   request = mock.Mock()
   request.execute.side_effect = [
     HttpError(mock.Mock(status=500), 'error'),
     HttpError(mock.Mock(status=503), 'error'),
     HttpError(mock.Mock(status=403), 'error'),
     'response'
   ]
   self.assertEquals(endpoints.retry_request(request), 'response')
   self.sleep.assert_has_calls([mock.call(1), mock.call(2), mock.call(4)])
Beispiel #10
0
    def flake(self, name, is_step, issue_id, build_steps):
        """Analyze a flake on Commit Queue

    Sends a request to Findit to analyze a flake on commit queue. The flake
    can analyze a step or a test.

    Args:
      name: string name of the test or step to be analyzed
      is_step: if analyzing a step, this is set to True. Set to False otherwise.
      bug_id: the integer bug id associated with this test if any
      build_steps: A list of dictionaries where each dictionay contains
        the 'master_name', 'builder_name', 'build_number', and 'step_name' fields
        for each individual test run to analyze.
    """
        body = {}
        body['name'] = name
        body['is_step'] = is_step
        body['bug_id'] = issue_id
        body['build_steps'] = build_steps
        endpoints.retry_request(self.client.flake(body=body))
Beispiel #11
0
  def update(self, issue, comment=None, send_email=True):
    if not issue.dirty and not comment:
      return issue

    updates = {}
    if 'summary' in issue.changed:
      updates['summary'] = issue.summary
    if 'status' in issue.changed:
      updates['status'] = issue.status
    if 'owner' in issue.changed:
      updates['owner'] = issue.owner
    if 'blocked_on' in issue.changed:
      updates['blockedOn'] = issue.blocked_on
    if issue.labels.isChanged():
      updates['labels'] = list(issue.labels.added)
      updates['labels'].extend('-%s' % label for label in issue.labels.removed)
    if issue.components.isChanged():
      updates['components'] = list(issue.components.added)
      updates['components'].extend(
          '-%s' % comp for comp in issue.components.removed)
    if issue.cc.isChanged():
      updates['cc'] = list(issue.cc.added)
      updates['cc'].extend('-%s' % cc for cc in issue.cc.removed)

    body = {'id': issue.id,
            'updates': updates}

    if comment:
      body['content'] = comment

    request = self.client.issues().comments().insert(
        projectId=self.project_name, issueId=issue.id, sendEmail=send_email,
        body=body)
    endpoints.retry_request(request)

    if issue.owner == '----':
      issue.owner = ''

    issue.setClean()
    return issue
Beispiel #12
0
 def flake(self, flake, flaky_runs):
     body = {}
     body['name'] = flake.name
     body['is_step'] = flake.is_step
     body['bug_id'] = flake.issue_id
     body['build_steps'] = []
     for flaky_run in flaky_runs:
         failure_run = flaky_run.failure_run.get()
         patchset_build_run = flaky_run.failure_run.parent().get()
         for occurrence in flaky_run.flakes:
             if occurrence.failure == flake.name:
                 body['build_steps'].append({
                     'master_name':
                     patchset_build_run.master,
                     'builder_name':
                     patchset_build_run.builder,
                     'build_number':
                     failure_run.buildnumber,
                     'step_name':
                     occurrence.name
                 })
     endpoints.retry_request(self.client.flake(body=body))
Beispiel #13
0
  def getIssues(self, query, project_id=None):
    """List issues of the given project id that match the provided query.

    Args:
      project_id (str): The project id that the issues belong to.
      query (str): Custom query for the issues that you want. Refer to monorail
          to construct your query. This will be the same string that you use
          in the search bar.
    Returns:
      ([Issue]) Issues matching the given query.
    """
    if project_id is None:
      project_id = self.project_name
    request = self.client.issues().list(projectId=project_id, q=query)
    feed = endpoints.retry_request(request)
    return [Issue(entry) for entry in feed.get('items', [])]
Beispiel #14
0
    def checkFlakeSwarmingTask(self,
                               master_name,
                               builder_name,
                               build_number,
                               step_name,
                               test_name,
                               total_reruns=100):
        """Check the status of a flake swarming rerun task

    Sends a request to Findit to retrieve the data of a scheduled task, whether
    it was scheduled externally via the API or through Findit. This will not
    trigger a new task but will return the data of the task if avaliable or report
    that the task is queued, running, failed, or supported, where supported indicates
    that the task has not been scheduled but it can be.
    """
        body = {}
        body['master_name'] = master_name
        body['builder_name'] = builder_name
        body['build_number'] = build_number
        body['step_name'] = step_name
        body['test_name'] = test_name
        body['total_reruns'] = total_reruns
        return endpoints.retry_request(
            self.client.flakeswarmingtaskdata(body=body))
Beispiel #15
0
 def getIssue(self, issue_id):
   """Retrieve a set of issues in a project."""
   request = self.client.issues().get(
       projectId=self.project_name, issueId=issue_id)
   entry = endpoints.retry_request(request)
   return Issue(entry)
Beispiel #16
0
 def test_fails_requests_with_too_many_retries(self):
   request = mock.Mock()
   request.execute.side_effect = [HttpError(mock.Mock(status=500), 'err')] * 3
   with self.assertRaises(HttpError):
     endpoints.retry_request(request, num_tries=3)