Пример #1
0
def open_patcher_portal():
    fix_id = None
    fix_name = None

    if current_branch.find('patcher-') == 0:
        fix_id = current_branch[len('patcher-'):]
    elif current_branch.find('fix-pack-fix-') == 0:
        fix_id = current_branch[len('fix-pack-fix-'):]

    for typeFilter in ['0', '1', '6', '2']:
        if fix_id is None:
            fix_id, fix_name = get_fix_id(typeFilter)

    if fix_id is None:
        print('No existing fix to update, opening window for a new fix...')
        base_url = 'https://patcher.liferay.com/group/guest/patching/-/osb_patcher/fixes/create'
    else:
        print('Opening window to update fix %s...' % fix_id)
        base_url = 'https://patcher.liferay.com/group/guest/patching/-/osb_patcher/fixes/%s/edit' % fix_id

    product_version, project_version = get_baseline_id()

    origin_name = sys.argv[1]

    parameters = {
        'patcherProductVersionId': product_version,
        'patcherProjectVersionId': project_version,
        'committish': current_branch,
        'gitRemoteURL': origin_name
    }

    if fix_name is not None:
        parameters['patcherFixName'] = fix_name
    elif fix_id is not None:
        parameters['patcherFixName'] = get_fix_name_from_id(fix_id)
    else:
        pattern = re.compile('LP[EPS]-[0-9]*')
        fixes = set()

        for line in git.log('%s..%s' % (base_tag, 'HEAD'),
                            '--pretty=%s').split('\n'):
            fixes.update(pattern.findall(line))

        parameters['patcherFixName'] = ','.join(sorted(fixes))

    namespaced_parameters = get_namespaced_parameters(
        '1_WAR_osbpatcherportlet', parameters)

    query_string = '&'.join([
        '%s=%s' % (key, value) for key, value in namespaced_parameters.items()
    ])
    webbrowser.open_new_tab('%s?%s' % (base_url, query_string))
Пример #2
0
def process_patcher_search_container(base_url, parameters, container_name, column_names, callback):
	namespaced_parameters = get_namespaced_parameters('1_WAR_osbpatcherportlet', parameters)
	namespaced_parameters['p_p_state'] = 'exclusive'

	html = get_liferay_content(base_url, namespaced_parameters)
	soup = BeautifulSoup(html, 'html.parser')

	namespaced_container_name = '_1_WAR_osbpatcherportlet_%s' % container_name
	search_container = soup.find('div', {'id': namespaced_container_name})

	if search_container is None:
		print('Unable to find search results %s' % namespaced_container_name)
		return

	table = search_container.find('table')

	if table is None:
		print('Unable to find search results %s' % (namespaced_container_name))
		return

	thead = table.find('thead')
	tbody = table.find('tbody')

	if thead is None or tbody is None:
		print('No search results %s' % (namespaced_container_name))
		return

	column_indices = [-1] * len(column_names)

	for i, th in enumerate(thead.find_all('th')):
		th_text = th.text.strip().lower()

		for j, column_name in enumerate(column_names):
			if th_text == column_name:
				column_indices[j] = i

	missing_column = False

	for column_index, column_name in zip(column_indices, column_names):
		if column_index == -1:
			print('Unable to find column %s in search results %s' % (column_name, namespaced_container_name))
			missing_column = True

	if missing_column:
		return

	for tr in tbody.find_all('tr'):
		cells = tr.find_all('td')

		if cells is None:
			continue

		null_cell = False

		for index in column_indices:
			if cells[index] is None:
				null_cell = True
				break

		if not null_cell:
			callback({name: cells[index] for index, name in zip(column_indices, column_names)})
def get_previous_patcher_build(patcher_build):
    if patcher_build is None:
        return None

    account_code = patcher_build['patcherBuildAccountEntryCode']

    if account_code is None:
        return None

    print('Looking up patcher builds for account %s' % account_code)

    base_url = 'https://patcher.liferay.com/api/jsonws/osb-patcher-portlet.accounts/view'

    parameters = {'limit': 10, 'patcherBuildAccountEntryCode': account_code}

    json_response = json.loads(get_liferay_content(base_url, parameters))

    if json_response['status'] != 200:
        print('Unable to retrieve patcher account builds for %s' %
              account_code)
        return None

    matching_builds = [
        build for build in json_response['data']
        if (build['statusLabel'] == 'complete'
            or build['statusLabel'] == 'released')
        and build['downloadURL'][-8:] == patcher_build['downloadURL'][-8:]
        and build['patcherBuildId'] != patcher_build['patcherBuildId']
    ]

    account_parameters = {'patcherBuildAccountEntryCode': account_code}

    successful_builds = [
        build for build in matching_builds
        if build['qaStatusLabel'] == 'qa-automation-passed'
    ]

    if len(successful_builds) > 0:
        matching_builds = successful_builds

    same_baseline_builds = [
        build for build in matching_builds if build['patcherProjectVersionId']
        == patcher_build['patcherProjectVersionId']
    ]

    if len(same_baseline_builds) > 0:
        matching_builds = same_baseline_builds
        account_parameters['patcherProjectVersionId'] = patcher_build[
            'patcherProjectVersionId']

    account_base_url = 'https://patcher.liferay.com/group/guest/patching/-/osb_patcher/accounts/view'
    account_namespaced_parameters = get_namespaced_parameters(
        '1_WAR_osbpatcherportlet', account_parameters)
    account_query_string = '&'.join([
        '%s=%s' % (key, value)
        for key, value in account_namespaced_parameters.items()
    ])

    webbrowser.open_new_tab('%s?%s' % (account_base_url, account_query_string))

    patcher_build_fixes = get_fix_names(patcher_build)

    if len(matching_builds) == 0:
        best_matching_build = None
        best_matching_build_diff = patcher_build_fixes
        best_matching_build_name = patcher_build['patcherProjectVersionName']
    else:
        best_matching_build = None
        best_matching_build_fixes = None
        best_matching_build_diff = patcher_build_fixes

        for matching_build in matching_builds:
            matching_build_fixes = get_fix_names(matching_build)
            matching_build_diff = patcher_build_fixes - matching_build_fixes

            if len(matching_build_diff) < len(best_matching_build_diff):
                best_matching_build = matching_build
                best_matching_build_fixes = matching_build_fixes
                best_matching_build_diff = matching_build_diff

        if best_matching_build is not None:
            best_matching_build_name = 'fix-pack-fix-%s' % best_matching_build[
                'patcherFixId']

    new_fixes = get_new_fixes(patcher_build['patcherBuildId'],
                              best_matching_build_diff)

    if len(same_baseline_builds) > 0:
        webbrowser.open_new_tab(
            'https://github.com/liferay/liferay-portal-ee/compare/%s...fix-pack-fix-%s'
            % (best_matching_build_name, patcher_build['patcherFixId']))
    else:
        tag_name = patcher_build['patcherProjectVersionName']

        if tag_name.find('6.2') == 0:
            tag_name = None

            patcher_build_name = get_62_fix_pack(patcher_build)

            if patcher_build_name is None:
                tag_name = 'fix-pack-base-6210-%s' % tag_name.split(
                    ' ')[1].lower()
            else:
                tag_name = get_62_fix_pack_tag(patcher_build_name)

        webbrowser.open_new_tab(
            'https://github.com/liferay/liferay-portal-ee/compare/%s...fix-pack-fix-%s'
            % (tag_name, patcher_build['patcherFixId']))

    return best_matching_build