aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2019-02-11 18:00:15 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2019-02-11 18:00:15 -0500
commita86823b5df8deb6b91973f8b4858885c0883b4e6 (patch)
treeadd5cbeb0ec624632eacf19a09970d3daf32c903
parent17b87f3ed4157135272c254e27c950b0d569fed0 (diff)
downloadkorg-helpers-a86823b5df8deb6b91973f8b4858885c0883b4e6.tar.gz
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>
-rwxr-xr-xpr-tracker-bot.py25
1 files changed, 18 insertions, 7 deletions
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 @@ def git_get_commit_id_from_repo_ref(repo, ref):
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)