Look up shortname refs in proper order

We were not using proper order when looking up remote refs, for details
see this thread:

https://lore.kernel.org/lkml/CAHk-=wg9yvP3hGVRSnc=8qoj0g7_zt=_2FjmgSAu-0DViyFtaw@mail.gmail.com

This fix changes the order to properly match heads and be more correct
when handling shortnames in general.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
diff --git a/pr-tracker-bot.py b/pr-tracker-bot.py
index 4ee0854..b58cacb 100755
--- a/pr-tracker-bot.py
+++ b/pr-tracker-bot.py
@@ -196,14 +196,25 @@
         return None
 
     logger.debug('getting commit-id from: %s %s', repo, ref)
-    lines = git_get_command_lines(None, ['ls-remote', repo, '%s^{}' % ref])
-    if not lines:
-        # Try it as a head
-        lines = git_get_command_lines(None, ['ls-remote', repo, ref])
+    # Is it a full ref name or a shortname?
+    if ref.find('refs/heads/') < 0 and ref.find('refs/tags/') < 0:
+        # Try grabbing it as a head first
+        lines = git_get_command_lines(None, ['ls-remote', repo, 'refs/heads/%s' % ref])
         if not lines:
-            # Oh well, we tried
-            logger.debug('did not find commit-id, ignoring pull request')
-            return None
+            # try it as a tag, then
+            lines = git_get_command_lines(None, ['ls-remote', repo, 'refs/tags/%s^{}' % ref])
+
+    elif ref.find('refs/tags/') == 0:
+        lines = git_get_command_lines(None, ['ls-remote', repo, '%s^{}' % ref])
+
+    else:
+        # Grab it as a head and hope for the best
+        lines = git_get_command_lines(None, ['ls-remote', repo, ref])
+
+    if not lines:
+        # Oh well, we tried
+        logger.debug('did not find commit-id, ignoring pull request')
+        return None
 
     commit_id = lines[0].split()[0]
     logger.debug('success, commit-id: %s', commit_id)