<commit_before>import urllib

from gitlabform.gitlab.core import GitLabCore


class GitLabProjects(GitLabCore):

    def get_all_projects(self):
        """
        :param group: group name
        :return: sorted list of ALL projects you have access to, strings "group/project_name"
        """
        result = self._make_requests_to_api("/projects?order_by=name&sort=asc", paginated=True)
        return sorted(map(lambda x: x['path_with_namespace'], result))

    def get_projects(self, group):
        """
        :param group: group name
        :return: sorted list of strings "group/project_name"
        """
        result = self._make_requests_to_api("/groups/%s/projects?simple=true", group, paginated=True)
        return sorted(map(lambda x: group + '/' + x['path'], result))

    def post_deploy_key(self, project_and_group_name, deploy_key):
        pid = self._get_project_id(project_and_group_name)
        # deploy_key has to be like this:
        # {
        #     'title': title,
        #     'key': key,
        #     'can_push': can_push,
        # }
        # ..as documented at: https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key<commit_msg>Get only projects from group namespace by default<commit_after>import urllib

from gitlabform.gitlab.core import GitLabCore


class GitLabProjects(GitLabCore):

    def get_all_projects(self):
        """
        :param group: group name
        :return: sorted list of ALL projects you have access to, strings "group/project_name"
        """
        result = self._make_requests_to_api("/projects?order_by=name&sort=asc", paginated=True)
        return sorted(map(lambda x: x['path_with_namespace'], result))

    def get_projects(self, group, only_from_group_namespace=True):
        """
        :param group: group name
        :param only_from_group_namespace: if `group` is also used as a *users* group to give access to projects
               within other namespaces than `group`, then to get projects only within namespace `group` with this method
               you should set `only_from_group_namespace` to True
        :return: sorted list of strings "group/project_name"
        """
        projects = self._make_requests_to_api("/groups/%s/projects", group, paginated=True)

        project_and_groups = sorted(map(lambda x: x['path_with_namespace'], projects))

        if only_from_group_namespace:
            return [x for x in project_and_groups if x.startswith(group + '/')]
        else:
            return project_and_groups

    def post_deploy_key(self, project_and_group_name, deploy_key):
        pid = self._get_project_id(project_and_group_name)
        # deploy_key has to be like this:
        # {
        #     'title': title,
        #     'key': key,
        #     'can_push': can_push,
        # }
        # ..as documented at: https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
{'fraction_non_alphanumeric': 0.10406616126809097, 'fraction_numerical': 0.0, 'mean_word_length': 2.809711286089239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1528463', 'n_tokens_mistral': 873, 'n_tokens_neox': 848, 'n_words': 215}