def update(self): """ Updates an issue on the GitHub repository. """ logging.info('Update issue #{}'.format(self.json['uid'])) try: get_ws_call(self.action, self.json, None) print(self.json) self.json['dateUpdated'] = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') del self.json['datasets'] # updating the issue body. with open(self.issue_path, 'w+') as data_file: data_file.write(simplejson.dumps(self.json, indent=4, sort_keys=True)) logging.info('Issue has been updated successfully!') except Exception as e: logging.error('An unknown error has occurred, this is the stack {0}, error code: {1}'.format(repr(e), 99))
def close(self): """ Close the GitHub issue """ logging.info('Closing issue #{}'.format(self.json['uid'])) try: get_ws_call(self.action, None, self.json['uid']) # Only in case the webservice operation succeeded. self.json['dateUpdated'] = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') self.json['dateClosed'] = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') if 'datasets' in self.json.keys(): del self.json['datasets'] with open(self.issue_path, 'w+') as data_file: data_file.write(simplejson.dumps(self.json, indent=4, sort_keys=True)) logging.info('Issue has been closed successfully!') except Exception as e: logging.error('An unknown error has occurred, this is the stack {0}, error code: {1}'.format(repr(e), 99))
def create(self): """ Creates an issue on the GitHub repository. :raises Error: If the issue registration fails without any result """ try: logging.info('Requesting issue #{} creation from errata service...'.format(self.json['uid'])) get_ws_call(self.action, self.json, None) logging.info('Updating fields of payload after remote issue creation...') self.json['dateUpdated'] = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') logging.info('Issue json schema has been updated, persisting in file...') with open(self.issue_path, 'w') as issue_file: if 'datasets' in self.json.keys(): del self.json['datasets'] issue_file.write(simplejson.dumps(self.json, indent=4, sort_keys=True)) logging.info('Issue file has been created successfully!') except Exception as e: logging.error('An unknown error has occurred, this is the stack {0}, error code: {1}'.format(repr(e), 99))
def retrieve(self, n, issues, dsets): """ :param n: :param issues: :param dsets: :return: """ logging.info('processing id {}'.format(n)) try: r = get_ws_call('retrieve', None, n) self.json = r.json()['issue'] path_to_issue, path_to_dataset = get_file_path(issues, dsets, self.json['uid']) # Todo find a better fix for key in fields_to_remove: del self.json[key] # Removing the closing date to avoid having null value for currently active issues. if 'dateClosed' in self.json.keys() and self.json['dateClosed'] is None: del self.json['dateClosed'] if 'models' not in self.json.keys(): self.json['models'] = [] # Writing dataset file with open(path_to_dataset, 'w') as dset_file: if not self.json['datasets']: logging.info('The issue {} seems to be affecting no datasets.'.format(self.json['uid'])) dset_file.write('No datasets provided with issue.') for dset in self.json['datasets']: dset_file.write(dset + '\n') del self.json['datasets'] # Writing issue file. with open(path_to_issue, 'w') as data_file: data_file.write(simplejson.dumps(self.json, indent=4, sort_keys=True)) except Exception as e: logging.error('An unknown error has occurred, this is the stack {0}, error code: {1}'.format(repr(e), 99))