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 e839d45 commit 8c00e8c
Show file tree
Hide file tree
Showing 28 changed files with 425 additions and 124 deletions.
15 changes: 12 additions & 3 deletions github_app_geo_project/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,21 @@ def get_github_application(config: dict[str, Any], application_name: str) -> Git


def get_github_project(
config: dict[str, Any], application: GithubApplication | str, owner: str, repository: str
config: dict[str, Any],
application: GithubApplication | str,
owner: str,
repository: str,
) -> GithubProject:
"""Get the Github Application by name."""
objects = get_github_application(config, application) if isinstance(application, str) else application

token = objects.integration.get_access_token(objects.integration.get_installation(owner, repository).id)
_LOGGER.debug("Generate token for %s/%s that expire at: %s", owner, repository, token.expires_at)
_LOGGER.debug(
"Generate token for %s/%s that expire at: %s",
owner,
repository,
token.expires_at,
)
github_application = github.Github(login_or_token=token.token)
repo = github_application.get_repo(f"{owner}/{repository}")

Expand Down Expand Up @@ -138,7 +146,8 @@ def get_configuration(

return jsonmerge.merge( # type: ignore[no-any-return]
APPLICATION_CONFIGURATION.get("profiles", {}).get(
project_custom_configuration.get("profile", APPLICATION_CONFIGURATION.get("default-profile")), {}
project_custom_configuration.get("profile", APPLICATION_CONFIGURATION.get("default-profile")),
{},
),
project_custom_configuration,
)
14 changes: 11 additions & 3 deletions github_app_geo_project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class Queue(Base):
index=True,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=sqlalchemy.sql.functions.now(), index=True
DateTime(timezone=True),
nullable=False,
server_default=sqlalchemy.sql.functions.now(),
index=True,
)
started_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=True)
finished_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=True)
Expand Down Expand Up @@ -99,10 +102,15 @@ class Output(Base):

id: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False, autoincrement=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=sqlalchemy.sql.functions.now(), index=True
DateTime(timezone=True),
nullable=False,
server_default=sqlalchemy.sql.functions.now(),
index=True,
)
status: Mapped[OutputStatus] = mapped_column(
Enum(OutputStatus, create_type=False, native_enum=False), nullable=False, index=True
Enum(OutputStatus, create_type=False, native_enum=False),
nullable=False,
index=True,
)
owner: Mapped[str] = mapped_column(Unicode, nullable=False)
repository: Mapped[str] = mapped_column(Unicode, nullable=False, index=True)
Expand Down
5 changes: 4 additions & 1 deletion github_app_geo_project/module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ def transversal_status_from_json(self, data: dict[str, Any] | None) -> _TRANSVER
try:
return generic_element(**data) # type: ignore[no-any-return]
except ValidationError:
_LOGGER.error("Invalid transversal status, try with empty transversal status: %s", data)
_LOGGER.error(
"Invalid transversal status, try with empty transversal status: %s",
data,
)
return generic_element() # type: ignore[no-any-return]
return data # type: ignore[return-value]

