ActivityPub signoff added to patches

main
Bob Mottram 2020-05-03 09:48:12 +00:00
parent c233306b23
commit 5dcc60aa7c
2 changed files with 31 additions and 4 deletions

22
git.py
View File

@ -70,8 +70,26 @@ def isGitPatch(baseDir: str, nickname: str, domain: str,
return True return True
def gitAddFromHandle(contentStr: str, handle: str) -> str:
"""Adds the activitypub handle of the sender to the patch
"""
fromStr = 'AP-signed-off-by: '
if fromStr in contentStr:
return contentStr
prevContentStr = contentStr
patchLines = prevContentStr.split('\n')
contentStr = ''
for line in patchLines:
contentStr += line + '\n'
if line.startswith('From:'):
contentStr += fromStr + handle + '\n'
return contentStr
def receiveGitPatch(baseDir: str, nickname: str, domain: str, def receiveGitPatch(baseDir: str, nickname: str, domain: str,
subject: str, content: str) -> bool: subject: str, content: str,
fromNickname: str, fromDomain: str) -> bool:
"""Receive a git patch """Receive a git patch
""" """
if not isGitPatch(baseDir, nickname, domain, if not isGitPatch(baseDir, nickname, domain,
@ -105,6 +123,8 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
break break
if not patchFilename: if not patchFilename:
return False return False
contentStr = \
gitAddFromHandle(contentStr, '@' + fromNickname + '@' + fromDomain)
with open(patchFilename, "w") as patchFile: with open(patchFilename, "w") as patchFile:
patchFile.write(contentStr) patchFile.write(contentStr)
patchNotifyFilename = \ patchNotifyFilename = \

View File

@ -2048,12 +2048,19 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
# check for incoming git patches # check for incoming git patches
if isinstance(postJsonObject['object'], dict): if isinstance(postJsonObject['object'], dict):
pprint(postJsonObject)
if postJsonObject['object'].get('content') and \ if postJsonObject['object'].get('content') and \
postJsonObject['object'].get('summary'): postJsonObject['object'].get('summary') and \
postJsonObject['object'].get('attributedTo'):
attributedTo = postJsonObject['object']['attributedTo']
fromNickname = getNicknameFromActor(attributedTo)
fromDomain, fromPort = getDomainFromActor(attributedTo)
if fromPort:
if fromPort != 80 and fromPort != 443:
fromDomain += ':' + str(fromPort)
if receiveGitPatch(baseDir, nickname, domain, if receiveGitPatch(baseDir, nickname, domain,
postJsonObject['object']['summary'], postJsonObject['object']['summary'],
postJsonObject['object']['content']): postJsonObject['object']['content'],
fromNickname, fromDomain):
gitPatchNotify(baseDir, handle, gitPatchNotify(baseDir, handle,
postJsonObject['object']['summary'], postJsonObject['object']['summary'],
postJsonObject['object']['content']) postJsonObject['object']['content'])