コード例 #1
0
def release_note_block(code_block: dict,
                       reference_type: ReferenceType,
                       user_login: str,
                       cn_current_repo: ComponentName,
                       reference_id: str = None) -> ReleaseNoteBlock:
    text = _.trim(code_block.get('text'))
    if not text or 'none' == text.lower():
        return None

    category = code_block.get('category')
    target_group = code_block.get('target_group')
    source_repo = code_block.get('source_repo')
    if source_repo:
        reference_type = reference_type_for_type_identifier(
            code_block.get('reference_type'))
        reference_id = code_block.get('reference_id')
        user_login = code_block.get('user')
    else:
        source_repo = cn_current_repo.name()
        reference_type = reference_type
        reference_id = reference_id

    return ReleaseNoteBlock(category_id=category,
                            target_group_id=target_group,
                            text=text,
                            reference_type=reference_type,
                            reference_id=reference_id,
                            user_login=user_login,
                            source_repo=source_repo,
                            cn_current_repo=cn_current_repo)
コード例 #2
0
ファイル: util.py プロジェクト: gardener/cc-utils
def create_release_note_block(
    code_block: dict,
    reference_type: ReferenceType,
    user_login: str,
    current_component: gci.componentmodel.Component,
    source_component: gci.componentmodel.Component = None,
    reference_id: str = None,
) -> ReleaseNoteBlock:
    text = _.trim(code_block.get('text'))
    if not text or 'none' == text.lower():
        return None

    category = code_block.get('category')
    target_group = code_block.get('target_group')
    source_repo = code_block.get('source_repo')

    if source_component:
        reference_id = code_block.get('reference_id')
        reference_type = reference_type_for_type_identifier(
            code_block.get('reference_type'))
        user_login = code_block.get('user')
    elif source_repo:
        try:
            # try to fetch cd for the parsed source repo. The actual version does not matter,
            # we're only interested in the components GithubAccess (we assume it does not
            # change).
            ctx_repo_url = current_component.current_repository_ctx().baseUrl
            source_component = cnudie.retrieve.component_descriptor(
                name=source_repo,
                version=product.v2.greatest_component_version(
                    component_name=source_repo,
                    ctx_repo_base_url=ctx_repo_url,
                    ignore_prerelease_versions=True,
                ),
                ctx_repo_url=ctx_repo_url,
            ).component
        except requests.exceptions.HTTPError:
            logger.warning(
                f'Unable to retrieve component descriptor for source repository {source_repo}'
            )
            return None

        reference_type = reference_type_for_type_identifier(
            code_block.get('reference_type'))
        reference_id = code_block.get('reference_id')
        user_login = code_block.get('user')
    else:
        source_component = current_component

    return ReleaseNoteBlock(
        category_id=category,
        target_group_id=target_group,
        text=text,
        reference_type=reference_type,
        reference_id=reference_id,
        user_login=user_login,
        source_component=source_component,
        current_component=current_component,
    )