def post_conf_init(self): self.server = self._get_conf('server') self.base_uri = '%s://%s:%s@%s/%s' % ( self._get_conf('method'), urlencode_str(self._get_conf('user')), urlencode_str(self._get_conf('pass')), self.server, self.base_path)
def alm_connect_project(self): """ Verifies that the GitHub repo exists """ self.project_uri = '%s/%s' % (urlencode_str(self.config[self.GITHUB_REPO_OWNER]), urlencode_str(self.config['alm_project'])) # Check if GitHub repo is accessible try: repo_info = self.alm_plugin.call_api('repos/%s' % self.project_uri) except APIError, err: raise AlmException('Unable to find GitHub repo. Reason: %s' % err)
def __init__(self, config, test_dir=None): resource_templates = ['card.xml'] self.project_uri = '/org_name/api/v2/projects/%s' % urlencode_str(urlencode_str(config['alm_project'])) rest_api_targets = { '/org_name/api/v2/projects.xml': 'get_projects', '%s.xml' % self.project_uri: 'get_project', '%s/cards.xml' % self.project_uri: 'call_cards', '%s/cards/[0-9]+.xml' % self.project_uri: 'call_card_by_number', '%s/card_types.xml' % self.project_uri: 'get_card_types', '%s/property_definitions.xml' % self.project_uri: 'get_property_definitions', '%s/property_definitions/[0-9]+.xml' % self.project_uri: 'get_property_definition_by_id' } super(MingleResponseGenerator, self).__init__(rest_api_targets, resource_templates, test_dir)
def alm_connect_project(self): """ Verifies that the GitHub repo exists """ self.project_uri = '%s/%s' % (urlencode_str(self.config[self.GITHUB_REPO_OWNER]), urlencode_str(self.config['alm_project'])) # Check if GitHub repo is accessible try: repo_info = self.alm_plugin.call_api('repos/%s' % self.project_uri) except APIError as err: raise AlmException('Unable to find GitHub repo. Reason: %s' % str(err)) self.sync_titles_only = not repo_info.get('private') """ Validate project configurations """ self.milestone_id = self.github_get_milestone_id(self.config[self.ALM_PROJECT_VERSION])
def __init__(self, config, test_dir=None): project_uri = '%s/%s' % (urlencode_str(config['github_repo_owner']), urlencode_str(config['alm_project'])) self.project_milestone = config['alm_project_version'] self.username = config['alm_user'] self.alm_project = config['alm_project'] resource_templates = ['user.json', 'issue.json', 'repo.json', 'milestone.json'] rest_api_targets = { '/user': '******', '/repos/%s$' % project_uri: 'get_repo', '/repos/%s/milestones' % project_uri: 'get_milestones', '/legacy/issues/search/%s' % project_uri: 'get_issue', '/repos/%s/issues$' % project_uri: 'post_issue', '/repos/%s/issues/[0-9]*$' % project_uri: 'update_status' } super(GitHubResponseGenerator, self).__init__(rest_api_targets, resource_templates, test_dir)
def alm_get_task(self, task): task_id = task['title'] try: # We need to perform 2 API calls to search open and closed issues open_issues = self.alm_plugin.call_api('legacy/issues/search/%s/%s/%s' % (self.project_uri, self.config[self.ALM_NEW_STATUS], urlencode_str(task_id))) closed_issues = self.alm_plugin.call_api('legacy/issues/search/%s/%s/%s' % (self.project_uri, self.config[self.ALM_DONE_STATUSES][0], urlencode_str(task_id))) except APIError, err: logger.error(err) raise AlmException('Unable to get task %s from GitHub' % task_id)
def alm_get_task_legacy(self, task): """ Returns a RationalTask object that has the same ID as the given task """ try: work_items = self._call_api( '%s/workitems?oslc.where=dcterms:title="%s*"' % (self.query_url, urlencode_str(task["alm_fixed_title"])) ) except APIError as err: logger.error(err) raise AlmException("Unable to get task %s from %s" % (task["task_id"], self.alm_name)) if work_items["oslc:responseInfo"]["oslc:totalCount"] == 0: return None work_item_url = work_items["oslc:results"][0]["rdf:resource"] work_item_target = work_item_url.replace(self.alm_plugin.base_uri + "/", "") try: work_item = self._call_api(work_item_target) except APIError as err: logger.error(err) raise AlmException("Unable to get task %s from %s" % (task["task_id"], self.alm_name)) logger.info("Found task: %s", task["task_id"]) return self.get_task_object(task, work_item)
def pt_get_epic(self, group_name): try: epic = self.alm_plugin.call_api('%s/epics?filter=%s&fields=id' % (self.project_uri, urlencode_str(group_name))) except APIError as err: raise AlmException('Unable to get epic %s from PivotalTracker because of %s' % (group_name, err)) return epic
def alm_connect_project(self): # Connect to the project try: user = self._call_api('%s/customization/users/%s' % (self.project_uri, urlencode_str(self.config['alm_user']))) except APIError as err: raise AlmException('Unable to verify domain and project details: %s' % (err)) if user['Name'] != self.config['alm_user']: raise AlmException('Unable to verify user access to domain and project')
def initialize(self): super(HPAlmConnector, self).initialize() # Verify that the configuration options are set properly for item in ['hp_alm_done_statuses', 'hp_alm_issue_type', 'hp_alm_new_status', 'hp_alm_domain']: if not self.config[item]: raise AlmException('Missing %s in configuration' % item) self.config.process_list_config('hp_alm_done_statuses') self.COOKIE_LWSSO = None self.COOKIE_QCSession = None self.issue_type = None self.mark_down_converter = markdown.Markdown(safe_mode="escape") self.project_uri = 'rest/domains/%s/projects/%s' % (urlencode_str(self.config['hp_alm_domain']), urlencode_str(self.config['alm_project'])) self.test_plan_folder_id = None self.hp_alm_test_type_id = None # We will map requirements its associated tests based on the problem id self.requirement_to_test_mapping = {} self.fields = {} self.references = {}
def alm_get_task_legacy(self, task): try: # We need to perform 2 API calls to search open and closed issues open_issues = self.alm_plugin.call_api('legacy/issues/search/%s/%s/%s' % (self.project_uri, GITHUB_NEW_STATUS, urlencode_str(task['alm_fixed_title']))) closed_issues = self.alm_plugin.call_api('legacy/issues/search/%s/%s/%s' % (self.project_uri, GITHUB_DONE_STATUS, urlencode_str(task['alm_fixed_title']))) except APIError as err: raise AlmException('Unable to get task %s from GitHub. Reason: %s' % (task['task_id'], str(err))) issues_list = open_issues['issues'] issues_list.extend(closed_issues['issues']) if not issues_list: return None index = 0 # Prune list of issues labeled as duplicate while index < len(issues_list): issue = issues_list[index] duplicate_label = self.config[self.GITHUB_DUPLICATE_LABEL] if issue['labels'].count(duplicate_label) > 0: issues_list.pop(index) else: index += 1 if len(issues_list) > 1: logger.warning('Found multiple issues with the title %s that are not labeled as duplicates.' 'Selecting the first task found with id %s' % (task['task_id'], issues_list[0]['number'])) elif not issues_list: return None logger.info('Found task: %s', task['task_id']) return self.get_task_object(task, issues_list[0])
def __init__(self, config, test_dir=None): self.new_status = config['hp_alm_new_status'] hp_alm_domain = urlencode_str(config['hp_alm_domain']) hp_alm_project = urlencode_str(config['alm_project']) self.hp_alm_user = config['alm_user'] project_uri = '/qcbin/rest/domains/%s/projects/%s' % (hp_alm_domain, hp_alm_project) resource_templates = ['user.json', 'requirement.json', 'test.json', 'test-folder.json', 'requirement-coverage.json'] rest_api_targets = { '/qcbin/authentication-point/authenticate': 'authenticate', '/qcbin/rest/site-session': 'get_session', '%s/requirements' % project_uri: 'call_requirements', '%s/customization/users/%s' % (project_uri, urlencode_str(self.hp_alm_user)): 'get_user', '%s/customization/entities/requirement/types/' % project_uri: 'get_requirement_types', '%s/customization/entities/test/types/' % project_uri: 'get_test_types', '%s/customization/used-lists\?name=Status' % project_uri: 'get_status_types', '%s/customization/entities/requirement/fields/' % project_uri: 'get_entity_fields', '%s/customization/entities/test/fields/' % project_uri: 'get_entity_fields', '%s/test-folders' % project_uri: 'call_test_folders', '%s/tests' % project_uri: 'call_tests', '/qcbin/authentication-point/logout': 'logout', '%s/requirement-coverages' % project_uri: 'call_requirement_coverage' } super(HPAlmResponseGenerator, self).__init__(rest_api_targets, resource_templates, test_dir)
def add_epic(self, target, flag, data, method): if not flag and data: epic_name = urlencode_str(data['name']) if len(self.generator_get_filtered_resource('epic', {'name': epic_name})) == 0: resource_data = data resource_data['project_id'] = self.project_id resource_data['id'] = random.randint(1, 999999999) self.generator_add_resource('epic', resource_data['id'], resource_data) return RESPONSE_HEADERS, self.generate_resource_from_template('epic', resource_data) else: self.raise_error('500', 'Epic %s already exists!' % data['name']) else: self.raise_error('401')
def pt_get_release_marker_id(self, release_name): try: release_markers = self.alm_plugin.call_api('%s/stories?filter=type:release,%s&fields=id' % (self.project_uri, urlencode_str(release_name))) except APIError as err: raise AlmException('Could not find release marker %s in PivotalTracker because of %s' % (release_name, err)) if not release_markers: raise AlmException('Could not find release marker %s in PivotalTracker' % release_name) release_marker = release_markers[0] if len(release_markers) > 1: logger.warning('Found multiple release markers with the title %s. Selecting the first release marker' 'found with id %s' % (release_name, release_marker['id'])) if release_marker.get('error'): raise AlmException('Could not find release marker %s in PivotalTracker. Reason: %s - %s' % (release_name, release_marker['code'], release_marker['general_problem'])) else: return release_marker['id']
def alm_get_task_legacy(self, task): alm_identity = self._clean_title(task['alm_fixed_title']) try: # Fields parameter will filter response data to only contain story status, name, timestamp and id target = ('%s/stories?filter="%s"&fields=url,current_state,name,updated_at,id,estimate,story_type' % (self.project_uri, urlencode_str(alm_identity))) stories = self.alm_plugin.call_api(target) except APIError as err: logger.error(err) raise AlmException('Unable to get story from PivotalTracker for task %s' % task['task_id']) if not stories: return None story = stories[0] if len(stories) > 1: logger.warning('Found multiple issues with the title %s. Selecting the first task found with id %s' % (alm_identity, story['id'])) logger.info('Found task: %s', task['task_id']) updateable = story['story_type'] not in self.requires_estimate or story.get('estimate') is not None return self.get_task_object(task, story, updateable)
def _hp_query_encoder(query): return urlencode_str(query).replace('+', '%20')