From 555c80a0a9354a9b4273135df854a4d67ece31eb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 3 May 2020 11:38:09 +0000 Subject: [PATCH] Function for extracting commit hash --- git.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/git.py b/git.py index 452b8a738..7d7d90e23 100644 --- a/git.py +++ b/git.py @@ -74,6 +74,20 @@ def isGitPatch(baseDir: str, nickname: str, domain: str, return True +def getGitHash(contentStr: str) -> str: + """Returns the commit hash from a given patch + """ + patchLines = contentStr.split('\n') + for line in patchLines: + if line.startswith('From '): + words = line.split(' ') + if len(words) > 1: + if len(words[1]) > 20: + return words[1] + break + return None + + def gitAddFromHandle(contentStr: str, handle: str) -> str: """Adds the activitypub handle of the sender to the patch """