diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 431c4f3..200a9e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,45 +10,45 @@ # repos: # Autoformat: Python code - - repo: https://github.com/ambv/black - rev: 23.1.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: f0fe93c067104b76ffb58852abe79673a8429bd1 # frozen: v0.11.8 hooks: - - id: black + - id: ruff + args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"] + - id: ruff-format # Autoformat: markdown, yaml - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.4 + rev: 787fb9f542b140ba0b2aced38e6a3e68021647a3 # frozen: v3.5.3 hooks: - id: prettier exclude: tests/.* - # Autoformat: https://github.com/asottile/reorder_python_imports - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.9.0 - hooks: - - id: reorder-python-imports - # Misc... - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # v6.0.0 # ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available hooks: - # Autoformat: Makes sure files end in a newline and only a newline. - - id: end-of-file-fixer - exclude: tests/.* - - # Autoformat: Sorts entries in requirements.txt. - - id: requirements-txt-fixer - - # Lint: Check for files with names that would conflict on a - # case-insensitive filesystem like MacOS HFS+ or Windows FAT. + # Sanity checks + - id: check-added-large-files - id: check-case-conflict - - # Lint: Checks that non-binary executables have a proper shebang. - id: check-executables-have-shebangs + - id: check-illegal-windows-names + - id: check-merge-conflict - # Lint: Python code - - repo: https://github.com/pycqa/flake8 - rev: "6.0.0" - hooks: - - id: flake8 + # Checks based on file type + - id: check-toml + - id: check-yaml + + # Detect mistakes + - id: debug-statements + - id: detect-private-key + - id: forbid-submodules + + # Automatic fixes + - id: mixed-line-ending + args: [--fix=lf] + - id: trailing-whitespace + - id: requirements-txt-fixer + - id: end-of-file-fixer + exclude: tests/.* diff --git a/github_activity/__init__.py b/github_activity/__init__.py index 2129abb..9146340 100644 --- a/github_activity/__init__.py +++ b/github_activity/__init__.py @@ -1,3 +1,4 @@ __version__ = "1.0.3" +__all__ = ["get_activity", "generate_activity_md"] from .github_activity import get_activity, generate_activity_md diff --git a/github_activity/github_activity.py b/github_activity/github_activity.py index 535ac33..912b89e 100644 --- a/github_activity/github_activity.py +++ b/github_activity/github_activity.py @@ -1,4 +1,5 @@ """Use the GraphQL api to grab issues/PRs that match a query.""" + import dataclasses import datetime import fnmatch @@ -7,10 +8,8 @@ import shlex import subprocess import sys -import urllib from collections import OrderedDict from json import loads -from pathlib import Path from subprocess import CalledProcessError from subprocess import PIPE from subprocess import run @@ -567,8 +566,6 @@ def filter_ignored(userlist): return # Separate into closed and opened - until_dt_str = data.until_dt_str - since_dt_str = data.since_dt_str closed = data.query("closedAt >= @since_dt_str and closedAt <= @until_dt_str") opened = data.query("createdAt >= @since_dt_str and createdAt <= @until_dt_str") @@ -691,7 +688,7 @@ def filter_ignored(userlist): items["md"].append("") for irow, irowdata in items["data"].iterrows(): - author = irowdata["author"] + # author = irowdata["author"] ititle = irowdata["title"] if strip_brackets and ititle.strip().startswith("[") and "]" in ititle: ititle = ititle.split("]", 1)[-1].strip() @@ -855,11 +852,11 @@ def _get_datetime_and_type(org, repo, datetime_or_git_ref, auth): try: dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth) return (dt, True) - except Exception as ref_error: + except Exception: try: dt = dateutil.parser.parse(datetime_or_git_ref) return (dt, False) - except Exception as datetime_error: + except Exception: raise ValueError( "{0} not found as a ref or valid date format".format( datetime_or_git_ref diff --git a/pyproject.toml b/pyproject.toml index a6a9fbf..205086a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,3 +81,6 @@ search = 'version = "{current_version}"' [[tool.tbump.file]] src = "github_activity/__init__.py" search = '__version__ = "{current_version}"' + +[tool.ruff.lint.per-file-ignores] +"docs/conf.py" = ["E402"] diff --git a/tests/test_cli.py b/tests/test_cli.py index 4c28ce9..d993964 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,3 @@ -import os import shutil from pathlib import Path from subprocess import run @@ -126,7 +125,7 @@ def test_cli_ignore_user(tmpdir): cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -o {path_output}" run(cmd.split(), check=True) md = path_output.read_text() - assert not "@choldgraf" in md + assert "@choldgraf" not in md def test_contributor_sorting(tmpdir, file_regression):