def sync_issuetracker(self, parent_type, parent_id, child_type): """Send comments to IssueTracker issues for child objects. Args: parent_type: type of parent object parent_id: id of parent object child_type: type of child object Returns: flask.wrappers.Response - response with result of generation. """ errors = [] try: with benchmark("Update issue tracker object for Audit child"): handler = self.INTEGRATION_HANDLERS[child_type] if not hasattr(handler, "load_issuetracked_objects"): raise integrations_errors.Error( "Updating issues for {} in scope of {} is not supported." .format(parent_type, child_type)) for obj in handler.load_issuetracked_objects(parent_type, parent_id, is_synced=True): handler().add_disable_comment( obj, obj.issuetracker_issue.issue_id) except (TypeError, ValueError, AttributeError, integrations_errors.Error, ggrc_exceptions.ValidationError, exceptions.Forbidden) as error: logger.error("Issues sync failed with error: %s", str(error)) self.send_notification(parent_type, parent_id, failed=True) else: self.send_notification(parent_type, parent_id, errors=errors) return self.make_response(errors)
def sync_issuetracker(self, parent_type, parent_id, child_type): """Generate IssueTracker issues in bulk for child objects. Args: parent_type: type of parent object parent_id: id of parent object child_type: type of child object Returns: flask.wrappers.Response - response with result of generation. """ errors = [] try: issuetracked_info = [] with benchmark("Load issuetracked objects from database"): handler = self.INTEGRATION_HANDLERS[child_type] if not hasattr(handler, "load_issuetracked_objects"): raise integrations_errors.Error( "Creation issues for {} in scope of {} is not supported." .format(parent_type, child_type)) for obj in handler.load_issuetracked_objects( parent_type, parent_id): issuetracked_info.append(IssuetrackedObjInfo(obj)) created, errors = self.handle_issuetracker_sync(issuetracked_info) logger.info("Synchronized issues count: %s, failed count: %s", len(created), len(errors)) except: # pylint: disable=bare-except self.send_notification(parent_type, parent_id, failed=True) else: self.send_notification(parent_type, parent_id, errors=errors) return self.make_response(errors)
def _process_result(result, issue_json): """Process result of issuetracker synchronization.""" if result and not issue_json.get("issue_id"): issue_json["enabled"] = True issue_json["issue_id"] = result.get("issueId") issue_json[ "issue_url"] = integration_utils.build_issue_tracker_url( result.get("issueId")) elif not result and not issue_json.get("issue_id"): raise integrations_errors.Error("Unknown error")
def _get_issue_json(self, object_): """Get json data for issuetracker issue related to provided object.""" issue_json = None integration_handler = self.INTEGRATION_HANDLERS.get(object_.type) if hasattr(integration_handler, "prepare_issue_update_json"): issue_json = integration_handler.prepare_issue_update_json(object_) if not issue_json: raise integrations_errors.Error( "Can't create issuetracker issue json for {}".format(object_.type) ) return issue_json
def test_issue_tracker_error(self, issue_tracker_enabled, issue_id, issue_enabled): """Test that issue tracker does not change state in case receiving an error.""" del issue_enabled # Unused with mock.patch.object( sync_utils, 'update_issue' ) as update_issue_mock: error_data = integrations_errors.Error('data') update_issue_mock.side_effect = error_data issue = factories.IssueTrackerIssueFactory( enabled=issue_tracker_enabled, issue_id=issue_id ) src = { 'issue_tracker': { 'enabled': issue_tracker_enabled, 'issue_id': issue_id, 'issue_url': integration_utils.build_issue_tracker_url( issue_id ), 'component_id': '1111', 'issue_type': 'PROCESS', 'issue_priority': 'P2', 'issue_severity': 'S2', 'title': 'Title' } } assessment_integration._hook_assmt_issue_update( sender=None, obj=issue.issue_tracked_obj, src=src, initial_state=issue.issue_tracked_obj ) update_issue_mock.assert_called_once() issue_obj = models.IssuetrackerIssue.get_issue( "Assessment", issue.issue_tracked_obj.id ) self.assertEqual(issue_obj.enabled, issue_tracker_enabled)