This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpostcommit.py
49 lines (42 loc) · 1.77 KB
/
postcommit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from twisted.python import log
from twisted.spread import pb
from twisted.internet import utils
from twisted.application import internet
class TracPostCommitPbServerRoot(pb.Root):
def __init__(self, allowedIP, tracEnvPath, tracURL, postCommitHook):
self.allowedIP = allowedIP
self.tracEnvPath = tracEnvPath
self.tracURL = tracURL
self.postCommitHook = postCommitHook
def remote_postCommit(self, revision, author, msg):
log.msg("postCommit(revision=%(revision)r)", revision=revision)
result = utils.getProcessOutput(
self.postCommitHook, ['-p', self.tracEnvPath,
'-r', str(revision),
'-u', author,
'-m', msg,
'-s', self.tracURL],
errortoo=True, env=os.environ)
def hooked(result):
log.msg("hook completed: %(result)r", result=result)
return result
def failed(reason):
log.err(reason, "hook failed")
return reason
result.addCallbacks(hooked, failed)
return result
class TracPostCommitPbServerRootFactory(pb.PBServerFactory):
def buildProtocol(self, addr):
if addr.host != self.root.allowedIP:
raise Exception("DISALLOWED")
return pb.PBServerFactory.buildProtocol(self, addr)
def service(vcsServer, postCommitHook, tracEnvPath, tracURL, tracCommitServerPort):
root = TracPostCommitPbServerRoot(
allowedIP=vcsServer,
tracEnvPath=tracEnvPath,
tracURL=tracURL,
postCommitHook=postCommitHook)
return internet.TCPServer(
tracCommitServerPort,
TracPostCommitPbServerRootFactory(root))