Exemple #1
0
 def get_contributors(self, commit_url):
     authors = []
     result = Helpers.request(commit_url)
     authors.append(self.parse_commits(result["values"]) if result else [])
     while "next" in result:
         result = Helpers.request(result["next"])
         authors.append(self.parse_commits(result["values"]) if result else [])
     return Helpers.flatten(authors)
Exemple #2
0
 def collect_repositories(self, repos_url):
     repos = []
     if self.args.verbose:
         Helpers.print_success("Collecting repositories")
     result = Helpers.request(repos_url)
     repos.append(self.parse_repositories(result["values"]) if result else [])
     while "next" in result:
         result = Helpers.request(result["next"])
         repos.append(self.parse_repositories(result["values"]) if result else [])
     repos = Helpers.flatten(repos)
     if not self.args.api:
         self.set_authors(repos)
     return repos
Exemple #3
0
 def collect_members(self, members_url):
     members = []
     if self.args.verbose:
         Helpers.print_success("Collecting members")
     last_page = Helpers.get_last_page(members_url)
     last_page = last_page + 1 if last_page == 0 else last_page
     for i in range(1, (last_page + 1)):
         result = Helpers.request("{}?page={}".format(members_url, i))
         if result:
             if self.args.include_users:
                 members.append(
                     list(
                         filter(
                             bool,
                             [
                                 self.collect_user(mem["login"],
                                                   with_repositories=False)
                                 for mem in result
                             ],
                         )))
             else:
                 members.append([
                     User(mem["login"], None, None, None, None)
                     for mem in result
                 ])
     return Helpers.flatten(members)
Exemple #4
0
    def get_userid(self, username):
        url = "{}/users?username={}".format(self.base_url, username)
        result = Helpers.request(url)
        if result:
            return result[0]["id"]

        return False
Exemple #5
0
 def collect_repositories(self, repos_url):
     if self.args.verbose:
         Helpers.print_success("Collecting repositories")
     result = Helpers.request(repos_url)
     repos = self.parse_repositories(result) if result else []
     self.get_collaborators(repos)
     return repos
Exemple #6
0
 def repository_collaborators(self, repoid):
     url = "{}/projects/{}/repository/contributors".format(
         self.base_url, repoid)
     result = Helpers.request(url)
     return [
         Author(contributor["name"], contributor["email"])
         for contributor in result if result
     ]
Exemple #7
0
    def collect_organization(self, organization):
        Helpers.print_success(
            "Collecting information of {} in Gitlab".format(organization))
        url = "{}/groups/{}".format(self.base_url, organization)
        result = Helpers.request(url)
        if result:
            repos = self.parse_repositories(result["projects"])
            self.get_collaborators(repos)
            return Organization(result["full_name"], None, None, repos, None)

        return False
Exemple #8
0
 def collect_repositories(self, repos_url):
     repos = []
     if self.args.verbose:
         Helpers.print_success("Collecting repositories")
     last_page = Helpers.get_last_page(repos_url)
     last_page = last_page + 1 if last_page == 0 else last_page
     for i in range(1, (last_page + 1)):
         result = Helpers.request("{}?page={}".format(repos_url, i))
         repos.append(self.parse_repositories(result) if result else [])
     repos = Helpers.flatten(repos)
     self.collect_authors(repos)
     return repos
Exemple #9
0
    def collect_user(self, username, with_repositories=True):
        Helpers.print_success(
            "Collecting information of {} in Github".format(username))
        url = "{}/users/{}".format(self.base_url, username)
        result = Helpers.request(url)
        if result:
            repos = None
            if with_repositories:
                repos = self.collect_repositories("{}/repos".format(url))
            return User(result["login"], result["name"], result["email"],
                        result["bio"], repos)

        return False
Exemple #10
0
    def collect_user(self, username):
        userid = self.get_userid(username)
        Helpers.print_success(
            "Collecting information of {} in Gitlab".format(username))
        url = "{}/users/{}".format(self.base_url, userid)
        result = Helpers.request(url)
        if result:
            repos = self.collect_repositories("{}/users/{}/projects".format(
                self.base_url, userid))
            return User(result["username"], result["name"], None,
                        result["bio"], repos)

        return False
Exemple #11
0
    def collect_organization(self, organization):
        Helpers.print_success(
            "Collecting information of {} in Bitbucket".format(organization)
        )
        url = "{}/teams/{}".format(self.base_url, organization)
        result = Helpers.request(url)
        if result:
            repos = self.collect_repositories(
                "{}/teams/{}/repositories".format(self.base_url, organization)
            )
            return Organization(
                result["display_name"], None, result["website"], repos, None
            )

        return False
Exemple #12
0
    def collect_user(self, username):
        Helpers.print_success(
            "Collecting information of {} in Bitbucket".format(username)
        )
        url = "{}/users/{}".format(self.base_url, username)
        result = Helpers.request(url)
        if result:
            repos = self.collect_repositories(
                "{}/repositories/{}".format(self.base_url, username)
            )
            return User(
                result["username"],
                result["display_name"],
                None,
                result["website"],
                repos,
            )

        return False
Exemple #13
0
    def collect_organization(self, organization):
        email = None
        blog = None
        name = None
        Helpers.print_success(
            "Collecting information of {} in Github".format(organization))
        url = "{}/orgs/{}".format(self.base_url, organization)
        result = Helpers.request(url)
        if result:
            members = self.collect_members("{}/members".format(url))
            repos = self.collect_repositories("{}/repos".format(url))
            if "email" in result:
                email = result["email"]
            if "blog" in result:
                blog = result["blog"]
            if "name" in result:
                name = result["name"]
            else:
                name = result["login"]
            return Organization(name, email, blog, repos, members)

        pass