Skip to content

Commit

Permalink
Add support that dpkg-versions.yaml is in .github
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 7, 2024
1 parent 75ab294 commit 1ef6136
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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 exception:
if exception.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)

0 comments on commit 1ef6136

Please sign in to comment.