Пример #1
0
    def list_build_subdirs(self):
        config = self.config
        gh_client = self._get_client()
        source = config["build_source"]

        try:
            repo = gh_client.get_repo(source)

            # Find the first matching branch.
            repo_branches = self.list_field_values("branch_name") or []
            branches = find_matching_branches(config, repo_branches)
            branches = branches or [repo.default_branch or "master"]
            default_commit = repo.get_branch(branches[0]).commit
            commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)

            return [
                elem.path
                for elem in commit_tree.tree
                if (
                    elem.type == "blob" and self.filename_is_dockerfile(os.path.basename(elem.path))
                )
            ]
        except GithubException as ghe:
            message = ghe.data.get("message", "Unable to list contents of repository: %s" % source)
            if message == "Branch not found":
                raise EmptyRepositoryException()

            raise RepositoryReadException(message)
Пример #2
0
    def list_build_subdirs(self):
        config = self.config
        gl_client = self._get_authorized_client()
        new_build_source = config["build_source"]

        gl_project = gl_client.projects.get(new_build_source)
        if not gl_project:
            msg = "Unable to find GitLab repository for source: %s" % new_build_source
            raise RepositoryReadException(msg)

        repo_branches = gl_project.branches.list()
        if not repo_branches:
            msg = "Unable to find GitLab branches for source: %s" % new_build_source
            raise RepositoryReadException(msg)

        branches = [branch.attributes["name"] for branch in repo_branches]
        branches = find_matching_branches(config, branches)
        branches = branches or [gl_project.attributes["default_branch"] or "master"]

        repo_tree = gl_project.repository_tree(ref=branches[0])
        if not repo_tree:
            msg = "Unable to find GitLab repository tree for source: %s" % new_build_source
            raise RepositoryReadException(msg)

        return [node["name"] for node in repo_tree if self.filename_is_dockerfile(node["name"])]
Пример #3
0
    def list_build_subdirs(self):
        config = self.config
        repository = self._get_repository_client()

        # Find the first matching branch.
        repo_branches = self.list_field_values('branch_name') or []
        branches = find_matching_branches(config, repo_branches)
        if not branches:
            branches = [self._get_default_branch(repository)]

        (result, data,
         err_msg) = repository.get_path_contents('', revision=branches[0])
        if not result:
            raise RepositoryReadException(err_msg)

        files = set([f['path'] for f in data['files']])
        return [
            "/" + file_path for file_path in files
            if self.filename_is_dockerfile(os.path.basename(file_path))
        ]
Пример #4
0
    def load_dockerfile_contents(self):
        gl_client = self._get_authorized_client()
        path = self.get_dockerfile_path()

        gl_project = gl_client.projects.get(self.config["build_source"])
        if not gl_project:
            return None

        branches = self.list_field_values("branch_name")
        branches = find_matching_branches(self.config, branches)
        if branches == []:
            return None

        branch_name = branches[0]
        if gl_project.attributes["default_branch"] in branches:
            branch_name = gl_project.attributes["default_branch"]

        try:
            return gl_project.files.get(path, branch_name).decode()
        except gitlab.GitlabGetError:
            return None