<commit_before># -*- coding: utf-8 -*-

import requests
import json
import markdown

# TODO: snippets
# TODO: repositories
# TODO: deploy keys
# TODo: notes


class Gitlab(object):
    def __init__(self, host, token=""):
        if token != "":
            self.token = token
            self.headers = {"PRIVATE-TOKEN": self.token}
        if host[-1] == '/':
            self.host = host[:-1]
        else:
            self.host = host
        self.projects_url = self.host + "/api/v3/projects"
        self.users_url = self.host + "/api/v3/users"
        self.keys_url = self.host + "/api/v3/user/keys"
        self.groups_url = self.host + "/api/v3/groups"

    def login(self, email, password):
        data = {"email": email, "password": password}
        request = requests.post(self.host + "/api/v3/session", data=data)
        if request.status_code == 201:
            self.token = json.loads(request.content)['private_token']
            self.headers = {"PRIVATE-TOKEN": self.token}
            return True
        else:
            print request
            return False

    def getUsers(self, id_=0, page=1, per_page=20):
        """
        Return a user list
        :param id_: the id of the user to get instead of getting all users,
         return all users if 0
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        return: returs a dictionary of the users, false if there is an error
        """
        params = {'page': page, 'per_page': per_page}
        if id_ != 0:
            request = requests.get(self.host + "/api/v3/users/" + str(id_),
                             params=params, headers=self.headers)
            user = json.loads(request.content)
            return [user['id'], user['username'], user['name'], user['email'],
                    user['state'], user['created_at']]
        else:
            request = requests.get(self.users_url, params=params, headers=self.headers)
            if request.status_code == 200:
                return json.loads(request.content)
            else:
                return False

    def createUser(self, name, username, password, email, skype="", linkedin="",
                   twitter="",
                   projects_limit="", extern_uid="", provider="", bio=""):
        """
        Create a user
        :param name: Obligatory
        :param username: Obligatory
        :param password: <PASSWORD>
        :param email: Obligatory
        :return: TRue if the user was created,false if it wasn't(already exists)
        """
        data = {"name": name, "username": username, "password": password,
                "email": email, "skype": skype,
                "twitter": twitter, "linkedin": linkedin,
                "projects_limit": projects_limit, "extern_uid": extern_uid,
                "provider": provider, "bio": bio}
        request = requests.post(self.users_url, headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        elif request.status_code == 404:
            print request
            return False

    def deleteUser(self, id_):
        """
        Deletes an user by ID
        :param id_: id of the user to delete
        :return: True if it deleted, False if it couldn't. False could happen
        for several reasons, but there isn't a
        good way of differenting them
        """
        request = requests.delete(self.users_url + "/" + str(id_),
                            headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def currentUser(self):
        """
        Returns the current user parameters. The current user is linked
        to the secret token
        :return: a list with the current user properties
        """
        request = requests.get(self.host + "/api/v3/user",
                         headers=self.headers)
        return json.loads(request.content)

    def editUser(self, id_, name="", username="", password="", email="",
                 skype="", linkedin="", twitter="",
                 projects_limit="", extern_uid="", provider="", bio=""):
        data = {}
        if name != "":
            data["name"] = name
        if username != "":
            data["username"] = username
        if password != "":
            data["password"] = password
        if email != "":
            data["email"] = email
        if skype != "":
            data["skype"] = skype
        if linkedin != "":
            data["linkedin"] = linkedin
        if twitter != "":
            data["twitter"] = twitter
        if projects_limit != "":
            data["projects_limit"] = projects_limit
        if extern_uid != "":
            data["extern_uid"] = extern_uid
        if provider != "":
            data["provider"] = provider
        if bio != "":
            data["bio"] = bio
        request = requests.put(self.users_url + "/" + str(id_),
                               headers=self.headers, data=data)
        if request.status_code == 404:
            return True
        # There is a problem here and that is that the api always return 404,
        #  doesn't matter what heappened with the request,
        # so now way of knowing what happened
        else:
            return False

    def getSshKeys(self):
        """
        Gets all the ssh keys for the current user
        :return: a dictionary with the lists
        """
        request = requests.get(self.keys_url, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getSshKey(self, id_):
        """
        Get a single ssh key identified by id_
        :param id_: the id of the key
        :return: the key itself
        """
        request = requests.get(self.keys_url + "/" + str(id_),
                               headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addSshKey(self, title, key):
        """
        Add a new ssh key for the current user
        :param title: title of the new key
        :param key: the key itself
        :return: true if added, false if it didn't add it
        (it could be because the name or key already exists)
        """
        data = {"title": title, "key": key}
        request = requests.post(self.keys_url, headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def addSshKeyUser(self, id_, title, key):
        """
        Add a new ssh key for the user identified by id
        :param id_: id of the user to add the key to
        :param title: title of the new key
        :param key: the key itself
        :return: true if added, false if it didn't add it
        (it could be because the name or key already exists)
        """
        data = {"title": title, "key": key}
        request = requests.post(self.keys_url + "/" + str(id_) + "/keys",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def deleteSshKey(self, id_):
        """
        Deletes an sshkey for the current user identified by id
        :param id_: the id of the key
        :return: False if it didn't delete it, True if it was deleted
        """
        request = requests.delete(self.keys_url + "/" + str(id_),
                            headers=self.headers)
        if request.content == "null":
            print request
            return False
        else:
            return True

    def getProjects(self, page=1, per_page=20):
        """
        Returns a dictionary of all the projects
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        :return: list with the repo name, description, last activity,
         web url, ssh url, owner and if its public
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.projects_url, params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProject(self, id_):
        """
        Get info for a project identified by id
        :param id_: id of the project
        :return: False if not found, a dictionary if found
        """
        request = requests.get(self.projects_url + "/" + str(id_),
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectEvents(self, id_, page=1, per_page=20):
        """
        Get the project identified by id, events(commits)
        :param id_: id of the project
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        :return: False if no project with that id, a dictionary
         with the events if found
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/events", params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def createProject(self, name, description="", default_branch="",
                      issues_enabled="", wall_enabled="",
                      merge_requests_enabled="", wiki_enabled="",
                      snippets_enabled="", public=""):
        """
        Create a project
        :param name: Obligatory
        :return: Dict of information on the newly created project if successful,
         False otherwise
        """
        data = {"name": name, "description": description,
                "default_branch": default_branch,
                "issues_enabled": issues_enabled, "wall_enabled": wall_enabled,
                "merge_requests_enabled": merge_requests_enabled,
                "wiki_enabled": wiki_enabled,
                "snippets_enabled": snippets_enabled}

        # if gitlab is the new 6th version, there is a public option for the
        # project creation
        if len(public) > 0:
            data['public'] = public
        #request now works with both GitLab 5 and GitLab 6.
        request = requests.post(self.projects_url, headers=self.headers,
                                data=data)
        if request.status_code == 201:
            return json.loads(request.content)
        else:
            print request
            return False

    def createProjectUser(self, id_, name, description="", default_branch="",
                          issues_enabled="", wall_enabled="",
                          merge_requests_enabled="", wiki_enabled="",
                          snippets_enabled=""):
        """
        Create a project for the given user identified by id
        :param id_: id of the user to crete the project for
        :param name: Obligatory
        :return: True if it created the project, False otherwise
        """
        data = {"name": name, "description": description,
                "default_branch": default_branch,
                "issues_enabled": issues_enabled, "wall_enabled": wall_enabled,
                "merge_requests_enabled": merge_requests_enabled,
                "wiki_enabled": wiki_enabled,
                "snippets_enabled": snippets_enabled}
        request = requests.post(self.projects_url + "/user/" + str(id_),
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def listProjectMembers(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) + "/members",
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addProjectMember(self, id_, user_id, access_level):
        # check the access level and put into a number
        if access_level.lower() == "master":
            access_level = 40
        elif access_level.lower() == "developer":
            access_level = 30
        elif access_level.lower() == "reporter":
            access_level = 20
        else:
            access_level = 10
        data = {"id": id_, "user_id": user_id, "access_level": access_level}
        request = requests.post(self.projects_url + "/" + str(id_) + "/members",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def editProjectMember(self, id_, user_id, access_level):
        if access_level.lower() == "master":
            access_level = 40
        elif access_level.lower() == "developer":
            access_level = 30
        elif access_level.lower() == "reporter":
            access_level = 20
        else:
            access_level = 10
        data = {"id": id_, "user_id": user_id, "access_level": access_level}
        request = requests.put(self.projects_url + "/" + str(id_) + "/members/"
                               + str(user_id), headers=self.headers, data=data)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def deleteProjectMember(self, id_, user_id):
        request = requests.delete(self.projects_url + "/" + str(id_)
                                  + "/members/" + str(user_id),
                                  headers=self.headers)
        if request.status_code == 200:
            return True  # It always returns true

    def getProjectHooks(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) + "/hooks",
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectHook(self, id_, hook_id):
        request = requests.get(self.projects_url + "/" + str(id_) + "/hooks/" +
                         str(hook_id), headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addProjectHook(self, id_, url):
        data = {"id": id_, "url": url}
        request = requests.post(self.projects_url + "/" + str(id_) + "/hooks",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def editProjectHook(self, id_, hook_id, url):
        data = {"id": id_, "hook_id": hook_id, "url": url}
        request = requests.put(self.projects_url + "/" + str(id_) + "/hooks/" +
                         str(hook_id), headers=self.headers,
                         data=data)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def deleteProjectHook(self, id_, hook_id):
        request = requests.delete(self.projects_url + "/" + str(id_)
                                  + "/hooks/"
                                  + str(hook_id), headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def listBranches(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/repository/branches", headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def listBranch(self, id_, branch):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch),
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def protectBranch(self, id_, branch):
        request = requests.put(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch) + "/protect",
                         headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def unprotectBranch(self, id_, branch):
        request = requests.put(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch) + "/unprotect",
                         headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def createForkRelation(self, id_, from_):
        data = {"id": id_, "forked_from_id": from_}
        request = requests.post(self.projects_url + "/" + str(id_) +
                          "/fork/" + str(from_), headers=self.headers,
                          data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def removeForkRelation(self, id_):
        request = requests.delete(self.projects_url + "/" + str(id_) +
                            "/fork", headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def getIssues(self, page=1, per_page=20):
        """
        Return a global list of issues for your user.
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.host + "/api/v3/issues",
                               params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectIssues(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/issues", headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectIssue(self, id_, issue_id):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/issues/" + str(issue_id), headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)<commit_msg>Pagination for Gitlab.getProjectIssues<commit_after># -*- coding: utf-8 -*-

import requests
import json
import markdown

# TODO: snippets
# TODO: repositories
# TODO: deploy keys
# TODo: notes


class Gitlab(object):
    def __init__(self, host, token=""):
        if token != "":
            self.token = token
            self.headers = {"PRIVATE-TOKEN": self.token}
        if host[-1] == '/':
            self.host = host[:-1]
        else:
            self.host = host
        self.projects_url = self.host + "/api/v3/projects"
        self.users_url = self.host + "/api/v3/users"
        self.keys_url = self.host + "/api/v3/user/keys"
        self.groups_url = self.host + "/api/v3/groups"

    def login(self, email, password):
        data = {"email": email, "password": password}
        request = requests.post(self.host + "/api/v3/session", data=data)
        if request.status_code == 201:
            self.token = json.loads(request.content)['private_token']
            self.headers = {"PRIVATE-TOKEN": self.token}
            return True
        else:
            print request
            return False

    def getUsers(self, id_=0, page=1, per_page=20):
        """
        Return a user list
        :param id_: the id of the user to get instead of getting all users,
         return all users if 0
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        return: returs a dictionary of the users, false if there is an error
        """
        params = {'page': page, 'per_page': per_page}
        if id_ != 0:
            request = requests.get(self.host + "/api/v3/users/" + str(id_),
                             params=params, headers=self.headers)
            user = json.loads(request.content)
            return [user['id'], user['username'], user['name'], user['email'],
                    user['state'], user['created_at']]
        else:
            request = requests.get(self.users_url, params=params, headers=self.headers)
            if request.status_code == 200:
                return json.loads(request.content)
            else:
                return False

    def createUser(self, name, username, password, email, skype="", linkedin="",
                   twitter="",
                   projects_limit="", extern_uid="", provider="", bio=""):
        """
        Create a user
        :param name: Obligatory
        :param username: Obligatory
        :param password: <PASSWORD>
        :param email: Obligatory
        :return: TRue if the user was created,false if it wasn't(already exists)
        """
        data = {"name": name, "username": username, "password": password,
                "email": email, "skype": skype,
                "twitter": twitter, "linkedin": linkedin,
                "projects_limit": projects_limit, "extern_uid": extern_uid,
                "provider": provider, "bio": bio}
        request = requests.post(self.users_url, headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        elif request.status_code == 404:
            print request
            return False

    def deleteUser(self, id_):
        """
        Deletes an user by ID
        :param id_: id of the user to delete
        :return: True if it deleted, False if it couldn't. False could happen
        for several reasons, but there isn't a
        good way of differenting them
        """
        request = requests.delete(self.users_url + "/" + str(id_),
                            headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def currentUser(self):
        """
        Returns the current user parameters. The current user is linked
        to the secret token
        :return: a list with the current user properties
        """
        request = requests.get(self.host + "/api/v3/user",
                         headers=self.headers)
        return json.loads(request.content)

    def editUser(self, id_, name="", username="", password="", email="",
                 skype="", linkedin="", twitter="",
                 projects_limit="", extern_uid="", provider="", bio=""):
        data = {}
        if name != "":
            data["name"] = name
        if username != "":
            data["username"] = username
        if password != "":
            data["password"] = password
        if email != "":
            data["email"] = email
        if skype != "":
            data["skype"] = skype
        if linkedin != "":
            data["linkedin"] = linkedin
        if twitter != "":
            data["twitter"] = twitter
        if projects_limit != "":
            data["projects_limit"] = projects_limit
        if extern_uid != "":
            data["extern_uid"] = extern_uid
        if provider != "":
            data["provider"] = provider
        if bio != "":
            data["bio"] = bio
        request = requests.put(self.users_url + "/" + str(id_),
                               headers=self.headers, data=data)
        if request.status_code == 404:
            return True
        # There is a problem here and that is that the api always return 404,
        #  doesn't matter what heappened with the request,
        # so now way of knowing what happened
        else:
            return False

    def getSshKeys(self):
        """
        Gets all the ssh keys for the current user
        :return: a dictionary with the lists
        """
        request = requests.get(self.keys_url, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getSshKey(self, id_):
        """
        Get a single ssh key identified by id_
        :param id_: the id of the key
        :return: the key itself
        """
        request = requests.get(self.keys_url + "/" + str(id_),
                               headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addSshKey(self, title, key):
        """
        Add a new ssh key for the current user
        :param title: title of the new key
        :param key: the key itself
        :return: true if added, false if it didn't add it
        (it could be because the name or key already exists)
        """
        data = {"title": title, "key": key}
        request = requests.post(self.keys_url, headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def addSshKeyUser(self, id_, title, key):
        """
        Add a new ssh key for the user identified by id
        :param id_: id of the user to add the key to
        :param title: title of the new key
        :param key: the key itself
        :return: true if added, false if it didn't add it
        (it could be because the name or key already exists)
        """
        data = {"title": title, "key": key}
        request = requests.post(self.keys_url + "/" + str(id_) + "/keys",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def deleteSshKey(self, id_):
        """
        Deletes an sshkey for the current user identified by id
        :param id_: the id of the key
        :return: False if it didn't delete it, True if it was deleted
        """
        request = requests.delete(self.keys_url + "/" + str(id_),
                            headers=self.headers)
        if request.content == "null":
            print request
            return False
        else:
            return True

    def getProjects(self, page=1, per_page=20):
        """
        Returns a dictionary of all the projects
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        :return: list with the repo name, description, last activity,
         web url, ssh url, owner and if its public
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.projects_url, params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProject(self, id_):
        """
        Get info for a project identified by id
        :param id_: id of the project
        :return: False if not found, a dictionary if found
        """
        request = requests.get(self.projects_url + "/" + str(id_),
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectEvents(self, id_, page=1, per_page=20):
        """
        Get the project identified by id, events(commits)
        :param id_: id of the project
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        :return: False if no project with that id, a dictionary
         with the events if found
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/events", params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def createProject(self, name, description="", default_branch="",
                      issues_enabled="", wall_enabled="",
                      merge_requests_enabled="", wiki_enabled="",
                      snippets_enabled="", public=""):
        """
        Create a project
        :param name: Obligatory
        :return: Dict of information on the newly created project if successful,
         False otherwise
        """
        data = {"name": name, "description": description,
                "default_branch": default_branch,
                "issues_enabled": issues_enabled, "wall_enabled": wall_enabled,
                "merge_requests_enabled": merge_requests_enabled,
                "wiki_enabled": wiki_enabled,
                "snippets_enabled": snippets_enabled}

        # if gitlab is the new 6th version, there is a public option for the
        # project creation
        if len(public) > 0:
            data['public'] = public
        #request now works with both GitLab 5 and GitLab 6.
        request = requests.post(self.projects_url, headers=self.headers,
                                data=data)
        if request.status_code == 201:
            return json.loads(request.content)
        else:
            print request
            return False

    def createProjectUser(self, id_, name, description="", default_branch="",
                          issues_enabled="", wall_enabled="",
                          merge_requests_enabled="", wiki_enabled="",
                          snippets_enabled=""):
        """
        Create a project for the given user identified by id
        :param id_: id of the user to crete the project for
        :param name: Obligatory
        :return: True if it created the project, False otherwise
        """
        data = {"name": name, "description": description,
                "default_branch": default_branch,
                "issues_enabled": issues_enabled, "wall_enabled": wall_enabled,
                "merge_requests_enabled": merge_requests_enabled,
                "wiki_enabled": wiki_enabled,
                "snippets_enabled": snippets_enabled}
        request = requests.post(self.projects_url + "/user/" + str(id_),
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def listProjectMembers(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) + "/members",
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addProjectMember(self, id_, user_id, access_level):
        # check the access level and put into a number
        if access_level.lower() == "master":
            access_level = 40
        elif access_level.lower() == "developer":
            access_level = 30
        elif access_level.lower() == "reporter":
            access_level = 20
        else:
            access_level = 10
        data = {"id": id_, "user_id": user_id, "access_level": access_level}
        request = requests.post(self.projects_url + "/" + str(id_) + "/members",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def editProjectMember(self, id_, user_id, access_level):
        if access_level.lower() == "master":
            access_level = 40
        elif access_level.lower() == "developer":
            access_level = 30
        elif access_level.lower() == "reporter":
            access_level = 20
        else:
            access_level = 10
        data = {"id": id_, "user_id": user_id, "access_level": access_level}
        request = requests.put(self.projects_url + "/" + str(id_) + "/members/"
                               + str(user_id), headers=self.headers, data=data)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def deleteProjectMember(self, id_, user_id):
        request = requests.delete(self.projects_url + "/" + str(id_)
                                  + "/members/" + str(user_id),
                                  headers=self.headers)
        if request.status_code == 200:
            return True  # It always returns true

    def getProjectHooks(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) + "/hooks",
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectHook(self, id_, hook_id):
        request = requests.get(self.projects_url + "/" + str(id_) + "/hooks/" +
                         str(hook_id), headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def addProjectHook(self, id_, url):
        data = {"id": id_, "url": url}
        request = requests.post(self.projects_url + "/" + str(id_) + "/hooks",
                          headers=self.headers, data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def editProjectHook(self, id_, hook_id, url):
        data = {"id": id_, "hook_id": hook_id, "url": url}
        request = requests.put(self.projects_url + "/" + str(id_) + "/hooks/" +
                         str(hook_id), headers=self.headers,
                         data=data)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def deleteProjectHook(self, id_, hook_id):
        request = requests.delete(self.projects_url + "/" + str(id_)
                                  + "/hooks/"
                                  + str(hook_id), headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def listBranches(self, id_):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/repository/branches", headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def listBranch(self, id_, branch):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch),
                         headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def protectBranch(self, id_, branch):
        request = requests.put(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch) + "/protect",
                         headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def unprotectBranch(self, id_, branch):
        request = requests.put(self.projects_url + "/" + str(id_) +
                         "/repository/branches/" + str(branch) + "/unprotect",
                         headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def createForkRelation(self, id_, from_):
        data = {"id": id_, "forked_from_id": from_}
        request = requests.post(self.projects_url + "/" + str(id_) +
                          "/fork/" + str(from_), headers=self.headers,
                          data=data)
        if request.status_code == 201:
            return True
        else:
            print request
            return False

    def removeForkRelation(self, id_):
        request = requests.delete(self.projects_url + "/" + str(id_) +
                            "/fork", headers=self.headers)
        if request.status_code == 200:
            return True
        else:
            print request
            return False

    def getIssues(self, page=1, per_page=20):
        """
        Return a global list of issues for your user.
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.host + "/api/v3/issues",
                               params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectIssues(self, id_, page=1, per_page=20):
        """
        Return a list of issues for project id_.
        :param id_: The id for the project.
        :param page: Which page to return (default is 1)
        :param per_page: Number of items to return per page (default is 20)
        """
        params = {'page': page, 'per_page': per_page}
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/issues", params=params, headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
        else:
            print request
            return False

    def getProjectIssue(self, id_, issue_id):
        request = requests.get(self.projects_url + "/" + str(id_) +
                         "/issues/" + str(issue_id), headers=self.headers)
        if request.status_code == 200:
            return json.loads(request.content)
{'fraction_non_alphanumeric': 0.10322432176736812, 'fraction_numerical': 0.008335677209849394, 'mean_word_length': 1.70003451846738, 'pattern_counts': {'":': 134, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7013617', 'n_tokens_mistral': 10608, 'n_tokens_neox': 10108, 'n_words': 3063}