diff --git a/.github/workflows/daily_collection.yaml b/.github/workflows/daily_collection.yaml index e2ed3ec..0de6ec7 100644 --- a/.github/workflows/daily_collection.yaml +++ b/.github/workflows/daily_collection.yaml @@ -25,9 +25,9 @@ jobs: run: | uv pip install -U pip uv pip install . - - name: Collect Github Data + - name: Collect GitHub Data run: | - uv run github-analytics collect -v -q -t ${{ secrets.GITHUB_TOKEN }} -m -c daily.yaml + uv run gitmetrics collect -v -q -t ${{ secrets.GITHUB_TOKEN }} -m -c daily.yaml env: PYDRIVE_CREDENTIALS: ${{ secrets.PYDRIVE_CREDENTIALS }} @@ -47,6 +47,6 @@ jobs: uv pip install -U pip uv pip install .[dev] - name: Slack alert if failure - run: python -m github_analytics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} + run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} env: SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/daily_summarize.yaml b/.github/workflows/daily_summarize.yaml index 4f93f60..43088dc 100644 --- a/.github/workflows/daily_summarize.yaml +++ b/.github/workflows/daily_summarize.yaml @@ -28,7 +28,7 @@ jobs: uv pip install . - name: Run Summarize run: | - uv run github-analytics summarize \ + uv run gitmetrics summarize \ --input-folder gdrive://1ZvsuVbFAUk3BN-n6Pv_lUBLwviHZSxM2 env: PYDRIVE_CREDENTIALS: ${{ secrets.PYDRIVE_CREDENTIALS }} @@ -66,9 +66,9 @@ jobs: uv pip install .[dev] - name: Slack alert if failure run: | - uv run python -m github_analytics.slack_utils \ + uv run python -m gitmetrics.slack_utils \ -r ${{ github.run_id }} \ -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} \ - -m 'Summarize GitHub Analytics build failed :fire: :dumpster-fire: :fire:' + -m 'Summarize GitMetrics build failed :fire: :dumpster-fire: :fire:' env: SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/manual.yaml b/.github/workflows/manual.yaml index 055b614..f05f63a 100644 --- a/.github/workflows/manual.yaml +++ b/.github/workflows/manual.yaml @@ -33,9 +33,9 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install . - - name: Collect Github Data + - name: Collect GitHub Data run: | - github-analytics collect -v -q \ + gitmetrics collect -v -q \ -t ${{ secrets.GITHUB_TOKEN }} \ -p ${{ github.event.inputs.project }} \ -r ${{ github.event.inputs.repositories }} \ diff --git a/.github/workflows/traffic_collection.yaml b/.github/workflows/traffic_collection.yaml index d145f71..8cb06a8 100644 --- a/.github/workflows/traffic_collection.yaml +++ b/.github/workflows/traffic_collection.yaml @@ -12,7 +12,7 @@ on: - cron: "0 0 */14 * *" # Runs every 14 days at midnight UTC jobs: - collect_traffic: + daily_traffic_collection: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -25,13 +25,13 @@ jobs: run: | uv pip install -U pip uv pip install . - - name: Collect Github Traffic Data + - name: Collect GitHub Traffic Data run: | - uv run github-analytics traffic -v -t ${{ secrets.GH_TRAFFIC_TOKEN }} -c traffic_config.yaml + uv run gitmetrics traffic -v -t ${{ secrets.GH_TRAFFIC_TOKEN }} -c traffic_config.yaml env: PYDRIVE_CREDENTIALS: ${{ secrets.PYDRIVE_CREDENTIALS }} alert: - needs: [daily_github_collection] + needs: [daily_traffic_collection] runs-on: ubuntu-latest if: failure() steps: @@ -46,6 +46,6 @@ jobs: uv pip install -U pip uv pip install .[dev] - name: Slack alert if failure - run: python -m github_analytics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} + run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} env: SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/weekly_collection.yaml b/.github/workflows/weekly_collection.yaml index 526f335..8d552b5 100644 --- a/.github/workflows/weekly_collection.yaml +++ b/.github/workflows/weekly_collection.yaml @@ -27,12 +27,12 @@ jobs: uv pip install . - name: Collect GitHub Data run: | - uv run github-analytics collect -v -q -t ${{ secrets.GITHUB_TOKEN }} -m -c weekly.yaml + uv run gitmetrics collect -v -q -t ${{ secrets.GITHUB_TOKEN }} -m -c weekly.yaml env: PYDRIVE_CREDENTIALS: ${{ secrets.PYDRIVE_CREDENTIALS }} - name: Consolidate GitHub Data run: | - uv run github-analytics consolidate -v -c weekly.yaml + uv run gitmetrics consolidate -v -c weekly.yaml env: PYDRIVE_CREDENTIALS: ${{ secrets.PYDRIVE_CREDENTIALS }} alert: @@ -51,6 +51,6 @@ jobs: uv pip install -U pip uv pip install .[dev] - name: Slack alert if failure - run: python -m github_analytics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} + run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} env: SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.gitignore b/.gitignore index 6a573f2..d3fdf7f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ bigquery_creds.json client_secrets.json credentials.json sdv-dev.github.io/* +uv.lock notebooks *.xlsx diff --git a/CONFIGURATION.md b/CONFIGURATION.md index ffd27fe..d4a17cb 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1,14 +1,14 @@ -# Github Analytics Configuration +# GitMetrics Configuration -The Github Analytics script can be configured using a YAML file that indicates which repositories +The GitMetrics script can be configured using a YAML file that indicates which repositories to collect and where to store the collected data. -Additionally, [Github Actions Workflows](.github/workflows) are being used to trigger the +Additionally, [GitMetrics Workflows](.github/workflows) are being used to trigger the collection of such projects either manually or on a scheduled basis. ## Configuration file format -The configuration file for `github-analytics` must have the following contents: +The configuration file for `gitmetrics` must have the following contents: * `output_folder`: Folder where results will be written. Can be a Google Drive in the format gdrive:// @@ -48,7 +48,7 @@ projects: ### Adding an entire organization Optionally, an organization or user name can be added to the confiuration instead of the -individual repositories, and then `github-analytics` will translate that into the list of +individual repositories, and then `gitmetrics` will translate that into the list of repositories owned by that user or organization *which are not forks of other repositories*. For example, this configuration file would include all the repositories listed above, @@ -78,12 +78,12 @@ projects: ## Default Configuration File -By default, Github Analytics collects the projects configured in the [config.yaml](config.yaml) +By default, GitMetrics collects the projects configured in the [config.yaml](config.yaml) file included in the project. However, passing a different configuration file when running the command line script is possible via the `-c` flag, as shown in the example above: ```bash -$ github-analytics collect -c my_config_file.yaml ... +$ gitmetrics collect -c my_config_file.yaml ... ``` ### Importing other configuration files @@ -142,11 +142,11 @@ projects: ## Daily and Weekly Collection -Github Analytics is configured to collect data daily and weekly via the +GitMetrics is configured to collect data daily and weekly via the [.github/workflow/daily.yaml](.github/workflow/daily.yaml) and [.github/workflow/weekly.yaml]( -.github/workflow/weekly.yaml) Github Action Workflows. +.github/workflow/weekly.yaml) GitHub Action Workflows. -These workflows are configured to execute the `github-analytics collect` command using the +These workflows are configured to execute the `gitmetrics collect` command using the [daily.yaml](daily.yaml) and [weekly.yaml](weekly.yaml) configuration files respectively, which: - Import the [config.yaml](config.yaml) file, where all the project repositories are listed diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 7182459..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,12 +0,0 @@ -include AUTHORS.rst -include CONTRIBUTING.rst -include HISTORY.md -include LICENSE -include README.md -include RELEASE.md - -recursive-include tests * -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] - -recursive-include docs *.md *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/README.md b/README.md index d69e25e..e1bf817 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Github Analytics +# GitMetrics -Scripts to extract multiple metrics from Github Projects. +Scripts to extract multiple metrics from GitHub Projects. ## Install ```bash -pip install git+ssh://git@github.com/datacebo/github-analytics +pip install git+ssh://git@github.com/datacebo/gitmetrics ``` ### Development @@ -13,18 +13,18 @@ pip install git+ssh://git@github.com/datacebo/github-analytics For development, clone the repository and install `dev-requirements.txt`: ```bash -git clone git@github.com:datacebo/github-analytics -cd github-analytics -pip install -r dev-requirements.txt +git clone git@github.com:datacebo/gitmetrics +cd gitmetrics +pip install -e .[test,dev] ``` # Local Usage -To collect metrics from github by running `github-analytics` on your computer you need to provide: +To collect metrics from GitHub by running `gitmetrics` on your computer you need to provide: -1. A Github Token. Documentation about how to create a Personal Access Token can be found +1. A GitHub Token. Documentation about how to create a Personal Access Token can be found [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) -2. A list of Github Repositories for which to collect the metrics. The repositories need +2. A list of GitHub Repositories for which to collect the metrics. The repositories need to be given as `{org-name}/{repo-name}`, like `sdv-dev/SDV`. 3. (Optional) A filename where the output will be stored. If a name containing the `.xlsx` extension is given (like `path/to/my-filename.xlsx`), it will be used as provided. @@ -36,7 +36,7 @@ To collect metrics from github by running `github-analytics` on your computer yo ## Python Interface In order to run the collection script from python, the `collect_project_metrics` function -needs to be imported from the `github_analytics` package and executed passing the values +needs to be imported from the `gitmetrics` package and executed passing the values indicated above. **NOTE**: For detailed output, logging must be enabled as shown in the example below. @@ -44,36 +44,36 @@ indicated above. ```python3 >>> import logging >>> logging.basicConfig(level=logging.INFO) ->>> from github_analytics import collect_project_metrics +>>> from gitmetrics import collect_project_metrics >>> repositories = ['sdv-dev/RDT', 'sdv-dev/SDV', 'sdv-dev/Copulas', 'sdv-dev/CTGAN'] >>> output_name = 'sdv-dev' >>> token = '' >>> collect_project_metrics(token, repositories, output_name) -INFO:github_analytics.main:Getting information for repository sdv-dev/RDT +INFO:gitmetrics.main:Getting information for repository sdv-dev/RDT 100%|███████████████████████████████████████████████████████████████| 143/143 [00:00<00:00, 195.00it/s] 100%|███████████████████████████████████████████████████████████████| 182/182 [00:00<00:00, 364.64it/s] 100%|███████████████████████████████████████████████████████████████| 37/37 [00:00<00:00, 91020.09it/s] -INFO:github_analytics.main:Getting information for repository sdv-dev/SDV +INFO:gitmetrics.main:Getting information for repository sdv-dev/SDV 100%|███████████████████████████████████████████████████████████████| 389/389 [00:02<00:00, 193.20it/s] 100%|███████████████████████████████████████████████████████████████| 219/219 [00:00<00:00, 231.17it/s] 100%|███████████████████████████████████████████████████████████████| 561/561 [00:03<00:00, 158.39it/s] -INFO:github_analytics.main:Getting information for repository sdv-dev/Copulas +INFO:gitmetrics.main:Getting information for repository sdv-dev/Copulas 100%|███████████████████████████████████████████████████████████████| 138/138 [00:00<00:00, 333.27it/s] 100%|███████████████████████████████████████████████████████████████| 143/143 [00:00<00:00, 287.29it/s] 100%|███████████████████████████████████████████████████████████████| 245/245 [00:01<00:00, 204.88it/s] -INFO:github_analytics.main:Getting information for repository sdv-dev/CTGAN +INFO:gitmetrics.main:Getting information for repository sdv-dev/CTGAN 100%|███████████████████████████████████████████████████████████████| 113/113 [00:00<00:00, 287.26it/s] 100%|██████████████████████████████████████████████████████████████| 64/64 [00:00<00:00, 134824.44it/s] 100%|███████████████████████████████████████████████████████████████| 498/498 [00:02<00:00, 171.11it/s] -INFO:github_analytics.main:Getting 164 missing users +INFO:gitmetrics.main:Getting 164 missing users 99%|██████████████████████████████████████████████████████████████▌| 163/164 [00:01<00:00, 121.99it/s] -INFO:github_analytics.output:Creating file github-metrics-sdv-dev-2021-11-12.xlsx +INFO:gitmetrics.output:Creating file github-metrics-sdv-dev-2021-11-12.xlsx ``` ## Command Line Interface -In order to run the collection script from the command line, the `github-analytics collect` command +In order to run the collection script from the command line, the `gitmetrics collect` command must be called passing the following optional arguments: - `-c / --config-file CONFIG_FILE`: Path to the config file to use. Defaults to `config.yaml`. @@ -91,13 +91,13 @@ must be called passing the following optional arguments: spreadsheet. - `-n / --not-incremental`: If indicated, collect data from scratch instead of doing it incrementally over the existing data. -- `-t / --token`: Github token to use. If not given, it will be requested in a prompt. +- `-t / --token`: GitHub token to use. If not given, it will be requested in a prompt. - `-l / --logfile LOGFILE`: Write logs to the indicated logfile. - `-v / --verbose`: Be more verbose. ```bash -$ github-analytics github -p sdv-dev -c config.yaml -Please input your Github Token: +$ gitmetrics github -p sdv-dev -c config.yaml +Please input your GitHub Token: 2021-11-12 15:42:43,100 - INFO - Getting information for repository sdv-dev/RDT 100%|███████████████████████████████████████████████████████████████| 143/143 [00:00<00:00, 300.87it/s] 100%|███████████████████████████████████████████████████████████████| 182/182 [00:00<00:00, 324.25it/s] @@ -144,7 +144,7 @@ aggregation metrics for the entire project. ## Google Drive Integration -Github Analytics is capable of reading and writing results in Google Spreadsheets. +GitMetrics is capable of reading and writing results in Google Spreadsheets. For this to work, the following things are required: @@ -156,11 +156,11 @@ For this to work, the following things are required: the corresponding `settings.yaml` file, or passed via the `PYDRIVE_CREDENTIALS` environment variable. -# Github Analytics Configuration +# GitMetrics Configuration -The Github Analytics script can be configured using a YAML file that indicates which repositories +The GitMetrics script can be configured using a YAML file that indicates which repositories to collect and where to store the collected data, as well as when to execute the collection -of data using Github Actions. +of data using GitHub Actions. For more details about how to configure this, check the [CONFIGURATION.md](CONFIGURATION.md) document. diff --git a/github_analytics/__init__.py b/github_analytics/__init__.py deleted file mode 100644 index 5507ac6..0000000 --- a/github_analytics/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Scripts to extract multiple metrics from github projects.""" - -from github_analytics.main import collect_project_metrics, collect_projects - -__all__ = ['collect_project_metrics', 'collect_projects'] diff --git a/github_analytics/github/__init__.py b/github_analytics/github/__init__.py deleted file mode 100644 index 421e694..0000000 --- a/github_analytics/github/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Classes and functions to extract stats from Github.""" diff --git a/gitmetrics/__init__.py b/gitmetrics/__init__.py new file mode 100644 index 0000000..ce70a28 --- /dev/null +++ b/gitmetrics/__init__.py @@ -0,0 +1,5 @@ +"""Scripts to extract multiple metrics from GitHub projects.""" + +from gitmetrics.main import collect_project_metrics, collect_projects + +__all__ = ['collect_project_metrics', 'collect_projects'] diff --git a/github_analytics/__main__.py b/gitmetrics/__main__.py similarity index 92% rename from github_analytics/__main__.py rename to gitmetrics/__main__.py index 9d19bfe..8634469 100644 --- a/github_analytics/__main__.py +++ b/gitmetrics/__main__.py @@ -1,4 +1,4 @@ -"""Github Analytics CLI.""" +"""GitMetrics CLI.""" import argparse import logging @@ -9,9 +9,9 @@ import yaml -from github_analytics.consolidate import consolidate_metrics -from github_analytics.main import collect_projects, collect_traffic -from github_analytics.summarize import summarize_metrics +from gitmetrics.consolidate import consolidate_metrics +from gitmetrics.main import collect_projects, collect_traffic +from gitmetrics.summarize import summarize_metrics LOGGER = logging.getLogger(__name__) @@ -22,7 +22,7 @@ def _env_setup(logfile, verbosity): format_ = '%(asctime)s - %(levelname)s - %(message)s' level = (3 - verbosity) * 10 logging.basicConfig(filename=logfile, level=level, format=format_) - logging.getLogger('github_analytics').setLevel(level) + logging.getLogger('gitmetrics').setLevel(level) logging.getLogger().setLevel(logging.WARN) @@ -53,7 +53,7 @@ def _load_config(config_path): def _collect(args, parser): token = args.token or os.getenv('GITHUB_TOKEN') if token is None: - token = input('Please input your Github Token: ') + token = input('Please input your GitHub Token: ') config = _load_config(args.config_file) config_projects = config['projects'] @@ -93,7 +93,7 @@ def _collect(args, parser): def _traffic_collection(args, parser): token = args.token or os.getenv('GITHUB_TOKEN') if token is None: - token = input('Please input your Github Token: ') + token = input('Please input your GitHub Token: ') config = _load_config(args.config_file) config_projects = config['projects'] @@ -169,8 +169,8 @@ def _get_parser(): ) parser = argparse.ArgumentParser( - prog='github-analytics', - description='Github Analytics Command Line Interface', + prog='gitmetrics', + description='GitMetrics Command Line Interface', parents=[logging_args], ) parser.set_defaults(action=None) @@ -188,7 +188,7 @@ def _get_parser(): required=False, help='Output folder path. Defaults to output folder in config-file.', ) - collect.add_argument('-t', '--token', type=str, required=False, help='Github Token to use.') + collect.add_argument('-t', '--token', type=str, required=False, help='GitHub Token to use.') collect.add_argument( '-p', '--projects', @@ -249,7 +249,7 @@ def _get_parser(): ) traffic.set_defaults(action=_traffic_collection) - traffic.add_argument('-t', '--token', type=str, required=False, help='Github Token to use.') + traffic.add_argument('-t', '--token', type=str, required=False, help='GitHub Token to use.') traffic.add_argument( '-c', '--config-file', @@ -271,7 +271,7 @@ def _get_parser(): # Summarize summarize = action.add_parser( - 'summarize', help='Summarize the github analytics information.', parents=[logging_args] + 'summarize', help='Summarize the GitMetrics information.', parents=[logging_args] ) summarize.set_defaults(action=_summarize) summarize.add_argument( @@ -298,7 +298,7 @@ def _get_parser(): def main(): - """Run the Github Analytics CLI.""" + """Run the GitMetrics CLI.""" parser = _get_parser() if len(sys.argv) < 2: parser.print_help() diff --git a/github_analytics/consolidate.py b/gitmetrics/consolidate.py similarity index 94% rename from github_analytics/consolidate.py rename to gitmetrics/consolidate.py index 1bdf68a..6289e79 100644 --- a/github_analytics/consolidate.py +++ b/gitmetrics/consolidate.py @@ -6,13 +6,13 @@ import pandas as pd from tqdm import tqdm -from github_analytics.constants import ( +from gitmetrics.constants import ( ECOSYSTEM_COLUMN_NAME, METRIC_COLUMN_NAME, METRICS_SHEET_NAME, VALUE_COLUMN_NAME, ) -from github_analytics.output import create_spreadsheet, load_spreadsheet +from gitmetrics.output import create_spreadsheet, load_spreadsheet OUTPUT_FILENAME = 'Consolidated_Overview' SHEET_NAME = 'Overview' diff --git a/github_analytics/constants.py b/gitmetrics/constants.py similarity index 100% rename from github_analytics/constants.py rename to gitmetrics/constants.py diff --git a/github_analytics/drive.py b/gitmetrics/drive.py similarity index 100% rename from github_analytics/drive.py rename to gitmetrics/drive.py diff --git a/gitmetrics/github/__init__.py b/gitmetrics/github/__init__.py new file mode 100644 index 0000000..7220fb9 --- /dev/null +++ b/gitmetrics/github/__init__.py @@ -0,0 +1 @@ +"""Classes and functions to extract stats from GitHub.""" diff --git a/github_analytics/github/client.py b/gitmetrics/github/client.py similarity index 98% rename from github_analytics/github/client.py rename to gitmetrics/github/client.py index a43e2cb..7de53bf 100644 --- a/github_analytics/github/client.py +++ b/gitmetrics/github/client.py @@ -27,11 +27,11 @@ class GQLClient: - """Generic Github API v4 client that handles pagination. + """Generic GitHub API v4 client that handles pagination. Args: token (str): - Github token to use. + GitHub token to use. """ def __init__(self, token, quiet): diff --git a/github_analytics/github/repository.py b/gitmetrics/github/repository.py similarity index 98% rename from github_analytics/github/repository.py rename to gitmetrics/github/repository.py index 710ea87..939ccf6 100644 --- a/github_analytics/github/repository.py +++ b/gitmetrics/github/repository.py @@ -2,8 +2,8 @@ import pandas as pd -from github_analytics.github.client import GQLClient -from github_analytics.utils import to_utc +from gitmetrics.github.client import GQLClient +from gitmetrics.utils import to_utc REPO_ENVELOPE = """ {{ diff --git a/github_analytics/github/repository_owner.py b/gitmetrics/github/repository_owner.py similarity index 96% rename from github_analytics/github/repository_owner.py rename to gitmetrics/github/repository_owner.py index 30d812c..506e611 100644 --- a/github_analytics/github/repository_owner.py +++ b/gitmetrics/github/repository_owner.py @@ -1,6 +1,6 @@ """GQLClient subclass specialized in repository_owner-related queries.""" -from github_analytics.github.client import GQLClient +from gitmetrics.github.client import GQLClient REPOSITORIES = """ {{ diff --git a/github_analytics/github/traffic.py b/gitmetrics/github/traffic.py similarity index 100% rename from github_analytics/github/traffic.py rename to gitmetrics/github/traffic.py diff --git a/github_analytics/github/users.py b/gitmetrics/github/users.py similarity index 96% rename from github_analytics/github/users.py rename to gitmetrics/github/users.py index 02d8eaa..6e67aac 100644 --- a/github_analytics/github/users.py +++ b/gitmetrics/github/users.py @@ -5,8 +5,8 @@ import pandas as pd from tqdm.auto import tqdm -from github_analytics.github.client import GQLClient -from github_analytics.utils import to_utc +from gitmetrics.github.client import GQLClient +from gitmetrics.utils import to_utc LOGGER = logging.getLogger(__name__) diff --git a/github_analytics/main.py b/gitmetrics/main.py similarity index 94% rename from github_analytics/main.py rename to gitmetrics/main.py index 89d1ebc..247da31 100644 --- a/github_analytics/main.py +++ b/gitmetrics/main.py @@ -6,14 +6,14 @@ import pandas as pd -from github_analytics.constants import METRICS_SHEET_NAME -from github_analytics.drive import get_or_create_gdrive_folder -from github_analytics.github.repository import RepositoryClient -from github_analytics.github.repository_owner import RepositoryOwnerClient -from github_analytics.github.traffic import TrafficClient -from github_analytics.github.users import UsersClient -from github_analytics.metrics import compute_metrics -from github_analytics.output import create_spreadsheet, load_spreadsheet +from gitmetrics.constants import METRICS_SHEET_NAME +from gitmetrics.drive import get_or_create_gdrive_folder +from gitmetrics.github.repository import RepositoryClient +from gitmetrics.github.repository_owner import RepositoryOwnerClient +from gitmetrics.github.traffic import TrafficClient +from gitmetrics.github.users import UsersClient +from gitmetrics.metrics import compute_metrics +from gitmetrics.output import create_spreadsheet, load_spreadsheet LOGGER = logging.getLogger(__name__) @@ -158,11 +158,11 @@ def collect_project_metrics( incremental=True, add_metrics=False, ): - """Pull data from Github to create metrics. + """Pull data from GitHub to create metrics. Args: token (str): - Github token to use. + GitHub token to use. repositories (list[str]): List of repositories to analyze, passed as ``{org_name}/{repo_name}`` output_path (str): @@ -244,7 +244,7 @@ def collect_projects( Args: token (str): - Github token to use. + GitHub token to use. projects (dict[str, List[str]]): Projects to collect, passed as a dict of project names and lists of repositories. @@ -275,7 +275,7 @@ def collect_traffic(token, projects, output_folder): Args: token (str): - Github token to use. + GitHub token to use. projects (dict[str, List[str]]): Projects to collect, passed as a dict of project names and lists of repositories. diff --git a/github_analytics/metrics.py b/gitmetrics/metrics.py similarity index 97% rename from github_analytics/metrics.py rename to gitmetrics/metrics.py index 16ba62b..813e719 100644 --- a/github_analytics/metrics.py +++ b/gitmetrics/metrics.py @@ -2,7 +2,7 @@ import pandas as pd -from github_analytics.constants import METRIC_COLUMN_NAME, VALUE_COLUMN_NAME +from gitmetrics.constants import METRIC_COLUMN_NAME, VALUE_COLUMN_NAME def compute_metrics(issues, pull_requests, users, contributors, stargazers): diff --git a/github_analytics/output.py b/gitmetrics/output.py similarity index 97% rename from github_analytics/output.py rename to gitmetrics/output.py index 8167a1f..93b50b6 100644 --- a/github_analytics/output.py +++ b/gitmetrics/output.py @@ -6,7 +6,7 @@ import pandas as pd -from github_analytics import drive +from gitmetrics import drive LOGGER = logging.getLogger(__name__) @@ -75,7 +75,7 @@ def create_spreadsheet(output_path, sheets): def load_spreadsheet(spreadsheet, sheet_name=None): - """Load a spreadsheet previously created by github-analytics. + """Load a spreadsheet previously created by gitmetrics. Args: spreadsheet (str or stream): diff --git a/github_analytics/slack_utils.py b/gitmetrics/slack_utils.py similarity index 92% rename from github_analytics/slack_utils.py rename to gitmetrics/slack_utils.py index ed0ef56..3765d13 100644 --- a/github_analytics/slack_utils.py +++ b/gitmetrics/slack_utils.py @@ -5,7 +5,7 @@ from slack_sdk import WebClient -GITHUB_URL_PREFIX = 'https://github.com/datacebo/github-analytics/actions/runs/' +GITHUB_URL_PREFIX = 'https://github.com/datacebo/gitmetrics/actions/runs/' DEFAULT_SLACK_CHANNEL = 'sdv-alerts-debug' @@ -72,13 +72,13 @@ def post_slack_message_in_thread(channel, text, thread_ts): def send_alert(args): """Send an alert message to a slack channel.""" url = GITHUB_URL_PREFIX + args.run_id - message = f'Github Analytics build failed :fire: :dumpster-fire: :fire: See errors <{url}|here>' + message = f'GitMetrics build failed :fire: :dumpster-fire: :fire: See errors <{url}|here>' post_slack_message(args.channel, message) def get_parser(): """Get the parser.""" - parser = argparse.ArgumentParser(description='Function to alert when a Github workflow fails.') + parser = argparse.ArgumentParser(description='Function to alert when a GitHub workflow fails.') parser.add_argument('-r', '--run-id', type=str, help='The id of the github run.') parser.add_argument( '-c', diff --git a/github_analytics/summarize.py b/gitmetrics/summarize.py similarity index 93% rename from github_analytics/summarize.py rename to gitmetrics/summarize.py index ac98929..a138238 100644 --- a/github_analytics/summarize.py +++ b/gitmetrics/summarize.py @@ -1,13 +1,13 @@ -"""Summarize GitHub Analytics.""" +"""Summarize GitMetrics.""" import logging import os import pandas as pd -from github_analytics.constants import ECOSYSTEM_COLUMN_NAME -from github_analytics.output import create_spreadsheet, load_spreadsheet -from github_analytics.time_utils import get_current_year, get_min_max_dt_in_year +from gitmetrics.constants import ECOSYSTEM_COLUMN_NAME +from gitmetrics.output import create_spreadsheet, load_spreadsheet +from gitmetrics.time_utils import get_current_year, get_min_max_dt_in_year dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -37,7 +37,7 @@ def summarize_metrics( dry_run=False, verbose=False, ): - """Summarize GitHub analytics. + """Summarize GitMetrics. Args: projects (dict[str, str | list[str]]): diff --git a/github_analytics/time_utils.py b/gitmetrics/time_utils.py similarity index 100% rename from github_analytics/time_utils.py rename to gitmetrics/time_utils.py diff --git a/github_analytics/utils.py b/gitmetrics/utils.py similarity index 100% rename from github_analytics/utils.py rename to gitmetrics/utils.py diff --git a/pyproject.toml b/pyproject.toml index eb5eb73..6e068ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,9 +3,9 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project] -name = "github-analytics" +name = "gitmetrics" version = "0.0.1.dev0" -description = "Scripts to extract multiple metrics from Github Projects." +description = "Scripts to extract multiple metrics from GitHub Projects." readme = "README.md" authors = [ { name = "DataCebo", email = "info@datacebo.com" } @@ -23,13 +23,13 @@ dependencies = [ ] [project.urls] -Homepage = "https://github.com/DataCebo/github-analytics" +Homepage = "https://github.com/datacebo/gitmetrics" [project.scripts] -github-analytics = "github_analytics.__main__:main" +gitmetrics = "gitmetrics.__main__:main" [tool.setuptools.packages.find] -include = ['github_analytics', 'github_analytics.*'] +include = ['gitmetrics', 'gitmetrics.*'] [project.optional-dependencies] dev = [ @@ -45,7 +45,7 @@ test = [ preview = true line-length = 100 indent-width = 4 -src = ["github_analytics"] +src = ["gitmetrics"] exclude = [ "docs", ".tox", @@ -91,7 +91,7 @@ docstring-code-format = true docstring-code-line-length = "dynamic" [tool.ruff.lint.isort] -known-first-party = ["github_analytics"] +known-first-party = ["gitmetrics"] lines-between-types = 0 [tool.ruff.lint.per-file-ignores]