Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support that dpkg-versions.yaml is in .github #600

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ async def _process_snyk_dpkg(
if context.module_event_data.type == "dpkg":
body_md = "Update dpkg packages"

if os.path.exists("ci/dpkg-versions.yaml"):
if os.path.exists("ci/dpkg-versions.yaml") or os.path.exists(
".github/dpkg-versions.yaml"
):
await audit_utils.dpkg(
context.module_config.get("dpkg", {}), local_config.get("dpkg", {})
)
Expand Down Expand Up @@ -422,10 +424,16 @@ async def process(

dpkg_version = None
try:
dpkg_version = repo.get_contents("ci/dpkg-versions.yaml")
dpkg_version = repo.get_contents(".github/dpkg-versions.yaml")
except github.GithubException as exception:
if exception.status == 404:
_LOGGER.debug("No dpkg-versions.yaml file in the repository")
try:
dpkg_version = repo.get_contents("ci/dpkg-versions.yaml")
except github.GithubException as exception2:
if exception2.status == 404:
_LOGGER.debug("No dpkg-versions.yaml file in the repository")
else:
raise
else:
raise
if (
Expand Down
17 changes: 11 additions & 6 deletions github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,16 @@ async def _get_packages_version(
async def dpkg(
config: configuration.DpkgConfiguration, local_config: configuration.DpkgConfiguration
) -> None:
"""Update the version of packages in the file ci/dpkg-versions.yaml."""
if not os.path.exists("ci/dpkg-versions.yaml"):
_LOGGER.warning("The file ci/dpkg-versions.yaml does not exist")

with open("ci/dpkg-versions.yaml", encoding="utf-8") as versions_file:
"""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"):
_LOGGER.warning("The file .github/dpkg-versions.yaml or ci/dpkg-versions.yaml does not exist")

dpkg_versions_filename = (
".github/dpkg-versions.yaml"
if os.path.exists(".github/dpkg-versions.yaml")
else "ci/dpkg-versions.yaml"
)
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():
Expand Down Expand Up @@ -734,5 +739,5 @@ async def dpkg(
exception,
)

with open("ci/dpkg-versions.yaml", "w", encoding="utf-8") as versions_file:
with open(dpkg_versions_filename, "w", encoding="utf-8") as versions_file:
yaml.dump(versions_config, versions_file, Dumper=yaml.SafeDumper)