Expand Down
45 changes: 35 additions & 10 deletions github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def _process_error(

output_url = urllib.parse.urljoin(context.service_url, f"output/{output_id}")
issue_check.set_title(
key, f"{key}: {message} ([Error]({output_url}))" if message else f"{key} ([Error]({output_url}))"
key,
(f"{key}: {message} ([Error]({output_url}))" if message else f"{key} ([Error]({output_url}))"),
)
elif message:
issue_check.set_title(key, f"{key}: {message}")
Expand All @@ -115,10 +116,20 @@ def _process_outdated(
except github.GithubException as exception:
if exception.status == 404:
_LOGGER.debug("No SECURITY.md file in the repository")
_process_error(context, _OUTDATED, issue_check, message="No SECURITY.md file in the repository")
_process_error(
context,
_OUTDATED,
issue_check,
message="No SECURITY.md file in the repository",
)
else:
_LOGGER.exception("Error while getting SECURITY.md")
_process_error(context, _OUTDATED, issue_check, message="Error while getting SECURITY.md")
_process_error(
context,
_OUTDATED,
issue_check,
message="Error while getting SECURITY.md",
)
raise


Expand Down Expand Up @@ -203,7 +214,8 @@ async def _process_snyk_dpkg(
".github/dpkg-versions.yaml"
):
await audit_utils.dpkg(
context.module_config.get("dpkg", {}), local_config.get("dpkg", {})
context.module_config.get("dpkg", {}),
local_config.get("dpkg", {}),
)

body_md += "\n" if body_md else ""
Expand All @@ -215,7 +227,10 @@ async def _process_snyk_dpkg(
)
if diff_proc.returncode != 0:
proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check
["git", "diff"], timeout=30, capture_output=True, encoding="utf-8"
["git", "diff"],
timeout=30,
capture_output=True,
encoding="utf-8",
)
message = module_utils.ansi_proc_message(proc)
message.title = "Changes to be committed"
Expand Down Expand Up @@ -245,7 +260,10 @@ async def _process_snyk_dpkg(
_LOGGER.error("Error while create commit or pull request")
else:
if pull_request is not None:
issue_check.set_title(key, f"{key} ([Pull request]({pull_request.html_url}))")
issue_check.set_title(
key,
f"{key} ([Pull request]({pull_request.html_url}))",
)
short_message.append(f"[Pull request]({pull_request.html_url})")

else:
Expand Down Expand Up @@ -337,7 +355,9 @@ def get_actions(self, context: module.GetActionContext) -> list[module.Action[_E
if "SECURITY.md" in context.event_data.get("push", {}).get("files", []):
return [
module.Action(
priority=module.PRIORITY_CRON, data=_EventData(type="outdated"), title="outdated"
priority=module.PRIORITY_CRON,
data=_EventData(type="outdated"),
title="outdated",
)
]
results: list[module.Action[_EventData]] = []
Expand All @@ -355,7 +375,9 @@ def get_actions(self, context: module.GetActionContext) -> list[module.Action[_E
if not old_check.is_checked("outdated") and new_check.is_checked("outdated"):
results.append(
module.Action(
priority=module.PRIORITY_STANDARD, data=_EventData(type="outdated"), title="outdated"
priority=module.PRIORITY_STANDARD,
data=_EventData(type="outdated"),
title="outdated",
)
)
if not old_check.is_checked("snyk") and new_check.is_checked("snyk"):
Expand All @@ -366,7 +388,9 @@ def get_actions(self, context: module.GetActionContext) -> list[module.Action[_E
if context.event_data.get("type") == "event" and context.event_data.get("name") == "daily":
results.append(
module.Action(
priority=module.PRIORITY_CRON, data=_EventData(type="outdated"), title="outdated"
priority=module.PRIORITY_CRON,
data=_EventData(type="outdated"),
title="outdated",
)
)
snyk = True
Expand All @@ -382,7 +406,8 @@ def get_actions(self, context: module.GetActionContext) -> list[module.Action[_E
return results

async def process(
self, context: module.ProcessContext[configuration.AuditConfiguration, _EventData, _TransversalStatus]
self,
context: module.ProcessContext[configuration.AuditConfiguration, _EventData, _TransversalStatus],
) -> module.ProcessOutput[_EventData, _TransversalStatus]:
"""
Process the action.
Expand Down
45 changes: 33 additions & 12 deletions github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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 @@ -211,7 +210,10 @@ async def _install_pipenv_dependencies(
env: dict[str, str],
) -> None:
proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check
["git", "ls-files", "Pipfile", "*/Pipfile"], capture_output=True, encoding="utf-8", timeout=30
["git", "ls-files", "Pipfile", "*/Pipfile"],
capture_output=True,
encoding="utf-8",
timeout=30,
)
if proc.returncode != 0:
message = module_utils.ansi_proc_message(proc)
Expand Down Expand Up @@ -271,7 +273,10 @@ async def _install_poetry_dependencies(
[
"poetry",
"install",
*local_config.get("poetry-install-arguments", config.get("poetry-install-arguments", [])),
*local_config.get(
"poetry-install-arguments",
config.get("poetry-install-arguments", []),
),
],
env,
int(os.environ.get("GHCI_PYTHON_INSTALL_TIMEOUT", "600")),
Expand All @@ -296,7 +301,8 @@ async def _snyk_monitor(
"monitor",
f"--target-reference={branch}",
*local_config.get(
"monitor-arguments", config.get("monitor-arguments", configuration.SNYK_MONITOR_ARGUMENTS_DEFAULT)
"monitor-arguments",
config.get("monitor-arguments", configuration.SNYK_MONITOR_ARGUMENTS_DEFAULT),
),
]
local_monitor_config = local_config.get("monitor", {})
Expand Down Expand Up @@ -345,7 +351,8 @@ async def _snyk_test(
"snyk",
"test",
*local_config.get(
"test-arguments", config.get("test-arguments", configuration.SNYK_TEST_ARGUMENTS_DEFAULT)
"test-arguments",
config.get("test-arguments", configuration.SNYK_TEST_ARGUMENTS_DEFAULT),
),
]
await module_utils.run_timeout(
Expand All @@ -362,7 +369,8 @@ async def _snyk_test(
"test",
"--json",
*local_config.get(
"test-arguments", config.get("test-arguments", configuration.SNYK_TEST_ARGUMENTS_DEFAULT)
"test-arguments",
config.get("test-arguments", configuration.SNYK_TEST_ARGUMENTS_DEFAULT),
),
]
test_json_str, _, message = await module_utils.run_timeout(
Expand All @@ -382,7 +390,9 @@ async def _snyk_test(
_LOGGER.debug(message)
else:
_LOGGER.error(
"Snyk test JSON returned nothing on project %s branch %s", module_utils.get_cwd(), branch
"Snyk test JSON returned nothing on project %s branch %s",
module_utils.get_cwd(),
branch,
)

test_json = json.loads(test_json_str) if test_json_str else []
Expand Down Expand Up @@ -525,7 +535,8 @@ async def _snyk_fix(
"snyk",
"fix",
*local_config.get(
"fix-arguments", config.get("fix-arguments", configuration.SNYK_FIX_ARGUMENTS_DEFAULT)
"fix-arguments",
config.get("fix-arguments", configuration.SNYK_FIX_ARGUMENTS_DEFAULT),
),
]
fix_message, snyk_fix_success, message = await module_utils.run_timeout(
Expand All @@ -544,7 +555,12 @@ async def _snyk_fix(
await module_utils.run_timeout(
command,
env_debug,
int(os.environ.get("GHCI_SNYK_FIX_TIMEOUT", os.environ.get("GHCI_SNYK_TIMEOUT", "300"))),
int(
os.environ.get(
"GHCI_SNYK_FIX_TIMEOUT",
os.environ.get("GHCI_SNYK_TIMEOUT", "300"),
)
),
"Snyk fix (debug)",
"Error while fixing the project (debug)",
"Timeout while fixing the project (debug)",
Expand Down Expand Up @@ -633,7 +649,9 @@ def outdated_versions(


def _get_sources(
dist: str, config: configuration.DpkgConfiguration, local_config: configuration.DpkgConfiguration
dist: str,
config: configuration.DpkgConfiguration,
local_config: configuration.DpkgConfiguration,
) -> apt_repo.APTSources:
"""
Get the sources for the distribution.
Expand Down Expand Up @@ -676,7 +694,9 @@ def _get_sources(


async def _get_packages_version(
package: str, config: configuration.DpkgConfiguration, local_config: configuration.DpkgConfiguration
package: str,
config: configuration.DpkgConfiguration,
local_config: configuration.DpkgConfiguration,
) -> str | None:
"""Get the version of the package."""
global _GENERATION_TIME # pylint: disable=global-statement
Expand All @@ -695,7 +715,8 @@ async def _get_packages_version(


async def dpkg(
config: configuration.DpkgConfiguration, local_config: configuration.DpkgConfiguration
config: configuration.DpkgConfiguration,
local_config: configuration.DpkgConfiguration,
) -> None:
"""Update the version of packages in the file .github/dpkg-versions.yaml or ci/dpkg-versions.yaml."""
if not os.path.exists("ci/dpkg-versions.yaml") and not os.path.exists(".github/dpkg-versions.yaml"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def get_github_application_permissions(self) -> module.GitHubApplicationPermissi
async def process(
self,
context: module.ProcessContext[
configuration.DeleteOldWorkflowRunsConfiguration, dict[str, Any], dict[str, Any]
configuration.DeleteOldWorkflowRunsConfiguration,
dict[str, Any],
dict[str, Any],
],
) -> module.ProcessOutput[dict[str, Any], dict[str, Any]]:
"""
Expand Down
Loading

0 comments on commit 8c00e8c

Please sign in to comment.