|
| 1 | +import pandas as pd |
| 2 | +from pandas import DataFrame |
| 3 | + |
| 4 | +from src.github import process_github_repositories |
| 5 | +from src.pypi import process_pypi_repositories |
| 6 | +from src.utils import get_config_var, get_env_var, log_function, setup_logger |
| 7 | + |
| 8 | +logger = setup_logger() |
| 9 | + |
| 10 | + |
| 11 | +@log_function(logger) |
| 12 | +def load_repositories( |
| 13 | + file_path: str, |
| 14 | +) -> DataFrame: |
| 15 | + """ |
| 16 | + Reads a list of repositories from a TSV file and returns it as a DataFrame. |
| 17 | +
|
| 18 | + :param file_path: Path to the TSV file containing the list of repositories. |
| 19 | + :return: DataFrame containing the list of repositories. |
| 20 | + """ |
| 21 | + return pd.read_csv(file_path, sep="\t") |
| 22 | + |
| 23 | + |
| 24 | +@log_function(logger) |
| 25 | +def process_repositories( |
| 26 | + repositories_df: DataFrame, |
| 27 | + github_token: str, |
| 28 | + pepy_x_api_key: str, |
| 29 | +): |
| 30 | + """ |
| 31 | + Args: |
| 32 | + repositories_df (DataFrame): DataFrame containing the list of repositories. |
| 33 | + github_token (str): GitHub token to access the GitHub API. |
| 34 | + Returns: |
| 35 | + None |
| 36 | + """ |
| 37 | + for _, row in repositories_df.iterrows(): |
| 38 | + source = row["source"].lower() |
| 39 | + repository = row["repository"] |
| 40 | + action = row["action"] |
| 41 | + project = row["project"] |
| 42 | + package = row["package"] |
| 43 | + if source == "github": |
| 44 | + owner, repo = repository.split("/") |
| 45 | + process_github_repositories( |
| 46 | + owner, repo, github_token, action, project, package |
| 47 | + ) |
| 48 | + elif source == "pypi": |
| 49 | + process_pypi_repositories( |
| 50 | + package, pepy_x_api_key, action, project |
| 51 | + ) |
| 52 | + else: |
| 53 | + logger.error(f"Unknown source: {source}") |
| 54 | + |
| 55 | + |
| 56 | +@log_function(logger) |
| 57 | +def main(): |
| 58 | + repo_file_path = get_config_var("DEFAULT", "REPO_FILE_PATH") |
| 59 | + if repo_file_path: |
| 60 | + logger.info("REPO_FILE_PATH found in .config file") |
| 61 | + repositories_df = load_repositories(repo_file_path) |
| 62 | + github_token = get_env_var("github_token") |
| 63 | + pepy_x_api_key = get_env_var("pepy_x_api_key") |
| 64 | + process_repositories(repositories_df, github_token, pepy_x_api_key) |
| 65 | + logger.debug(f"Repositories DataFrame: \n{repositories_df}") |
| 66 | + else: |
| 67 | + logger.error("REPO_FILE_PATH not found in .config file") |
| 68 | + print("REPO_FILE_PATH not found in .config file") |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
0 commit comments