diff --git a/git.py b/git.py index 3e5493adc..0a0a12ed8 100644 --- a/git.py +++ b/git.py @@ -47,7 +47,7 @@ def isGitPatch(baseDir: str, nickname: str, domain: str, """Is the given post content a git patch? """ if messageType != 'Note' and \ - messageType != 'Commit': + messageType != 'Patch': return False # must have a subject line if not subject: @@ -91,10 +91,10 @@ def getGitHash(patchStr: str) -> str: return None -def convertPostToCommit(baseDir: str, nickname: str, domain: str, - postJsonObject: {}) -> bool: +def convertPostToPatch(baseDir: str, nickname: str, domain: str, + postJsonObject: {}) -> bool: """Detects whether the given post contains a patch - and if so then converts it to a Commit ActivityPub type + and if so then converts it to a Patch ActivityPub type """ if not postJsonObject.get('object'): return False @@ -102,7 +102,7 @@ def convertPostToCommit(baseDir: str, nickname: str, domain: str, return False if not postJsonObject['object'].get('type'): return False - if postJsonObject['object']['type'] == 'Commit': + if postJsonObject['object']['type'] == 'Patch': return True if not postJsonObject['object'].get('summary'): return False @@ -120,7 +120,7 @@ def convertPostToCommit(baseDir: str, nickname: str, domain: str, commitHash = getGitHash(patchStr) if not commitHash: return False - postJsonObject['object']['type'] = 'Commit' + postJsonObject['object']['type'] = 'Patch' # add a commitedBy parameter if not postJsonObject['object'].get('committedBy'): postJsonObject['object']['committedBy'] = \ @@ -130,7 +130,10 @@ def convertPostToCommit(baseDir: str, nickname: str, domain: str, "mediaType": "text/plain", "content": patchStr } - print('Converted post to Commit type') + # remove content map + if postJsonObject['object'].get('contentMap'): + del postJsonObject['object']['contentMap'] + print('Converted post to Patch ActivityPub type') return True diff --git a/outbox.py b/outbox.py index 333206b8b..717a79714 100644 --- a/outbox.py +++ b/outbox.py @@ -188,7 +188,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str, messageJson['type'] == 'Question' or \ messageJson['type'] == 'Note' or \ messageJson['type'] == 'Article' or \ - messageJson['type'] == 'Commit' or \ + messageJson['type'] == 'Patch' or \ messageJson['type'] == 'Announce': indexes = [outboxName, "inbox"] for boxNameIndex in indexes: diff --git a/posts.py b/posts.py index ecebc8d29..89eb1e497 100644 --- a/posts.py +++ b/posts.py @@ -49,7 +49,7 @@ from auth import createBasicAuthHeader from config import getConfigParam from blocking import isBlocked from filters import isFiltered -from git import convertPostToCommit +from git import convertPostToPatch # try: # from BeautifulSoup import BeautifulSoup # except ImportError: @@ -796,9 +796,9 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int, modFile.write(newPostId + '\n') modFile.close() - # If a commit has been posted - i.e. the output from + # If a patch has been posted - i.e. the output from # git format-patch - then convert the activitypub type - convertPostToCommit(baseDir, nickname, domain, newPost) + convertPostToPatch(baseDir, nickname, domain, newPost) if schedulePost: if eventDate and eventTime: @@ -2256,7 +2256,7 @@ def isDM(postJsonObject: {}) -> bool: if not isinstance(postJsonObject['object'], dict): return False if postJsonObject['object']['type'] != 'Note' and \ - postJsonObject['object']['type'] != 'Commit' and \ + postJsonObject['object']['type'] != 'Patch' and \ postJsonObject['object']['type'] != 'Article': return False if postJsonObject['object'].get('moderationStatus'): @@ -2433,7 +2433,7 @@ def addPostStringToTimeline(postStr: str, boxname: str, # must be a "Note" or "Announce" type if ('"Note"' in postStr or '"Article"' in postStr or - '"Commit"' in postStr or + '"Patch"' in postStr or '"Announce"' in postStr or ('"Question"' in postStr and ('"Create"' in postStr or '"Update"' in postStr))):