def update(self, fields=None, async_=None, jira=None, notify=True, **kwargs): """Update this resource on the server. Keyword arguments are marshalled into a dict before being sent. If this resource doesn't support ``PUT``, a :py:exc:`.JIRAError` will be raised; subclasses that specialize this method will only raise errors in case of user error. :param fields: Fields which should be updated for the object. :type fields: Optional[Dict[str, Any]] :param async_: If true the request will be added to the queue so it can be executed later using async_run() :type async_: bool :param jira: Instance of JIRA Client :type jira: jira.JIRA :param notify: Whether or not to notify users about the update. (Default: True) :type notify: bool :type kwargs: **Any """ if async_ is None: async_ = self._options['async'] data = {} if fields is not None: data.update(fields) data.update(kwargs) data = json.dumps(data) if not notify: querystring = "?notifyUsers=false" else: querystring = "" r = self._session.put(self.self + querystring, data=data) if 'autofix' in self._options and \ r.status_code == 400: user = None error_list = get_error_list(r) logging.error(error_list) if "The reporter specified is not a user." in error_list: if 'reporter' not in data['fields']: logging.warning( "autofix: setting reporter to '%s' and retrying the update." % self._options['autofix']) data['fields']['reporter'] = { 'name': self._options['autofix'] } if "Issues must be assigned." in error_list: if 'assignee' not in data['fields']: logging.warning( "autofix: setting assignee to '%s' for %s and retrying the update." % (self._options['autofix'], self.key)) data['fields']['assignee'] = { 'name': self._options['autofix'] } # for some reason the above approach fails on Jira 5.2.11 # so we need to change the assignee before if "Issue type is a sub-task but parent issue key or id not specified." in error_list: logging.warning( "autofix: trying to fix sub-task without parent by converting to it to bug" ) data['fields']['issuetype'] = {"name": "Bug"} if "The summary is invalid because it contains newline characters." in error_list: logging.warning("autofix: trying to fix newline in summary") data['fields']['summary'] = self.fields.summary.replace( "/n", "") for error in error_list: if re.search(r"^User '(.*)' was not found in the system\.", error, re.U): m = re.search( r"^User '(.*)' was not found in the system\.", error, re.U) if m: user = m.groups()[0] else: raise NotImplementedError() if re.search(r"^User '(.*)' does not exist\.", error): m = re.search(r"^User '(.*)' does not exist\.", error) if m: user = m.groups()[0] else: raise NotImplementedError() if user: logging.warning( "Trying to add missing orphan user '%s' in order to complete the previous failed operation." % user) jira.add_user(user, '*****@*****.**', 10100, active=False) # if 'assignee' not in data['fields']: # logging.warning("autofix: setting assignee to '%s' and retrying the update." % self._options['autofix']) # data['fields']['assignee'] = {'name': self._options['autofix']} # EXPERIMENTAL ---> if async_: if not hasattr(self._session, '_async_jobs'): self._session._async_jobs = set() self._session._async_jobs.add( threaded_requests.put(self.self, data=json.dumps(data))) else: r = self._session.put(self.self, data=json.dumps(data)) time.sleep(self._options['delay_reload']) self._load(self.self)
else: raise NotImplemented() if user: logging.warning( "Trying to add missing orphan user '%s' in order to complete the previous failed operation." % user) jira.add_user(user, '*****@*****.**', 10100, active=False) # if 'assignee' not in data['fields']: # logging.warning("autofix: setting assignee to '%s' and retrying the update." % self._options['autofix']) # data['fields']['assignee'] = {'name': self._options['autofix']} # EXPERIMENTAL ---> # import grequests if async: if not hasattr(self._session, '_async_jobs'): self._session._async_jobs = set() self._session._async_jobs.add(threaded_requests.put( self.self, data=json.dumps(data))) else: r = self._session.put( self.self, data=json.dumps(data)) # TODO(ssbarnea): compare loaded data in order to verify if resource was updated indeed # we had random test failures (probably) due to caching time.sleep(4) self._load(self.self) def delete(self, params=None): """Delete this resource from the server, passing the specified query parameters. If this resource doesn't support ``DELETE``, a :py:exc:`.JIRAError` will be raised; subclasses that specialize this method will only raise errors in case of user error.
if user: logging.warning( "Trying to add missing orphan user '%s' in order to complete the previous failed operation." % user) jira.add_user(user, '*****@*****.**', 10100, active=False) # if 'assignee' not in data['fields']: # logging.warning("autofix: setting assignee to '%s' and retrying the update." % self._options['autofix']) # data['fields']['assignee'] = {'name': self._options['autofix']} # EXPERIMENTAL ---> # import grequests if async: if not hasattr(self._session, '_async_jobs'): self._session._async_jobs = set() self._session._async_jobs.add( threaded_requests.put(self.self, data=json.dumps(data))) else: r = self._session.put(self.self, data=json.dumps(data)) # TODO(ssbarnea): compare loaded data in order to verify if resource was updated indeed # we had random test failures (probably) due to caching time.sleep(4) self._load(self.self) def delete(self, params=None): """Delete this resource from the server, passing the specified query parameters. If this resource doesn't support ``DELETE``, a :py:exc:`.JIRAError` will be raised; subclasses that specialize this method will only raise errors in case of user error. """
def update(self, fields=None, async_=None, jira=None, notify=True, **kwargs): """Update this resource on the server. Keyword arguments are marshalled into a dict before being sent. If this resource doesn't support ``PUT``, a :py:exc:`.JIRAError` will be raised; subclasses that specialize this method will only raise errors in case of user error. :param async_: if true the request will be added to the queue so it can be executed later using async_run() """ if async_ is None: async_ = self._options['async'] data = {} if fields is not None: data.update(fields) data.update(kwargs) data = json.dumps(data) if not notify: querystring = "?notifyUsers=false" else: querystring = "" r = self._session.put( self.self + querystring, data=data) if 'autofix' in self._options and \ r.status_code == 400: user = None error_list = get_error_list(r) logging.error(error_list) if "The reporter specified is not a user." in error_list: if 'reporter' not in data['fields']: logging.warning( "autofix: setting reporter to '%s' and retrying the update." % self._options['autofix']) data['fields']['reporter'] = { 'name': self._options['autofix']} if "Issues must be assigned." in error_list: if 'assignee' not in data['fields']: logging.warning("autofix: setting assignee to '%s' for %s and retrying the update." % ( self._options['autofix'], self.key)) data['fields']['assignee'] = { 'name': self._options['autofix']} # for some reason the above approach fails on Jira 5.2.11 # so we need to change the assignee before if "Issue type is a sub-task but parent issue key or id not specified." in error_list: logging.warning( "autofix: trying to fix sub-task without parent by converting to it to bug") data['fields']['issuetype'] = {"name": "Bug"} if "The summary is invalid because it contains newline characters." in error_list: logging.warning("autofix: trying to fix newline in summary") data['fields'][ 'summary'] = self.fields.summary.replace("/n", "") for error in error_list: if re.search(u"^User '(.*)' was not found in the system\.", error, re.U): m = re.search( u"^User '(.*)' was not found in the system\.", error, re.U) if m: user = m.groups()[0] else: raise NotImplemented() if re.search("^User '(.*)' does not exist\.", error): m = re.search("^User '(.*)' does not exist\.", error) if m: user = m.groups()[0] else: raise NotImplemented() if user: logging.warning( "Trying to add missing orphan user '%s' in order to complete the previous failed operation." % user) jira.add_user(user, '*****@*****.**', 10100, active=False) # if 'assignee' not in data['fields']: # logging.warning("autofix: setting assignee to '%s' and retrying the update." % self._options['autofix']) # data['fields']['assignee'] = {'name': self._options['autofix']} # EXPERIMENTAL ---> if async_: if not hasattr(self._session, '_async_jobs'): self._session._async_jobs = set() self._session._async_jobs.add(threaded_requests.put( self.self, data=json.dumps(data))) else: r = self._session.put( self.self, data=json.dumps(data)) # TODO(ssbarnea): compare loaded data in order to verify if resource was updated indeed # we had random test failures (probably) due to caching time.sleep(4) self._load(self.self)