Extract patch description

main
Bob Mottram 2020-05-03 13:50:01 +00:00
parent 0beeb438ca
commit dc68e2c20b
1 changed files with 17 additions and 1 deletions

18
git.py
View File

@ -91,6 +91,22 @@ def getGitHash(patchStr: str) -> str:
return None return None
def getPatchDescription(patchStr: str) -> str:
"""Returns the description from a given patch
"""
patchLines = patchStr.split('\n')
description = ''
started = False
for line in patchLines:
if started:
if line.strip() == '---':
break
description += line + '\n'
if line.startswith('Subject:'):
started = True
return description
def convertPostToPatch(baseDir: str, nickname: str, domain: str, def convertPostToPatch(baseDir: str, nickname: str, domain: str,
postJsonObject: {}) -> bool: postJsonObject: {}) -> bool:
"""Detects whether the given post contains a patch """Detects whether the given post contains a patch
@ -128,7 +144,7 @@ def convertPostToPatch(baseDir: str, nickname: str, domain: str,
postJsonObject['object']['hash'] = commitHash postJsonObject['object']['hash'] = commitHash
postJsonObject['object']['description'] = { postJsonObject['object']['description'] = {
"mediaType": "text/plain", "mediaType": "text/plain",
"content": patchStr "content": getPatchDescription(patchStr)
} }
# remove content map # remove content map
if postJsonObject['object'].get('contentMap'): if postJsonObject['object'].get('contentMap'):