forked from indymedia/epicyon
Receiving git patches via the inbox
parent
15ba6c3688
commit
ba042f4dd8
47
git.py
47
git.py
|
@ -9,8 +9,26 @@ __status__ = "Production"
|
|||
import os
|
||||
|
||||
|
||||
def extractPatch(baseDir: str, nickname: str, domain: str,
|
||||
subject: str, content: str) -> bool:
|
||||
def getGitProjectName(baseDir: str, nickname: str, domain: str,
|
||||
subject: str, content: str) -> str:
|
||||
"""Returns the project name for a git patch
|
||||
The project name should be contained within the subject line
|
||||
and should match against a list of projects which the account
|
||||
holder wants to receive
|
||||
"""
|
||||
gitProjectsFilename = \
|
||||
baseDir + '/accounts/' + nickname + '@' + domain + '/gitprojects.txt'
|
||||
if not os.path.isfile(gitProjectsFilename):
|
||||
return None
|
||||
projectName = None
|
||||
for word in subject.lower().split(' '):
|
||||
if word + '\n' in open(gitProjectsFilename).read():
|
||||
return word
|
||||
return projectName
|
||||
|
||||
|
||||
def isGitPatch(baseDir: str, nickname: str, domain: str,
|
||||
subject: str, content: str) -> bool:
|
||||
"""Is the given post content a git patch?
|
||||
"""
|
||||
# must have a subject line
|
||||
|
@ -30,17 +48,21 @@ def extractPatch(baseDir: str, nickname: str, domain: str,
|
|||
return False
|
||||
if '\n' not in content:
|
||||
return False
|
||||
gitProjectsFilename = \
|
||||
baseDir + '/accounts/' + nickname + '@' + domain + '/gitprojects.txt'
|
||||
if not os.path.isfile(gitProjectsFilename):
|
||||
return False
|
||||
projectName = None
|
||||
for word in subject.lower().split(' '):
|
||||
if word + '\n' in open(gitProjectsFilename).read():
|
||||
projectName = word
|
||||
break
|
||||
projectName = \
|
||||
getGitProjectName(baseDir, nickname, domain,
|
||||
subject, content)
|
||||
if not projectName:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def receiveGitPatch(baseDir: str, nickname: str, domain: str,
|
||||
subject: str, content: str) -> bool:
|
||||
"""Receive a git patch
|
||||
"""
|
||||
if not isGitPatch(baseDir, nickname, domain,
|
||||
subject, content):
|
||||
return False
|
||||
patchLines = content.split('\n')
|
||||
patchFilename = None
|
||||
patchDir = None
|
||||
|
@ -49,6 +71,9 @@ def extractPatch(baseDir: str, nickname: str, domain: str,
|
|||
if line.startswith('Subject:'):
|
||||
patchSubject = \
|
||||
line.replace('Subject:', '').replace('/', '|').strip()
|
||||
projectName = \
|
||||
getGitProjectName(baseDir, nickname, domain,
|
||||
subject, content)
|
||||
patchDir = \
|
||||
baseDir + '/accounts/' + nickname + '@' + domain + \
|
||||
'/patches/' + projectName
|
||||
|
|
10
inbox.py
10
inbox.py
|
@ -58,6 +58,8 @@ from webinterface import individualPostAsHtml
|
|||
from webinterface import getIconsDir
|
||||
from question import questionUpdateVotes
|
||||
from media import replaceYouTube
|
||||
from git import isGitPatch
|
||||
from git import receiveGitPatch
|
||||
|
||||
|
||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||
|
@ -1578,6 +1580,10 @@ def validPostContent(baseDir: str, nickname: str, domain: str,
|
|||
return False
|
||||
if 'Z' not in messageJson['object']['published']:
|
||||
return False
|
||||
if isGitPatch(baseDir, nickname, domain,
|
||||
messageJson['object']['summary'],
|
||||
messageJson['object']['content']):
|
||||
return True
|
||||
# check for bad html
|
||||
invalidStrings = ('<script>', '<canvas>', '<style>',
|
||||
'</html>', '</body>', '<br>', '<hr>')
|
||||
|
@ -2027,6 +2033,10 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
|
|||
nickname = handle.split('@')[0]
|
||||
if validPostContent(baseDir, nickname, domain,
|
||||
postJsonObject, maxMentions, maxEmoji):
|
||||
receiveGitPatch(baseDir, nickname, domain,
|
||||
messageJson['object']['summary'],
|
||||
messageJson['object']['content'])
|
||||
|
||||
# replace YouTube links, so they get less tracking data
|
||||
replaceYouTube(postJsonObject)
|
||||
|
||||
|
|
Loading…
Reference in New Issue