Skip to content

Commit

Permalink
merge: Replace flatpak-builder with json-glib
Browse files Browse the repository at this point in the history
  • Loading branch information
barthalion authored and bbhtt committed Jun 17, 2024
1 parent c85708d commit 1368361
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions .github/actions/merge/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import tempfile
import time

import gi
import github
import pygit2
import yaml
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport

gi.require_version("Json", "1.0")
from gi.repository import Json


def set_protected_branch(token, repo, branch):
transport = RequestsHTTPTransport(
Expand Down Expand Up @@ -74,6 +78,7 @@ def set_protected_branch(token, repo, branch):
def detect_appid(dirname):
files = []
ret = (None, None)
appid = None

for ext in ("yml", "yaml", "json"):
files.extend(glob.glob(f"{dirname}/*.{ext}"))
Expand All @@ -86,32 +91,26 @@ def detect_appid(dirname):
with open(filename) as f:
if ext in ("yml", "yaml"):
manifest = yaml.safe_load(f)
if "app-id" in manifest:
appid = manifest["app-id"]
elif "id" in manifest:
appid = manifest["id"]
else:
result = subprocess.run(
["flatpak-builder", "--show-manifest", filename],
stdout=subprocess.PIPE,
)
if result.returncode == 0:
manifest = json.loads(result.stdout.decode("utf-8"))
else:
print(
"flatpak-builder failed to print manifest, falling back to json Python module"
)
try:
with open(filename) as f:
manifest = json.load(f)
except json.decoder.JSONDecodeError:
("Manifest is not a valid JSON")
break

if manifest:
parser = Json.Parser()
if parser.load_from_file(parser, filename):
root_node = parser.get_root()
if root_node.get_node_type() == Json.NodeType.OBJECT:
json_object = root_node.get_object()
if json_object.has_member("id"):
appid = json_object.get_string_member("id")
elif json_object.has_member("app-id"):
appid = json_object.get_string_member("app-id")

if not appid:
continue

if appid:
manifest_file = os.path.basename(filename)
if "app-id" in manifest:
appid = manifest["app-id"]
elif "id" in manifest:
appid = manifest["id"]
else:
continue
if os.path.splitext(manifest_file)[0] != appid:
print(f"Skipping {manifest_file}, does not match appid {appid}")
continue
Expand Down

0 comments on commit 1368361

Please sign in to comment.