def get(self): """The get handler method is called from a cron job. It expects no parameters and has no output. It checks all current bisect try jobs and send comments to an issue on the issue tracker if a bisect job has completed. """ credentials = utils.ServiceAccountCredentials() issue_tracker = issue_tracker_service.IssueTrackerService( additional_credentials=credentials) # Set privilege so we can also fetch internal try_job entities. datastore_hooks.SetPrivilegedRequest() jobs_to_check = try_job.TryJob.query( try_job.TryJob.status.IN(['started', 'pending'])).fetch() all_successful = True for job in jobs_to_check: try: _CheckJob(job, issue_tracker) except Exception as e: # pylint: disable=broad-except logging.error('Caught Exception %s: %s\n%s', type(e).__name__, e, traceback.format_exc()) all_successful = False if all_successful: utils.TickMonitoringCustomMetric('UpdateBugWithResults')
def _CommentOnRecoveredBug(cls, bug_id): """Adds a comment and close the bug on Issue tracker.""" bug = ndb.Key('Bug', bug_id).get() if bug.status != bug_data.BUG_STATUS_OPENED: return bug.status = bug_data.BUG_STATUS_RECOVERED bug.put() comment = cls._RecoveredBugComment(bug_id) issue_tracker = issue_tracker_service.IssueTrackerService( additional_credentials=utils.ServiceAccountCredentials()) issue_tracker.AddBugComment(bug_id, comment)
def _MakeSingleton(cls, override_credentials=None): """Instantiates the singleton.""" # Uses rietveld credentials to authorize an http client. Note this same # account is authorized for buildbucket. cls._singleton = httplib2.Http() if override_credentials: credentials = override_credentials else: credentials = utils.ServiceAccountCredentials() # If we cannot pull the credentials from ndb we simply use the unauthorized # client. This useful when running a local dev server. if credentials: credentials.authorize(cls._singleton)
def PerformBisect(bisect_job): """Starts the bisect job. This creates a patch, uploads it, then tells Rietveld to try the patch. TODO(qyearsley): If we want to use other tryservers sometimes in the future, then we need to have some way to decide which one to use. This could perhaps be passed as part of the bisect bot name, or guessed from the bisect bot name. Args: bisect_job: A TryJob entity. Returns: A dictionary containing the result; if successful, this dictionary contains the field "issue_id" and "issue_url", otherwise it contains "error". Raises: AssertionError: Bot or config not set as expected. request_handler.InvalidInputError: Some property of the bisect job is invalid. """ assert bisect_job.bot and bisect_job.config if not bisect_job.key: bisect_job.put() if bisect_job.use_buildbucket: result = _PerformBuildbucketBisect(bisect_job) else: result = _PerformLegacyBisect(bisect_job) if 'error' in result: bisect_job.run_count += 1 bisect_job.SetFailed() comment = 'Bisect job failed to kick off' elif result.get('issue_url'): comment = 'Started bisect job %s' % result['issue_url'] else: comment = 'Started bisect job: %s' % result if bisect_job.bug_id: issue_tracker = issue_tracker_service.IssueTrackerService( additional_credentials=utils.ServiceAccountCredentials()) issue_tracker.AddBugComment(bisect_job.bug_id, comment, send_email=False) return result
def _Http(self): if not self._http: self._http = httplib2.Http() credentials = utils.ServiceAccountCredentials() credentials.authorize(self._http) return self._http