osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-dev/+/42902?usp=email )


Change subject: src/grd: use origin url to get get host + project
......................................................................

src/grd: use origin url to get get host + project

For most projects we can get the gerrit host and project from the git
remote URL already. Do this when a git repository has no ".gitreview"
file so it works even if the file is not present.

Change-Id: Ib2b201e5238ba7036c6121e8875ee85c73da8751
---
M src/grd
1 file changed, 28 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-dev refs/changes/02/42902/1

diff --git a/src/grd b/src/grd
index d86225d..3c0cf3f 100755
--- a/src/grd
+++ b/src/grd
@@ -28,14 +28,38 @@

 def get_config_path():
     ret = f"{get_topdir()}/.gitreview"
-    if not os.path.exists(ret):
-        print(f"ERROR: config not found: {ret}")
-        sys.exit(1)
-    return ret
+    return ret if os.path.exists(ret) else None
+
+
+def exit_gerrit_host_project_unknown():
+    print("ERROR: failed to get gerrit host and project")
+    print("Consider adding a .gitreview file:")
+    print("  [gerrit]")
+    print("  host=gerrit.osmocom.org")
+    print("  project=…")
+    sys.exit(1)
+
+
+def get_config_from_origin_url():
+    url = subprocess.run(
+        ["git", "config", "--get", "remote.origin.url"],
+        check=True,
+        capture_output=True,
+        encoding="UTF-8",
+    ).stdout.rstrip()
+
+    if not url.startswith("https://gerrit.osmocom.org/";):
+        exit_gerrit_host_project_unknown()
+
+    host = url.split("/")[2]
+    project = "/".join(url.split("/")[3:])
+    return host, project


 def get_config():
     config_path = get_config_path()
+    if not config_path:
+        return get_config_from_origin_url()
     config = configparser.ConfigParser()
     config.read(config_path)
     return config["gerrit"]["host"], config["gerrit"]["project"]

--
To view, visit https://gerrit.osmocom.org/c/osmo-dev/+/42902?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-dev
Gerrit-Branch: master
Gerrit-Change-Id: Ib2b201e5238ba7036c6121e8875ee85c73da8751
Gerrit-Change-Number: 42902
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to