Esempio n. 1
0
 def save_jira_icons_locally(self):
     from osbot_jira.api.jira_server.API_Jira_Rest import API_Jira_Rest
     jira_rest_api = API_Jira_Rest()
     icons = jira_rest_api.projects_icons()
     for key, url in icons.items():
         icon_path = f'{self.web_root}{self.jira_icons}/{key}.png'
         icon_bytes = jira_rest_api.request_get(url)
         save_bytes_as_file(icon_bytes, icon_path)
     return icons
Esempio n. 2
0
def run(event, context):
    load_dependency('requests')

    issue_id = event.get('issue_id')

    from osbot_jira.api.jira_server.API_Jira_Rest import API_Jira_Rest
    api_jira_rest = API_Jira_Rest()

    return api_jira_rest.issue(issue_id)
Esempio n. 3
0
    def send_data_from_project(self, project=None):
        if project:
            jql = 'project={0}'.format(project)
        else:
            jql = ''                                                        # todo: find a better way to get all results from Jira

        api_jira_rest = API_Jira_Rest()
        issues = api_jira_rest.search(jql)

        return self.elastic.add_bulk(issues, "Key")
Esempio n. 4
0
 def all_icons_local(self):  # todo find a way to get this from GitHub
     icons_local = []
     from osbot_jira.api.jira_server.API_Jira_Rest import API_Jira_Rest
     icons_names = API_Jira_Rest().projects_icons().keys()
     for icon_name in icons_names:
         icons_local.append(self.icon_local(icon_name))
     return icons_local
 def jira_edit_issue(self):
     try:
         for key, value in self.submission.items():
             key_split = key.split('::')
             issue_id = key_split.pop(0)
             field = key_split.pop(0)
             from osbot_jira.api.jira_server.API_Jira_Rest import API_Jira_Rest
             api_jira_rest = API_Jira_Rest()
             result = api_jira_rest.issue_update_field(
                 issue_id, field, value)
             if result:
                 return 'Field `{0}` updated'.format(field)
             else:
                 return ':red_circle: data not saved ok'.format(result)
     except Exception as error:
         self.send_message(
             ':red_circle: error in jira_edit_issue: {0}'.format(error))
Esempio n. 6
0
 def __init__(self, file_ids=None, sheet_name=None):
     self.gsuite_secret_id = 'gsuite_gsbot_user'
     self.file_id = Misc.array_get(file_ids, 0)
     self.other_files = file_ids
     self.sheet_name = sheet_name
     self.gsheets = GSheets(self.gsuite_secret_id)
     self.gsheets_sync = API_Jira_Sheets_Sync(self.file_id,
                                              self.gsuite_secret_id)
     self.jira_api_rest = API_Jira_Rest()
     self.gsheets_create = API_Jira_Sheets_Create(self.file_id)
 def api_jira_rest(self):
     return API_Jira_Rest()
Esempio n. 8
0
 def setUp(self):
     super().setUp()
     self.api = API_Jira_Rest()
Esempio n. 9
0
class Test_API_Jira_Rest(Test_Helper):
    def setUp(self):
        super().setUp()
        self.api = API_Jira_Rest()

    def test_config(self):
        assert self.api.config()[1] == 'gsbot'

    def test_fields(self):
        assert len(self.api.fields()) > 10
        #self.result = self.api.fields(index_by='name')
        # for field in self.api.fields():
        #     print(field.get('id'), field.get('name'))

    def test_fields_by_id(self):
        assert 'worklog' in self.api.fields_by_id().keys()
        #Dev.pprint(self.api.fields_by_id())

    def test_fields_by_name(self):
        assert 'Description' in self.api.fields_by_name().keys()
        #Dev.pprint(self.api.fields_by_name())

    # def test_fields_by_name__performance_test(self):        # test what happens when this method is called multiple times
    #     for i in range(0,2):
    #         Dev.pprint(len(self.api.fields_by_name()))

    def test_issue_raw(self):
        issue_id = 'PERSON-1'
        result = self.api.issue_raw(issue_id, '_')
        assert set(result) == {'id', 'self', 'key', 'expand'}

    def test_issue(self):
        issue_id = 'RISK-1'
        result = self.api.issue(issue_id)
        assert 'Key' in set(result)
        #assert set(result) == { 'Assignee', 'Created', 'Creator', 'Description', 'Issue Type', 'Key', 'Labels', 'Last Viewed', 'Priority', 'Project', 'Reporter', 'Risk Description', 'Risk Owner', 'Risk Rating', 'Risk Title', 'Status', 'Summary', 'Updated', 'Work Ratio'}

    def test_issues(self):
        issues_ids = ['RISK-12', 'RISK-424', 'SL-118', 'IA-12']
        result = self.api.issues(issues_ids, 'key')
        assert len(result) == 4

    def test_issue_update_field(self):
        issue_id = 'RISK-12'
        summary = 'updated via a rest put request.....'
        result = self.api.issue_update_field(issue_id, 'summary', summary)
        Dev.pprint(result)

    def test_issue_update_fields(self):
        issue_id = 'RISK-12'
        fields = {
            "Summary": "update from test... 12345",
            "Description": "The description.....123456",
            "Risk Description": "The risk description",
            "Labels": "Risk,Unit-Test",
            #"Priority"        : "Major"                     ,  # cannot be set (I think it is a screen issue)
            "Risk Rating": "High",
            "Assignee": "james.wharton"
        }
        assert self.api.issue_update_fields(issue_id, fields) is True

    def test_issue_status_available(self):
        issue_id = 'RISK-12'
        result = self.api.issue_status_available(issue_id)
        assert 'Blocked' in set(result)

    def test_projects(self):
        self.result = self.api.projects()

    def test_projects_icons(self):
        self.result = self.api.projects_icons()

    def test_search(self):
        jql = 'PROJECT=PERSON'
        fetch_all = True
        issues = self.api.search(jql, fetch_all)

        self.result = len(issues)

    def test_webhook_failed(self):
        self.result = self.api.webhook_failed()

    # https://glasswall.atlassian.net/browse/BUG-162
    # GWBot bug : The Creator field is not currently being updated when importing into elastic
    def test_bug_162__creator_field_not_updated(self):
        #assert self.api.issue_raw('TASK-21').get('fields').get('creator') is not None  # confirms we are getting the value from Jira
        #assert self.api.issue('TASK-21').get('Creator') is None                        # bug , this value should be set

        #self.result = self.api.issue_raw('TASK-21').get('fields')

        self.result = self.api.issue('TASK-21')
