mirror of https://gitlab.com/bashrc2/epicyon
More descriptive variable name
parent
555c80a0a9
commit
ebfb234a3c
46
git.py
46
git.py
|
@ -14,12 +14,12 @@ def gitFormatContent(content: str) -> str:
|
||||||
""" replace html formatting, so that it's more
|
""" replace html formatting, so that it's more
|
||||||
like the original patch file
|
like the original patch file
|
||||||
"""
|
"""
|
||||||
contentStr = content.replace('<br>', '\n').replace('<br />', '\n')
|
patchStr = content.replace('<br>', '\n').replace('<br />', '\n')
|
||||||
contentStr = contentStr.replace('<p>', '').replace('</p>', '\n')
|
patchStr = patchStr.replace('<p>', '').replace('</p>', '\n')
|
||||||
contentStr = html.unescape(contentStr)
|
patchStr = html.unescape(patchStr)
|
||||||
if 'From ' in contentStr:
|
if 'From ' in patchStr:
|
||||||
contentStr = 'From ' + contentStr.split('From ', 1)[1]
|
patchStr = 'From ' + patchStr.split('From ', 1)[1]
|
||||||
return contentStr
|
return patchStr
|
||||||
|
|
||||||
|
|
||||||
def getGitProjectName(baseDir: str, nickname: str, domain: str,
|
def getGitProjectName(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -74,10 +74,10 @@ def isGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def getGitHash(contentStr: str) -> str:
|
def getGitHash(patchStr: str) -> str:
|
||||||
"""Returns the commit hash from a given patch
|
"""Returns the commit hash from a given patch
|
||||||
"""
|
"""
|
||||||
patchLines = contentStr.split('\n')
|
patchLines = patchStr.split('\n')
|
||||||
for line in patchLines:
|
for line in patchLines:
|
||||||
if line.startswith('From '):
|
if line.startswith('From '):
|
||||||
words = line.split(' ')
|
words = line.split(' ')
|
||||||
|
@ -88,22 +88,22 @@ def getGitHash(contentStr: str) -> str:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def gitAddFromHandle(contentStr: str, handle: str) -> str:
|
def gitAddFromHandle(patchStr: str, handle: str) -> str:
|
||||||
"""Adds the activitypub handle of the sender to the patch
|
"""Adds the activitypub handle of the sender to the patch
|
||||||
"""
|
"""
|
||||||
fromStr = 'AP-signed-off-by: '
|
fromStr = 'AP-signed-off-by: '
|
||||||
if fromStr in contentStr:
|
if fromStr in patchStr:
|
||||||
return contentStr
|
return patchStr
|
||||||
|
|
||||||
prevContentStr = contentStr
|
prevContentStr = patchStr
|
||||||
patchLines = prevContentStr.split('\n')
|
patchLines = prevContentStr.split('\n')
|
||||||
contentStr = ''
|
patchStr = ''
|
||||||
for line in patchLines:
|
for line in patchLines:
|
||||||
contentStr += line + '\n'
|
patchStr += line + '\n'
|
||||||
if line.startswith('From:'):
|
if line.startswith('From:'):
|
||||||
if fromStr not in contentStr:
|
if fromStr not in patchStr:
|
||||||
contentStr += fromStr + handle + '\n'
|
patchStr += fromStr + handle + '\n'
|
||||||
return contentStr
|
return patchStr
|
||||||
|
|
||||||
|
|
||||||
def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -115,9 +115,9 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
subject, content):
|
subject, content):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
contentStr = gitFormatContent(content)
|
patchStr = gitFormatContent(content)
|
||||||
|
|
||||||
patchLines = contentStr.split('\n')
|
patchLines = patchStr.split('\n')
|
||||||
patchFilename = None
|
patchFilename = None
|
||||||
projectDir = None
|
projectDir = None
|
||||||
patchesDir = \
|
patchesDir = \
|
||||||
|
@ -142,14 +142,14 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||||
break
|
break
|
||||||
if not patchFilename:
|
if not patchFilename:
|
||||||
return False
|
return False
|
||||||
contentStr = \
|
patchStr = \
|
||||||
gitAddFromHandle(contentStr, '@' + fromNickname + '@' + fromDomain)
|
gitAddFromHandle(patchStr, '@' + fromNickname + '@' + fromDomain)
|
||||||
with open(patchFilename, "w") as patchFile:
|
with open(patchFilename, "w") as patchFile:
|
||||||
patchFile.write(contentStr)
|
patchFile.write(patchStr)
|
||||||
patchNotifyFilename = \
|
patchNotifyFilename = \
|
||||||
baseDir + '/accounts/' + \
|
baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/.newPatchContent'
|
nickname + '@' + domain + '/.newPatchContent'
|
||||||
with open(patchNotifyFilename, "w") as patchFile:
|
with open(patchNotifyFilename, "w") as patchFile:
|
||||||
patchFile.write(contentStr)
|
patchFile.write(patchStr)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue