Пример #1
0
def get_vcs_url(*, project, version_type, version_name):
    """
    Generate VCS (github, gitlab, bitbucket) URL for this version.

    Example: https://github.com/rtfd/readthedocs.org/tree/3.4.2/.
    External version example: https://github.com/rtfd/readthedocs.org/pull/99/.
    """
    if version_type == EXTERNAL:
        if 'github' in project.repo:
            user, repo = get_github_username_repo(project.repo)
            return GITHUB_PULL_REQUEST_URL.format(
                user=user,
                repo=repo,
                number=version_name,
            )
        if 'gitlab' in project.repo:
            user, repo = get_gitlab_username_repo(project.repo)
            return GITLAB_MERGE_REQUEST_URL.format(
                user=user,
                repo=repo,
                number=version_name,
            )
        # TODO: Add VCS URL for BitBucket.
        return ''

    url = ''
    if ('github' in project.repo) or ('gitlab' in project.repo):
        url = f'/tree/{version_name}/'
    elif 'bitbucket' in project.repo:
        url = f'/src/{version_name}'

    # TODO: improve this replacing
    return project.repo.replace('git://', 'https://').replace('.git', '') + url
Пример #2
0
    def vcs_url(self):
        """
        Generate VCS (github, gitlab, bitbucket) URL for this version.

        Example: https://github.com/rtfd/readthedocs.org/tree/3.4.2/.
        External Version Example: https://github.com/rtfd/readthedocs.org/pull/99/.
        """
        if self.type == EXTERNAL:
            if 'github' in self.project.repo:
                user, repo = get_github_username_repo(self.project.repo)
                return GITHUB_PULL_REQUEST_URL.format(
                    user=user,
                    repo=repo,
                    number=self.verbose_name,
                )
            if 'gitlab' in self.project.repo:
                user, repo = get_gitlab_username_repo(self.project.repo)
                return GITLAB_MERGE_REQUEST_URL.format(
                    user=user,
                    repo=repo,
                    number=self.verbose_name,
                )
            # TODO: Add VCS URL for BitBucket.
            return ''

        url = ''
        if self.slug == STABLE:
            slug_url = self.ref
        elif self.slug == LATEST:
            slug_url = self.project.default_branch or self.project.vcs_repo(
            ).fallback_branch
        else:
            slug_url = self.slug

        if ('github' in self.project.repo) or ('gitlab' in self.project.repo):
            url = f'/tree/{slug_url}/'

        if 'bitbucket' in self.project.repo:
            slug_url = self.identifier
            url = f'/src/{slug_url}'

        # TODO: improve this replacing
        return self.project.repo.replace('git://', 'https://').replace(
            '.git', '') + url