Esempio n. 10
0
 def __init__(self, grid):
     self.grid = grid
     self.api_jira = API_Jira()
     self.api_jira_rest = API_Jira_Rest()
Esempio n. 11
0
class QGrid_To_Jira:
    def __init__(self, grid):
        self.grid = grid
        self.api_jira = API_Jira()
        self.api_jira_rest = API_Jira_Rest()

    def jira_update_issue_status(self, key, value):
        transitions = self.api_jira.issue_next_transitions(key)
        transitions_id = transitions.get(value)
        if transitions_id is None:
            return {
                'status': 'error',
                'data': 'transition not available: {0}'.format(value)
            }
        result = self.api_jira.jira().transition_issue(key, transitions_id)

        return {'status': 'ok', 'data': result}

    def jira_remove_links_to_target(self, from_id, link_type, to_id):
        all_issue_links = self.api_jira.issue_links(from_id)
        issue_links = all_issue_links.get(link_type)
        if issue_links:
            for issue_link in issue_links:
                if to_id == issue_link.get('Key'):
                    link_id = issue_link.get('Id')
                    print('deleting link', from_id, link_type, link_id)
                    self.api_jira.issue_delete_link(link_id)
                    return True
        return False
        #return True  # to handle cases when a mistaske is made on the new issue link type

    def jira_update_issue_link(self, issue_id, to_id, old_link_issue,
                               new_link_issue):
        removed_ok = self.jira_remove_links_to_target(issue_id, old_link_issue,
                                                      to_id)
        if new_link_issue is '':
            if removed_ok:
                return {'status': 'ok', 'data': 'issue link removed'}
            else:
                return {'status': 'error', 'data': 'failed to remove link'}
        try:
            self.api_jira.issue_add_link(issue_id, new_link_issue, to_id)
            print('added link', issue_id, new_link_issue, to_id)
            if removed_ok:
                return {'status': 'ok', 'data': 'issue link edited'}
            else:
                print('Removing link failed', issue_id, old_link_issue, to_id)
                return {
                    'status': 'error',
                    'data': 'removing link failed BUT, adding new link worked'
                }
        except Exception as error:
            print('Failed to add link', issue_id, new_link_issue, to_id)
            print(error.text)
            if removed_ok:
                return {
                    'status': 'error',
                    'data': 'adding link failed (after removing link)'
                }
            else:
                return {
                    'status': 'error',
                    'data': 'adding and removing links failed'
                }

    def jira_update_field(self, key, field, value):
        if not value:
            result = {'status': 'error', 'data': 'empty values not supported'}
        else:
            value = value.strip()
            if field == 'Latest_Information': field = 'Latest Information'
            if field == 'Status':
                result = self.jira_update_issue_status(key, value)
            else:
                data = self.api_jira_rest.issue_update_field(key, field, value)
                if data is False:
                    result = {'status': 'error', 'data': data}
                else:
                    result = {'status': 'ok', 'data': data}
            result['key'] = key
            result['field'] = field
            result['value'] = value

        return result

    def setup(self):
        def on_value_change(event, qgrid_widget):
            key = event.get('index')
            field = event.get('column')
            value = event.get('new')
            print("updating field `{0}` with value `{1}` on issue `{2}".format(
                field, value, key))
            result = self.jira_update_field(key, field, value)
            print(result)

        self.grid.on('cell_edited', on_value_change)
        return self