Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting repos by name #61

Closed
slarse opened this issue Jul 31, 2018 · 3 comments
Closed

Getting repos by name #61

slarse opened this issue Jul 31, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@slarse
Copy link
Collaborator

slarse commented Jul 31, 2018

Really doesn't work well for organizations with thousands of repos, it's just too slow.

@slarse slarse added the enhancement New feature or request label Jul 31, 2018
@slarse
Copy link
Collaborator Author

slarse commented Aug 1, 2018

    def get_repo_urls(self, repo_names: Iterable[str]) -> List[str]:
        """Get repo urls for all specified repo names in the current organization.
        Assumes that the repos exist, there is no guarantee that they actually do
        as checking this with the REST API takes too much time.

        Args:
            repo_names: A list of repository names.

        Returns:
            a list of urls corresponding to the repo names.
        """
        org_url = self._api._org.html_url
        return [
            "{}/{}".format(org_url, repo_name) for repo_name in list(repo_names)
        ]

@slarse
Copy link
Collaborator Author

slarse commented Aug 1, 2018

def _repo_names_to_urls(repo_names: Iterable[str],
                        api: github_api.GitHubAPI) -> List[str]:
    """Use the repo_names to extract urls to the repos. Look for git repos
    with the correct names in the local directory and create local uris for them.
    For the rest, create urls to the repos assuming they are in the target
    organization. Do note that theere is _not_ guarantee that the remote repos
    exist as checking this takes too much time with the REST API.

    A possible improvement would be to use the GraphQL API for this function.

    Args:
        repo_names: names of repositories.
        api: A GitHubAPI instance.

    Returns:
        a list of urls corresponding to the repo_names.
    """
    local = [
        name for name in repo_names if util.is_git_repo(os.path.abspath(name))
    ]
    non_local = [name for name in repo_names if name not in local]

    non_local_urls = api.get_repo_urls(repo_names)
    local_uris = [
        pathlib.Path(os.path.abspath(repo_name)).as_uri()
        for repo_name in local
    ]

    return non_local_urls + local_uris

@slarse
Copy link
Collaborator Author

slarse commented Aug 1, 2018

This is miles faster (as no HTTP calls are made). It makes the tool so much more snappy.

@slarse slarse closed this as completed in 8ce6576 Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant