Remove html formatting on git patches

main
Bob Mottram 2020-05-02 14:47:30 +00:00
parent 884fb86d1a
commit 0e2b1065f6
1 changed files with 11 additions and 7 deletions

18
git.py
View File

@ -10,7 +10,7 @@ import os
def getGitProjectName(baseDir: str, nickname: str, domain: str, def getGitProjectName(baseDir: str, nickname: str, domain: str,
subject: str, content: str) -> str: subject: str) -> str:
"""Returns the project name for a git patch """Returns the project name for a git patch
The project name should be contained within the subject line The project name should be contained within the subject line
and should match against a list of projects which the account and should match against a list of projects which the account
@ -46,11 +46,12 @@ def isGitPatch(baseDir: str, nickname: str, domain: str,
return False return False
if 'Subject:' not in content: if 'Subject:' not in content:
return False return False
if '\n' not in content: if '<br>' not in content:
return False if '<br />' not in content:
return False
projectName = \ projectName = \
getGitProjectName(baseDir, nickname, domain, getGitProjectName(baseDir, nickname, domain,
subject, content) subject)
if not projectName: if not projectName:
return False return False
return True return True
@ -63,7 +64,10 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
if not isGitPatch(baseDir, nickname, domain, if not isGitPatch(baseDir, nickname, domain,
subject, content): subject, content):
return False return False
patchLines = content.split('\n') contentStr = content.replace('<br>','\n').replace('<br />','\n')
contentStr = contentStr.replace('<p>','').replace('</p>','\n')
patchLines = contentStr.split('\n')
patchFilename = None patchFilename = None
patchDir = None patchDir = None
# get the subject line and turn it into a filename # get the subject line and turn it into a filename
@ -73,7 +77,7 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
line.replace('Subject:', '').replace('/', '|').strip() line.replace('Subject:', '').replace('/', '|').strip()
projectName = \ projectName = \
getGitProjectName(baseDir, nickname, domain, getGitProjectName(baseDir, nickname, domain,
subject, content) subject)
patchDir = \ patchDir = \
baseDir + '/accounts/' + nickname + '@' + domain + \ baseDir + '/accounts/' + nickname + '@' + domain + \
'/patches/' + projectName '/patches/' + projectName
@ -85,6 +89,6 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
patchFile = open(patchFilename, "w") patchFile = open(patchFilename, "w")
if not patchFile: if not patchFile:
return False return False
patchFile.write(content) patchFile.write(contentStr)
patchFile.close() patchFile.close()
return True return True