diff --git a/git.py b/git.py index 61f51d458..c454b30a0 100644 --- a/git.py +++ b/git.py @@ -70,8 +70,26 @@ def isGitPatch(baseDir: str, nickname: str, domain: str, 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, - subject: str, content: str) -> bool: + subject: str, content: str, + fromNickname: str, fromDomain: str) -> bool: """Receive a git patch """ if not isGitPatch(baseDir, nickname, domain, @@ -105,6 +123,8 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str, break if not patchFilename: return False + contentStr = \ + gitAddFromHandle(contentStr, '@' + fromNickname + '@' + fromDomain) with open(patchFilename, "w") as patchFile: patchFile.write(contentStr) patchNotifyFilename = \ diff --git a/inbox.py b/inbox.py index baebe2b83..f689900c2 100644 --- a/inbox.py +++ b/inbox.py @@ -2048,12 +2048,19 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int, # check for incoming git patches if isinstance(postJsonObject['object'], dict): - pprint(postJsonObject) 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, postJsonObject['object']['summary'], - postJsonObject['object']['content']): + postJsonObject['object']['content'], + fromNickname, fromDomain): gitPatchNotify(baseDir, handle, postJsonObject['object']['summary'], postJsonObject['object']['content'])