Skip to content

Commit

Permalink
Apply pre-commit fix
Browse files Browse the repository at this point in the history
From the artifact of the previous workflow run
  • Loading branch information
geo-ghci-int[bot] committed Nov 15, 2024
1 parent 63fd770 commit 221dff4
Show file tree
Hide file tree
Showing 32 changed files with 71 additions and 140 deletions.
4 changes: 1 addition & 3 deletions github_app_geo_project/application_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import Any, TypedDict

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@


def apply_profile_inheritance(profile_name: str, profiles: dict[str, Any]) -> None:
"""
Apply the inheritance of the profile.
"""
"""Apply the inheritance of the profile."""
for other_name, other_profile in APPLICATION_CONFIGURATION["profiles"].items():
if other_profile.get("inherits") == profile_name:
_LOGGER.debug("Apply inheritance %s -> %s", profile_name, other_name)
Expand Down
7 changes: 2 additions & 5 deletions github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ async def _process_snyk_dpkg(
python_version = ".".join(line.split(" ")[1].split(".")[0:2]).strip()
break

if python_version:
env = _use_python_version(python_version)
else:
env = os.environ.copy()
env = _use_python_version(python_version) if python_version else os.environ.copy()

result, body, short_message, new_success = await audit_utils.snyk(
branch,
Expand All @@ -186,7 +183,7 @@ async def _process_snyk_dpkg(
", ".join(short_message),
)
message: module_utils.Message = module_utils.HtmlMessage(
"<a href='%s'>Output</a>" % output_url
f"<a href='{output_url}'>Output</a>"
)
message.title = "Output URL"
_LOGGER.debug(message)
Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/module/audit/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import Any, Literal, TypedDict, Union

Expand Down
25 changes: 9 additions & 16 deletions github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
The auditing functions.
"""
"""The auditing functions."""

import asyncio
import datetime
Expand Down Expand Up @@ -128,7 +126,6 @@ async def _select_java_version(
local_config: configuration.SnykConfiguration,
env: dict[str, str],
) -> None:

if not os.path.exists("gradlew"):
return

Expand Down Expand Up @@ -607,9 +604,7 @@ async def _npm_audit_fix(
def outdated_versions(
security: security_md.Security,
) -> list[str | models.OutputData]:
"""
Check that the versions from the SECURITY.md are not outdated.
"""
"""Check that the versions from the SECURITY.md are not outdated."""
version_index = security.headers.index("Version")
date_index = security.headers.index("Supported Until")

Expand All @@ -635,9 +630,7 @@ def outdated_versions(
def _get_sources(
dist: str, config: configuration.DpkgConfiguration, local_config: configuration.DpkgConfiguration
) -> apt_repo.APTSources:
"""
Get the sources for the distribution.
"""
"""Get the sources for the distribution."""
if dist not in _SOURCES:
conf = local_config.get("sources", config.get("sources", configuration.DPKG_SOURCES_DEFAULT))
if dist not in conf:
Expand All @@ -657,9 +650,7 @@ def _get_sources(
name = f"{dist}/{package.package}"
try:
version = debian_inspector.version.Version.from_string(package.version)
if name not in _PACKAGE_VERSION:
_PACKAGE_VERSION[name] = version
elif version > _PACKAGE_VERSION[name]:
if name not in _PACKAGE_VERSION or version > _PACKAGE_VERSION[name]:
_PACKAGE_VERSION[name] = version
except ValueError as exception:
_LOGGER.warning(
Expand All @@ -680,8 +671,10 @@ async def _get_packages_version(
) -> str | None:
"""Get the version of the package."""
global _GENERATION_TIME # pylint: disable=global-statement
if _GENERATION_TIME is None or _GENERATION_TIME < datetime.datetime.now() - utils.parse_duration(
os.environ.get("GHCI_DPKG_CACHE_DURATION", "3h")
if (
_GENERATION_TIME is None
or datetime.datetime.now() - utils.parse_duration(os.environ.get("GHCI_DPKG_CACHE_DURATION", "3h"))
> _GENERATION_TIME
):
_PACKAGE_VERSION.clear()
_SOURCES.clear()
Expand Down Expand Up @@ -709,7 +702,7 @@ async def dpkg(
with open(dpkg_versions_filename, encoding="utf-8") as versions_file:
versions_config = yaml.load(versions_file, Loader=yaml.SafeLoader)
for versions in versions_config.values():
for package_full in versions.keys():
for package_full in versions:
version = await _get_packages_version(package_full, config, local_config)
if version is None:
_LOGGER.warning("No version found for %s", package_full)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import TypedDict

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/module/modules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Module registry.
"""
"""Module registry."""

import logging
from typing import Any
Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/module/pull_request/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
The modules related to the pull request.
"""
"""The modules related to the pull request."""
4 changes: 1 addition & 3 deletions github_app_geo_project/module/pull_request/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def _get_code_spell_command(
],
ignore_file: NamedTemporaryFileStr,
) -> list[str]:
"""
Get the codespell command.
"""
"""Get the codespell command."""
config = context.module_config
code_spell_config = config.get("codespell", {})
code_spell_config = code_spell_config if isinstance(code_spell_config, dict) else {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import TypedDict, Union

Expand Down
2 changes: 1 addition & 1 deletion github_app_geo_project/module/pull_request/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import github
import github.PullRequest

from github_app_geo_project import configuration, module
from github_app_geo_project import module
from github_app_geo_project.module.pull_request import links_configuration


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import TypedDict

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/module/standard/auto_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import TypedDict

Expand Down
19 changes: 5 additions & 14 deletions github_app_geo_project/module/standard/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,12 @@ def match(item: ChangelogItem, condition: Condition) -> bool:

def match_and(item: ChangelogItem, condition: changelog_configuration.ConditionAndSolidusOr) -> bool:
"""Match all the conditions."""
for cond in condition["conditions"]:
if not match(item, cond):
return False
return True
return all(match(item, cond) for cond in condition["conditions"])


def match_or(item: ChangelogItem, condition: changelog_configuration.ConditionAndSolidusOr) -> bool:
"""Match any of the conditions."""
for cond in condition["conditions"]:
if match(item, cond):
return True
return False
return any(match(item, cond) for cond in condition["conditions"])


def match_not(item: ChangelogItem, condition: changelog_configuration.ConditionNot) -> bool:
Expand All @@ -131,10 +125,7 @@ def match_title(item: ChangelogItem, condition: changelog_configuration.Conditio
def match_files(item: ChangelogItem, condition: changelog_configuration.ConditionFiles) -> bool:
"""Match all the files of the pull request."""
file_re = re.compile("|".join(condition["regex"]))
for file_name in item.files:
if file_re.match(file_name) is None:
return False
return True
return all(file_re.match(file_name) is not None for file_name in item.files)


def match_label(item: ChangelogItem, condition: changelog_configuration.ConditionLabel) -> bool:
Expand Down Expand Up @@ -255,7 +246,7 @@ def _previous_tag(tag: Tag, tags: dict[Tag, Tag]) -> Tag | None:
return _previous_tag(test_tag, tags)
if tag.major != 0:
# Get previous version
tags_list = sorted([t for t in tags.keys() if t.major < tag.major])
tags_list = sorted([t for t in tags if t.major < tag.major])
if not tags_list:
return None
previous_major_minor = tags_list[-1]
Expand All @@ -264,7 +255,7 @@ def _previous_tag(tag: Tag, tags: dict[Tag, Tag]) -> Tag | None:
tags_list = sorted(
[
t
for t in tags.keys()
for t in tags
if t.major == previous_major_minor.major and t.minor == previous_major_minor.minor
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import Literal, TypedDict, Union

Expand Down
10 changes: 6 additions & 4 deletions github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import shlex
import subprocess # nosec
from typing import Any, Union, cast
from typing import Any, cast

import github
import html_sanitizer
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, title: str, comment: str = "", checked: bool | None = None) -
self.checked = checked


DashboardIssueRaw = list[Union[DashboardIssueItem, str]]
DashboardIssueRaw = list[DashboardIssueItem | str]

_CHECK_RE = re.compile(r"- \[([ x])\] (.*)")
_COMMENT_RE = re.compile(r"^(.*)<!--(.*)-->(.*)$")
Expand Down Expand Up @@ -643,7 +643,8 @@ def create_pull_request(
body = f"See: #{pull_request.number}"
found = False
issues = project.repo.get_issues(
state="open", creator=project.application.integration.get_app().slug + "[bot]" # type: ignore[arg-type]
state="open",
creator=project.application.integration.get_app().slug + "[bot]", # type: ignore[arg-type]
)
if issues.totalCount > 0:
for candidate in issues:
Expand Down Expand Up @@ -707,7 +708,8 @@ def close_pull_request_issues(new_branch: str, message: str, project: configurat

title = f"Pull request {message} is open for 5 days"
issues = project.repo.get_issues(
state="open", creator=project.application.integration.get_app().slug + "[bot]" # type: ignore[arg-type]
state="open",
creator=project.application.integration.get_app().slug + "[bot]", # type: ignore[arg-type]
)
for issue in issues:
if title == issue.title:
Expand Down
5 changes: 2 additions & 3 deletions github_app_geo_project/module/versions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,8 @@ def _get_names(
names = names_by_datasource.setdefault("pypi", _TransversalStatusNameByDatasource()).names
for line in file:
match = re.match(r'^ *name ?= ?[\'"](.*)[\'"],?$', line)
if match:
if match.group(1) not in names:
names.append(match.group(1))
if match and match.group(1) not in names:
names.append(match.group(1))
os.environ["GITHUB_REPOSITORY"] = f"{context.github_project.owner}/{context.github_project.repository}"
data = c2cciutils.get_config()
docker_config = data.get("publish", {}).get("docker", {})
Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/module/versions/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import Any, TypedDict

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/project_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Automatically generated file from a JSON schema.
"""
"""Automatically generated file from a JSON schema."""

from typing import TypedDict

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
The scripts module.
"""
"""The scripts module."""
8 changes: 2 additions & 6 deletions github_app_geo_project/scripts/health_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Script used to check the health of the process-queue daemon.
"""
"""Script used to check the health of the process-queue daemon."""

import argparse
import os
Expand All @@ -10,9 +8,7 @@


def main() -> None:
"""
Check the health of the process-queue daemon.
"""
"""Check the health of the process-queue daemon."""
parser = argparse.ArgumentParser(description="Check the health of the process-queue daemon")
parser.add_argument("--timeout", type=int, help="Timeout in seconds")
args = parser.parse_args()
Expand Down
11 changes: 5 additions & 6 deletions github_app_geo_project/scripts/process_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Process the jobs present in the database queue.
"""
"""Process the jobs present in the database queue."""

import argparse
import asyncio
Expand All @@ -23,7 +21,7 @@
import prometheus_client.exposition
import sentry_sdk
import sqlalchemy.orm
from prometheus_client import Gauge, Info
from prometheus_client import Gauge

from github_app_geo_project import configuration, models, module, project_configuration, utils
from github_app_geo_project.module import modules
Expand Down Expand Up @@ -102,7 +100,7 @@ def _validate_job(config: dict[str, Any], application: str, event_data: dict[str
github_application = configuration.get_github_application(config, application)
github_app = github_application.integration.get_app()
installation_id = event_data.get("installation", {}).get("id", 0)
if not github_app.id != installation_id:
if github_app.id == installation_id:
_LOGGER.error("Invalid installation id %i != %i", github_app.id, installation_id)
return False
return True
Expand Down Expand Up @@ -510,7 +508,8 @@ def _get_dashboard_issue(
github_application: configuration.GithubApplication, repo: github.Repository.Repository
) -> github.Issue.Issue | None:
open_issues = repo.get_issues(
state="open", creator=github_application.integration.get_app().slug + "[bot]" # type: ignore[arg-type]
state="open",
creator=github_application.integration.get_app().slug + "[bot]", # type: ignore[arg-type]
)
if open_issues.totalCount > 0:
for candidate in open_issues:
Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/scripts/send_event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Send an event in the database queue.
"""
"""Send an event in the database queue."""

import argparse

Expand Down
2 changes: 1 addition & 1 deletion github_app_geo_project/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def identity(self, request: pyramid.request.Request) -> User:
else:
user = User("anonymous", None, None, None, False, None, request)

setattr(request, "user", user)
request.user = user

return request.user # type: ignore

Expand Down
4 changes: 1 addition & 3 deletions github_app_geo_project/static/favicon_color.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Used to generate different color favicons for the website.
"""
"""Used to generate different color favicons for the website."""

import cv2 # pylint: disable=import-error

Expand Down
Loading

0 comments on commit 221dff4

Please sign in to comment.