def send_json(data): try: requests.post("http://%s:%s%s" % (cfg.gitpubsub_host, cfg.gitpubsub_port, cfg.gitpubsub_path), data = json.dumps({"commit": data})) except: log.exception()
def authorized_committers(repo_name): writers = set() # Read the static file to get admin and bot names. parser = ConfigParser.SafeConfigParser() with open(cfg.auth_file) as handle: parser.readfp(handle) for admin in parser.get("groups", "gitadmins").split(","): writers.add(util.decode(admin.strip())) if parser.has_option("groups", repo_name): dn = parser.get("groups", repo_name).strip() else: # drop subproject name if present repo_name = SUBPROJECT_RE.sub("", repo_name) dn = GROUP_DN % {"group": repo_name} pdn = PGROUP_DN % {"group": repo_name} # Individually granted access if parser.has_option("individuals", repo_name): for person in parser.get("individuals", repo_name).split(","): writers.add(util.decode(person.strip())) # Add the committers listed in ldap for the project. lh = ldap.initialize("ldaps://ldap-us-ro.apache.org") numldap = 0 # ldap entries fetched attrs = ["memberUid", "member"] # check new style ldap groups DN first try: for ldapresult, attrs in lh.search_s(pdn, ldap.SCOPE_BASE, attrlist=attrs): numldap += 1 for availid in attrs.get("memberUid", []): writers.add(availid) for result in attrs.get("member", []): writers.add(DN_RE.match(result).group(1)) except: log.exception() # If new style doesn't exist, default to old style DN if numldap == 0: try: for ldapresult, attrs in lh.search_s(dn, ldap.SCOPE_BASE, attrlist=attrs): numldap += 1 for availid in attrs.get("memberUid", []): writers.add(availid) for result in attrs.get("member", []): writers.add(DN_RE.match(result).group(1)) except: log.exception() # Add per-repository exceptions map(writers.add, cfg.extra_writers) return writers
def main(): ghurl = "git@github:apache/%s.git" % cfg.repo_name os.chdir("/x1/repos/asf/%s.git" % cfg.repo_name) try: subprocess.check_call(["git", "push", "--all", ghurl]) try: os.unlink("/x1/gitbox/broken/%s.txt" % cfg.repo_name) except: pass except Exception as err: with open("/x1/git/gitbox/broken/%s.txt" % cfg.repo_name, "w") as f: f.write("BROKEN AT %s\n" % time.strftime("%c")) f.close() log.exception(err)
def send_json(data): try: data = json.dumps({"commit": data}) + "\n\n" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((cfg.gitpubsub_host, int(cfg.gitpubsub_port))) request = "PUT %s HTTP/1.1\r\n\r\n%s" % (cfg.gitpubsub_path, data) sock.sendall(request) resp = [] while True: resp.append(sock.recv(4096)) if len(resp[-1]) == 0: break resp = "".join(resp) # Ignore the resp because gitpubsub returns # garbage. #if not resp.startswith("HTTP/1.1 OK"): # raise ValueError("Invalid server response: %r" % resp) sock.close() except: log.exception()
path = filter(None, os.environ["PATH_INFO"].split("/")) path = filter(lambda p: p != "git-receive-pack", path) if len(path) != 1: raise ValueError("Invalid PATH_INFO: %s" % os.environ["PATH_INFO"]) path = path[0] repo = "" if path[-4:] == ".git": repo = util.decode(path[:-4]) else: repo = util.decode(path) try: config = git_multimail.Config('multimailhook') try: environment = git_multimail.GenericEnvironment(config=config) except git_multimail.ConfigurationException: sys.stderr.write('*** %s\n' % sys.exc_info()[1]) sys.exit(1) mailer = git_multimail.SendMailer( os.environ, command=['/usr/local/sbin/sendmail', '-oi', '-t'], envelopesender='*****@*****.**', ) git_multimail.run_as_post_receive_hook(environment, mailer) except Exception, exc: log.exception() print "Error: %s" % exc exit(0) # Don't exit(1) here, we want the bleedin' sync to complete!