def transition_jira_issue(issue: Issue, state=None):
    """
    Note: if state is None, then this merely makes the labels self-consistent.

    :param issue:
    :param state:
    :return:
    """
    current_fields = issue.fields
    labels = set(current_fields.labels)

    if state is not None:
        assert state in progression.values()
        labels.discard('NeedsValidation')
        labels.add(state)

    expand_triage_label(labels)

    if {progression[triage_state] for triage_state in triage_states} <= labels:
        labels.remove('Triage')

    new_fields = {
        "labels": list(labels),
    }

    issue.update(fields=new_fields)
Exemplo n.º 2
0
def unflag_issue(conn: CustomJira, issue: Issue) -> None:
    """
    Remove the "Impediment" flag from an issue.

    :param conn: Jira connection.
    :param issue: Jira issue.
    """
    if getattr(issue.fields, conn.issue_fields[settings.JIRA_FIELDS_FLAGGED]):
        issue.update(fields={conn.issue_fields[settings.JIRA_FIELDS_FLAGGED]: None})
Exemplo n.º 3
0
def flag_issue(conn: CustomJira, issue: Issue) -> None:
    """
    Add the "Impediment" flag to an issue.

    :param conn: Jira connection.
    :param issue: Jira issue.
    """
    if not getattr(issue.fields, conn.issue_fields[settings.JIRA_FIELDS_FLAGGED]):
        issue.update(fields={conn.issue_fields[settings.JIRA_FIELDS_FLAGGED]: [{"value": "Impediment"}]})
Exemplo n.º 4
0
 def _close_issue(self, issue: jira.Issue, fields: Dict[str, Any], ignore_reopened: bool) -> None:
     if issue.fields.status.name == 'Closed':
         issue.update(fields=fields)
         return
     if not ignore_reopened and JiraCloser._is_reopened(issue):
         self.jira_client.add_comment(issue, 'A change related to this issue was integrated. This issue was re-opened before, the bot will not close this issue, please close it manually when applicable.')
         return
     if issue.fields.status.name == 'In Progress':
         fields.update({'resolution': {'name': 'Done'}})
         self.jira_client.transition_issue(issue.key, transition='Fixed', fields=fields)
         return
     fields.update({'resolution': {'name': 'Done'}})
     self.jira_client.transition_issue(issue.key, transition='Close', fields=fields)
Exemplo n.º 5
0
    def _mock_jira(self, old_jira=False, user=None):
        mock.patch.stopall()
        mock_patch = mock.patch('waldur_jira.backend.JIRA')
        self.mock_jira = mock_patch.start()
        self.mock_jira().fields.return_value = json.loads(
            load_resource('jira_fields.json'))
        issue_raw = json.loads(load_resource('jira_issue_raw.json'))
        mock_backend_issue = Issue({'server': ''}, None, raw=issue_raw)
        mock_backend_issue.update = mock.MagicMock()
        self.mock_jira(
        ).create_customer_request.return_value = mock_backend_issue
        self.mock_jira().waldur_create_customer_request.return_value = (
            mock_backend_issue)

        self.mock_jira().create_issue.return_value = mock_backend_issue

        mock_backend_users = [
            User(
                {'server': ''},
                None,
                raw={
                    'key': 'user_1',
                    'active': True,
                    'name': user.email if user else '*****@*****.**',
                },
            )
        ]
        if old_jira:
            self.mock_jira().search_users.return_value = mock_backend_users
        else:
            self.mock_jira(
            ).waldur_search_users.return_value = mock_backend_users
Exemplo n.º 6
0
    def _mock_jira(self):
        mock.patch.stopall()
        mock_patch = mock.patch('waldur_jira.backend.JIRA')
        self.mock_jira = mock_patch.start()
        self.mock_jira().fields.return_value = json.loads(load_resource('jira_fields.json'))
        issue_raw = json.loads(load_resource('jira_issue_raw.json'))
        mock_backend_issue = Issue({'server': ''}, None, raw=issue_raw)
        mock_backend_issue.update = mock.MagicMock()
        self.mock_jira().create_customer_request.return_value = mock_backend_issue

        self.mock_jira().create_issue.return_value = mock_backend_issue

        mock_backend_users = [User({'server': ''}, None, raw={'key': 'user_1', 'active': True})]
        self.mock_jira().search_users.return_value = mock_backend_users