diff --git a/.github/linters/.isort.cfg b/.github/linters/.isort.cfg index f238bf7..a443079 100644 --- a/.github/linters/.isort.cfg +++ b/.github/linters/.isort.cfg @@ -1,2 +1,3 @@ [settings] profile = black +known_first_party = auth,cleanowners,env,markdown_writer diff --git a/.github/workflows/super-linter.yaml b/.github/workflows/super-linter.yaml index ad12004..477e73e 100644 --- a/.github/workflows/super-linter.yaml +++ b/.github/workflows/super-linter.yaml @@ -41,7 +41,7 @@ jobs: - name: Install dependencies run: uv sync --frozen - name: Lint Code Base - uses: super-linter/super-linter@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0 + uses: super-linter/super-linter@2da136927bd4a73596db63044b504547c62cb854 # v9.0.0 env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index aa61bf6..dc980d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN uv sync --frozen --no-dev --no-editable \ # Add a simple healthcheck to satisfy container scanners HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ - CMD python3 -c "import os,sys; sys.exit(0 if os.path.exists('/action/workspace/cleanowners.py') else 1)" + CMD ["python3", "-c", "import os,sys; sys.exit(0 if os.path.exists('/action/workspace/cleanowners.py') else 1)"] ENV PYTHONUNBUFFERED=1 ENV UV_LINK_MODE=copy diff --git a/cleanowners.py b/cleanowners.py index 815e23c..d3e9ee1 100644 --- a/cleanowners.py +++ b/cleanowners.py @@ -4,9 +4,10 @@ import re import uuid +from github import GithubException, UnknownObjectException + import auth import env -from github import GithubException, UnknownObjectException from markdown_writer import write_step_summary, write_to_markdown @@ -252,7 +253,7 @@ def main(): # pragma: no cover f" Check write permissions." ) continue - except Exception as e: # pylint: disable=broad-exception-caught + except Exception as e: # noqa: BLE001 # pylint: disable=broad-exception-caught error_message = str(e) print(f"Error: {error_message}") finally: @@ -361,9 +362,7 @@ def get_usernames_from_codeowners(codeowners_file_contents, ignore_teams=True): handle = handle.split()[0] # Identify team handles by the presence of a slash. # Ignore teams because non-org members cannot be in a team. - if ignore_teams and "/" not in handle: - usernames.append(handle) - elif not ignore_teams: + if not ignore_teams or "/" not in handle: usernames.append(handle) return usernames @@ -398,7 +397,7 @@ def commit_changes( default_branch = repo.default_branch default_branch_commit = repo.get_git_ref(f"heads/{default_branch}").object.sha front_matter = "refs/heads/" - branch_name = f"codeowners-{str(uuid.uuid4())}" + branch_name = f"codeowners-{uuid.uuid4()!s}" repo.create_git_ref(front_matter + branch_name, default_branch_commit) if create_new: repo.create_file( diff --git a/markdown_writer.py b/markdown_writer.py index be9d904..56a6d12 100644 --- a/markdown_writer.py +++ b/markdown_writer.py @@ -94,8 +94,7 @@ def write_step_summary( _write_repos_missing_codeowners(file, repos_missing_codeowners, warning_suffix) if pull_request_urls: file.write("## Pull Requests Created :link:\n") - for url in pull_request_urls: - file.write(f"- {url}\n") + file.write("".join(f"- {url}\n" for url in pull_request_urls)) file.write("\n") if error: file.write(f"## Error :x:\n\n{error}\n") diff --git a/test_cleanowners.py b/test_cleanowners.py index 2510741..2101811 100644 --- a/test_cleanowners.py +++ b/test_cleanowners.py @@ -5,6 +5,8 @@ from io import StringIO from unittest.mock import MagicMock, patch +from github import UnknownObjectException + from cleanowners import ( build_default_codeowners, cleanup_whitespace, @@ -16,7 +18,6 @@ print_stats, remove_username_from_content, ) -from github import UnknownObjectException class TestCommitChanges(unittest.TestCase):