def test_send_success_message(self): callback = JiraRegistry.get('write_success_comment') issue = Issue({}, None) issue.id = 'JIRA-42' callback(self.jira_plugin, issue, self, "a message") self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue, mock.ANY) self.assertEqual(0, len(self.jira_plugin.regressions))
def test_warn_regression(self): callback = JiraRegistry.get('warn_regression') issue = Issue({}, None) issue.id = 'JIRA-42' callback(self.jira_plugin, issue, self, "a message") self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue, mock.ANY) self.assertEqual(1, len(self.jira_plugin.regressions)) self.assertEqual(self.jira_plugin.regressions[0].issue_id, issue.id)
def update_release_jira(self, issue: Issue, subtasks: List[Issue], template_vars: Dict[str, int]): template_issue_key = self.runtime.config["jira"]["templates"][ f"ocp{self.release_version[0]}"] _LOGGER.info("Updating release JIRA %s from template %s...", issue.key, template_issue_key) template_issue = self._jira_client.get_issue(template_issue_key) old_fields = { "summary": issue.fields.summary, "description": issue.fields.description, } fields = { "summary": template_issue.fields.summary, "description": template_issue.fields.description, } if "template" in template_issue.fields.labels: fields = self._render_jira_template(fields, template_vars) jira_changed = fields != old_fields if not self.dry_run: issue.update(fields) else: _LOGGER.warning( "Would have updated JIRA ticket %s with summary %s", issue.key, fields["summary"]) _LOGGER.info("Updating subtasks for release JIRA %s...", issue.key) template_subtasks = [ self._jira_client.get_issue(subtask.key) for subtask in template_issue.fields.subtasks ] if len(subtasks) != len(template_subtasks): _LOGGER.warning( "Release JIRA %s has different number of subtasks from the template ticket %s. Subtasks will not be updated.", issue.key, template_issue.key) return for subtask, template_subtask in zip(subtasks, template_subtasks): fields = { "summary": template_subtask.fields.summary, "description": template_subtask.fields.description, } if "template" in template_subtask.fields.labels: fields = self._render_jira_template(fields, template_vars) if not self.dry_run: subtask.update(fields) else: _LOGGER.warning( "Would have updated JIRA ticket %s with summary %s", subtask.key, fields["summary"]) return jira_changed
def rehydrate_issue(self, filename): stored = json.loads(self.get_asset_contents(filename)) return Issue( stored["options"], None, stored["raw"], )
def test_apply_jira_transition(self): register_transition('write_failure_and_back_in_dev', 'Set as To Do', 'test={test} message={message}') callback = JiraRegistry.get('write_failure_and_back_in_dev') issue = Issue({}, None) issue.id = 'JIRA-42' callback(self.jira_plugin, issue, self, "a message") self.jira_plugin.jira_client.add_comment.assert_called_once_with(issue, 'test={test} message={message}'.format( message='a message', test=self )) self.jira_plugin.jira_client.find_transitionid_by_name\ .assert_called_once_with(issue, 'Set as To Do') self.jira_plugin.jira_client.transition_issue\ .assert_called_once_with(issue, 1) self.assertEqual(0, len(self.jira_plugin.regressions))
def create_customer_request(self, fields=None, prefetch=True, use_old_api=False, **fieldargs): """The code for this function is almost completely copied from function create_customer_request of the JIRA library""" data = fields p = data['serviceDeskId'] service_desk = None if isinstance(p, str) or isinstance(p, int): service_desk = self.service_desk(p) elif isinstance(p, ServiceDesk): service_desk = p data['serviceDeskId'] = service_desk.id p = data['requestTypeId'] if isinstance(p, int): data['requestTypeId'] = p elif isinstance(p, str): data['requestTypeId'] = self.request_type_by_name(service_desk, p).id requestParticipants = data.pop('requestParticipants', None) url = self._options['server'] + '/rest/servicedeskapi/request' headers = {'X-ExperimentalApi': 'opt-in'} r = self._session.post(url, headers=headers, data=json.dumps(data)) raw_issue_json = json_loads(r) if 'issueKey' not in raw_issue_json: raise JIRAError(r.status_code, request=r) if requestParticipants: url = (self._options['server'] + '/rest/servicedeskapi/request/%s/participant' % raw_issue_json['issueKey']) headers = {'X-ExperimentalApi': 'opt-in'} if use_old_api: data = {'usernames': requestParticipants} else: data = {'accountIds': requestParticipants} r = self._session.post(url, headers=headers, json=data) if r.status_code != status.HTTP_200_OK: raise JIRAError(r.status_code, request=r) if prefetch: return self.issue(raw_issue_json['issueKey']) else: return Issue(self._options, self._session, raw=raw_issue_json)
def __call__(self, timer, issue): project_id = self.get_issue_project_id(issue) # If the issue did not match any explicitly defined project and it is # a subtask, get the parent issue if not project_id and issue.fields.issuetype.subtask: parent = Issue(issue._options, issue._session) parent.find(issue.fields.parent.key) project_id = self.get_issue_project_id(parent) # If no project was found yet, get the default project if not project_id: project_id = self._project_ids.get(None) # At this point, if we didn't get a project, then it's an error if not project_id: raise ValueError('Could not find a project ID for issue type "{}"' .format(issue.fields.issuetype)) return project_id
def get_epic(self, issue): if issue.fields.issuetype.subtask: parent = Issue(issue._options, issue._session) parent.find(issue.fields.parent.key) issue = parent epic = Issue(issue._options, issue._session) epic.find(getattr(issue.fields, self.epic_link_field)) return epic
def sprint_issues(cls, board_id, sprint_id): r_json = cls._get_json( 'rapid/charts/sprintreport?rapidViewId=%s&sprintId=%s' % (board_id, sprint_id), base=cls.AGILE_BASE_URL) issues = [] for t in type_of_issues_to_pull: if t in r_json['contents']: issues += [ Issue(cls._options, cls._session, raw_issues_json) for raw_issues_json in r_json['contents'][t] ] return {x.key: x for x in issues}.values()
def cached_issue(self): if not hasattr(self, '_cached_issue'): try: issue_path = self.get_metadata_path('issue.json') with io.open(issue_path, 'r', encoding='utf-8') as _in: storable = json.loads(_in.read()) self._cached_issue = Issue( storable['options'], None, storable['raw'], ) except IOError: self.log( 'Error encountered while loading cached issue!', level=logging.ERROR, ) self._cached_issue = self.issue return self._cached_issue
def cached_issue(self): if not hasattr(self, "_cached_issue"): try: issue_path = self.get_metadata_path("issue.json") with io.open(issue_path, "r", encoding="utf-8") as _in: storable = json.loads(_in.read()) self._cached_issue = Issue( storable["options"], None, storable["raw"], ) except IOError: self.log( "Error encountered while loading cached issue!", level=logging.ERROR, ) self._cached_issue = self.issue return self._cached_issue
def rehydrate(self, value: Dict) -> Issue: return Issue({}, None, value)