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
|
import os
|
||||||
|
|
||||||
|
|
||||||
def extractPatch(baseDir: str, nickname: str, domain: str,
|
def getGitProjectName(baseDir: str, nickname: str, domain: str,
|
||||||
subject: str, content: str) -> bool:
|
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?
|
"""Is the given post content a git patch?
|
||||||
"""
|
"""
|
||||||
# must have a subject line
|
# must have a subject line
|
||||||
|
@ -30,17 +48,21 @@ def extractPatch(baseDir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
if '\n' not in content:
|
if '\n' not in content:
|
||||||
return False
|
return False
|
||||||
gitProjectsFilename = \
|
projectName = \
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/gitprojects.txt'
|
getGitProjectName(baseDir, nickname, domain,
|
||||||
if not os.path.isfile(gitProjectsFilename):
|
subject, content)
|
||||||
return False
|
|
||||||
projectName = None
|
|
||||||
for word in subject.lower().split(' '):
|
|
||||||
if word + '\n' in open(gitProjectsFilename).read():
|
|
||||||
projectName = word
|
|
||||||
break
|
|
||||||
if not projectName:
|
if not projectName:
|
||||||
return False
|
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')
|
patchLines = content.split('\n')
|
||||||
patchFilename = None
|
patchFilename = None
|
||||||
patchDir = None
|
patchDir = None
|
||||||
|
@ -49,6 +71,9 @@ def extractPatch(baseDir: str, nickname: str, domain: str,
|
||||||
if line.startswith('Subject:'):
|
if line.startswith('Subject:'):
|
||||||
patchSubject = \
|
patchSubject = \
|
||||||
line.replace('Subject:', '').replace('/', '|').strip()
|
line.replace('Subject:', '').replace('/', '|').strip()
|
||||||
|
projectName = \
|
||||||
|
getGitProjectName(baseDir, nickname, domain,
|
||||||
|
subject, content)
|
||||||
patchDir = \
|
patchDir = \
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + \
|
baseDir + '/accounts/' + nickname + '@' + domain + \
|
||||||
'/patches/' + projectName
|
'/patches/' + projectName
|
||||||
|
|
10
inbox.py
10
inbox.py
|
@ -58,6 +58,8 @@ from webinterface import individualPostAsHtml
|
||||||
from webinterface import getIconsDir
|
from webinterface import getIconsDir
|
||||||
from question import questionUpdateVotes
|
from question import questionUpdateVotes
|
||||||
from media import replaceYouTube
|
from media import replaceYouTube
|
||||||
|
from git import isGitPatch
|
||||||
|
from git import receiveGitPatch
|
||||||
|
|
||||||
|
|
||||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
|
@ -1578,6 +1580,10 @@ def validPostContent(baseDir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
if 'Z' not in messageJson['object']['published']:
|
if 'Z' not in messageJson['object']['published']:
|
||||||
return False
|
return False
|
||||||
|
if isGitPatch(baseDir, nickname, domain,
|
||||||
|
messageJson['object']['summary'],
|
||||||
|
messageJson['object']['content']):
|
||||||
|
return True
|
||||||
# check for bad html
|
# check for bad html
|
||||||
invalidStrings = ('<script>', '<canvas>', '<style>',
|
invalidStrings = ('<script>', '<canvas>', '<style>',
|
||||||
'</html>', '</body>', '<br>', '<hr>')
|
'</html>', '</body>', '<br>', '<hr>')
|
||||||
|
@ -2027,6 +2033,10 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
if validPostContent(baseDir, nickname, domain,
|
if validPostContent(baseDir, nickname, domain,
|
||||||
postJsonObject, maxMentions, maxEmoji):
|
postJsonObject, maxMentions, maxEmoji):
|
||||||
|
receiveGitPatch(baseDir, nickname, domain,
|
||||||
|
messageJson['object']['summary'],
|
||||||
|
messageJson['object']['content'])
|
||||||
|
|
||||||
# replace YouTube links, so they get less tracking data
|
# replace YouTube links, so they get less tracking data
|
||||||
replaceYouTube(postJsonObject)
|
replaceYouTube(postJsonObject)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue