Commits

Juha Komulainen committed c0185fb

Support bb:-urls in when looking up the bitbucket-repo.

  • Participants
  • Parent commits 0d21a26

Comments (0)

Files changed (1)

-#!/bin/sh
+#!/usr/bin/env python
 
-P="$(hg paths 2>/dev/null | grep 'bitbucket.org' | head -1)"
-URL="$(echo $P | sed -e's|.*\(bitbucket.org.*\)|http://\1|')"
-[[ -n $URL ]] && open $URL || echo "No BitBucket path found!"
+import subprocess, re, os, sys
+
+# TODO: get the default bitbucket user from the configuration of bb-extension
+default_user = os.getenv("USER")
+
+bitbucket_re = re.compile("^(ssh://hg@bitbucket.org/|https?://bitbucket.org/|bb://)([^/]*)/([^/]*)")
+
+def find_repository(paths):
+    for path in paths:
+        m = bitbucket_re.match(path.split(" = ")[1])
+        if m:
+            return (m.group(2), m.group(3)) if m.group(3) else (default_user, m.group(2))
+
+    return None
+
+paths = subprocess.check_output(["hg", "paths"]).split("\n")
+paths.remove("")
+
+repo = find_repository(paths)
+if repo:
+    url = "https://bitbucket.org/%s/%s" % repo
+    subprocess.call(["open", url])
+else:
+    print "No BitBucket path found!"
+    sys.exit(1)