def get_repo_attributes_dict(input_repo: Repository,
                             last_commit_within_years: int = 2):
    result_dict = {}
    try:
        result_dict = {
            'repo_path': input_repo.full_name,
            'created_at': input_repo.created_at,
            'last_commit': get_last_commit_date(input_repo),
            'last_update': input_repo.updated_at,
            'star_count': input_repo.stargazers_count,
            'fork_count': input_repo.forks_count,
            'contributors_count': input_repo.get_contributors().totalCount
        }
        today = datetime.datetime.today()
        check_start_date = datetime.datetime(
            today.year - last_commit_within_years, today.month, today.day)

        if result_dict['last_commit'] >= check_start_date:
            repo_status = 'active'
        else:
            repo_status = 'inactive'
        result_dict['repo_status'] = repo_status
    except Exception as e:
        print(e)

    return result_dict
Example #2
0
            def import_repo(repo: Repository):
                repo_id = repo.full_name
                if repo_id is None:
                    return repo, []

                with graph_lock:
                    if repo_id in g:
                        return repo, []

                if repo.fork and repo.parent and repo.parent.full_name and repo.owner:
                    import_repo(repo.parent)
                    link_user(repo.parent.full_name,
                              repo.owner.login,
                              relation='fork',
                              fork_source=repo_id,
                              date=repo.created_at.isoformat())

                language = repo.language or '?'
                weight = repo.watchers_count or 0
                with graph_lock:
                    g.add_node(repo_id,
                               bipartite=0,
                               language=language,
                               weight=weight,
                               date=repo.updated_at.isoformat())

                repo_forks = []
                try:
                    if since is None:
                        if repo.owner is not None:
                            link_user(repo_id,
                                      repo.owner.login,
                                      relation='owner',
                                      date=repo.pushed_at.isoformat())

                        contributors = repo.get_contributors()
                        for user in contributors:
                            link_user(repo_id,
                                      user.login or user.email,
                                      relation='contributor')
                    else:
                        commits = [
                            x for x in repo.get_commits(since=since)
                            if x.author and x.commit.author
                        ]
                        commits = sorted(commits,
                                         key=lambda x: x.commit.author.date)
                        for commit in commits:
                            date: datetime = commit.commit.author.date
                            link_user(repo_id,
                                      commit.author.login
                                      or commit.author.email,
                                      relation="committer",
                                      date=date.isoformat())

                    repo_forks = list(repo.get_forks())
                except RateLimitExceededException:
                    with graph_lock:
                        g.remove_node(repo_id)
                    raise
                except GithubException:
                    with graph_lock:
                        g.remove_node(repo_id)
                except Exception:
                    raise

                return repo, repo_forks