Beispiel #1
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)
Beispiel #2
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
Beispiel #3
0
 def print_user(self, user, with_repos=True):
     base = "{} ({})".format(user.name, user.username)
     if user.email:
         base = "{} - {}".format(base, user.email)
     Helpers.print_success("{}:".format(base), jumpline=True)
     if user.bio:
         print("  Bio: {}".format(user.bio))
     if with_repos:
         self.print_repos(user.repositories)
Beispiel #4
0
 def print_raw(self, data):
     authors = []
     if data:
         for item in data:
             authors.append(Parser(self.args).get_authors(item))
     if authors:
         Helpers.print_success("All emails:\n")
         self.print_raw_authors(set(Helpers.flatten(authors)))
     else:
         Helpers.print_error("gitmails: No authors to print")
Beispiel #5
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
Beispiel #6
0
 def print_organization(self, organization, with_repos=True):
     base = "{}".format(organization.name)
     if organization.email:
         base = "{} <{}>".format(base, organization.email)
     if organization.members:
         base = "{} ({} Members)".format(base, len(organization.members))
     Helpers.print_success("{}:".format(base), jumpline=True)
     if organization.blog:
         print("  Blog: {}".format(organization.blog))
     if with_repos:
         self.print_repos(organization.repositories)
Beispiel #7
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
Beispiel #8
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
Beispiel #9
0
    def clone_repo(self, repo):
        try:
            if self.args.verbose:
                Helpers.print_success("Clonning {}".format(repo_url))
            clone_repository(repo.url, self.get_repo_path(repo), bare=True)
            return True

        except ValueError as e:
            return False

        except Exception as e:
            Helpers.print_error(e)
            return False
Beispiel #10
0
 def set_repos_authors(self, repos):
     p = Pool()
     p.map(self.clone_repo, repos)
     Helpers.print_success("Collecting authors of repositories")
     results = p.map(self.get_repo_authors, repos)
     for i in results:
         if i:
             [
                 Helpers.get_by_identifier(repos,
                                           repo_id).set_authors(authors)
                 for repo_id, authors in i.items()
             ]
     return True
Beispiel #11
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
Beispiel #12
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
Beispiel #13
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
Beispiel #14
0
    def get_collaborators(self, repos):
        if repos:
            if self.args.verbose:
                Helpers.print_success("Collecting authors")
            if self.args.api:
                [
                    repo.set_authors(
                        self.repository_collaborators(repo.identifier))
                    for repo in repos
                ]
            else:
                GitUtils(self.args).set_repos_authors(repos)
            return True

        return False
Beispiel #15
0
    def collect(self, collectors):
        collected = []
        if self.args.username:
            Helpers.print_success("Collecting information for {}".format(
                self.args.username))
            collected = self.collect_users(self.args.username, collectors)
        elif self.args.organization:
            Helpers.print_success("Collecting information for {}".format(
                self.args.organization))
            collected = self.collect_organizations(self.args.organization,
                                                   collectors)
        if not collected:
            Helpers.print_error("gitmails: Could not collect any information")
            return False

        return collected
Beispiel #16
0
    def get_authors(self, repo_path):
        try:
            if self.args.verbose:
                Helpers.print_success(
                    "Collecting authors in ".format(repo_path))
            authors_set = set()
            repo = Repository(repo_path)
            for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
                authors_set.add(Author(commit.author.name,
                                       commit.author.email))
            return authors_set

        except Exception as e:
            Helpers.print_error(
                "{}: Could not collect authors".format(repo_path))
            return None
Beispiel #17
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
Beispiel #18
0
 def execute(self):
     if self.args.repository:
         Helpers.print_success("Collecting information for {}".format(
             self.args.repository))
         collected = GitUtils(self.args).get_repo_authors_by_url(
             self.args.repository)
     else:
         collected = self.collect(self.get_collectors())
     if not collected:
         sys.exit(3)
     Printer(self.args).print(collected)
     if self.args.file:
         authors_to_print = collected
         if not self.args.repository:
             authors_to_print = Parser(
                 self.args).get_collected_authors(collected)
         Helpers.write_authors_file(self.args.file, collected)
     if self.args.run_plugins and not self.args.repository:
         self.apply_plugins(self.get_plugins(), collected)
     return collected
Beispiel #19
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
Beispiel #20
0
 def collect_authors(self, repos):
     if self.args.verbose:
         Helpers.print_success("Collecting authors")
     return GitUtils(self.args).set_repos_authors(repos)
Beispiel #21
0
 def get_repo_authors_by_url(self, repo_url):
     Helpers.print_success("Clonning {}".format(repo_url))
     self.clone_repo_by_url(repo_url)
     return self.get_authors(self.get_repo_path_by_url(repo_url))