def main(): ghurl = "git@github:apache/%s.git" % cfg.repo_name for loc in locations: filepath = os.path.join(loc, '%s.git' % cfg.repo_name) if os.path.exists(filepath): break else: filepath = None if filepath: os.chdir(filepath) try: for ref in git.stream_refs(sys.stdin): if ref.is_rewrite(): print("Syncing %s (FORCED)..." % ref.name) subprocess.check_output([ "git", "push", "-f", ghurl, "%s:%s" % (ref.newsha, ref.name) ]) else: print("Syncing %s..." % ref.name) subprocess.check_output([ "git", "push", ghurl, "%s:%s" % (ref.newsha, ref.name) ]) except subprocess.CalledProcessError as err: what = err.output if type(what) is bytes: what = what.decode('utf-8') util.abort("Could not sync with GitHub: %s" % what) else: util.abort( "Could not sync with GitHub: Could not determine file-path for repository!" )
def main(): # Set some vars for use in templating later tmplvars = { 'committer': cfg.committer, 'reponame': cfg.repo_name, 'refname': "??", 'what': 'rewind' } # Check individual refs and commits for all of # our various conditions. Track each ref update # so that we can log them if everything is ok. for ref in git.stream_refs(sys.stdin): tmplvars['refname'] = ref.name # If protected ref and rewinding is attempted: if ref.is_protected(cfg.protect) and ref.is_rewrite(): tmplvars['what'] = 'rewind' notify(TMPL_REWRITE % tmplvars, "GitBox: Rewind attempted on %s in %s" % (ref.name, cfg.repo_name)) if ref.is_tag(): continue for commit in ref.commits(): # If protected ref and merge is attempted: if cfg.no_merges and commit.is_merge() \ and ref.is_protected(cfg.protect): tmplvars['what'] = 'merge' notify(TMPL_REWRITE % tmplvars, "GitBox: Merge attempted on %s in %s" % (ref.name, cfg.repo_name))
def main(): # Check if commits are enabled. for lockname in cfg.write_locks: if os.path.exists(lockname): util.abort(WRITE_LOCKED) # Check if the repo is out of sync lockfile = "/x1/gitbox/broken/%s.txt" % cfg.repo_name if os.path.exists(lockfile): util.abort(SYNC_BROKEN % lockfile) # Check committer's authorization for this # repository. authorized_committers = auth.authorized_committers(cfg.repo_name) authorized_committers.add('git-site-role') authorized_committers.add('mergebot-role') authorized_committers.add('buildbot') if cfg.committer not in authorized_committers: util.abort(NOT_AUTHORIZED) # Mergebot can only commit from a.b.c.d # IP addresses are listed in the constant above. if cfg.committer == "mergebot-role" and cfg.ip not in MERGEBOT_APPROVED_IPS: util.abort(u"mergebot only works from the mergebot VM, tut tut!") # buildbot only possible from bb-slave1 # 209.188.14.160 is bb-slave1.a.o if cfg.committer == "buildbot" and (cfg.ip != "209.188.14.160"): util.abort(u"Buildbot role account only accessible via bb-slave1") # Check individual refs and commits for all of # our various conditions. Track each ref update # so that we can log them if everything is ok. refs = [] for ref in git.stream_refs(sys.stdin): refs.append(ref) # Site writer role if cfg.committer == "git-site-role" and not re.match(r".*(asf-site|asf-staging.*)$", ref.name): util.abort(u"git-site-role can only write to asf-site/asf-staging* branches!") if ref.is_protected(cfg.protect) and ref.is_rewrite(): util.abort(NO_REWRITES % ref.name) if ref.is_tag(): continue for commit in ref.commits(): if cfg.no_merges and commit.is_merge() \ and ref.is_protected(cfg.protect): util.abort(NO_MERGES % ref.name) # Log pushlogs to sqlite3 conn = sqlite3.connect('/x1/gitbox/db/gitbox.db') cursor = conn.cursor() for ref in refs: cursor.execute("""INSERT INTO pushlog (repository, asfid, githubid, baseref, ref, old, new, date) VALUES (?,?,?,?,?,?,?,DATETIME('now'))""", (cfg.repo_name, cfg.committer, 'asfgit', ref.name, ref.name, ref.oldsha, ref.newsha, )) # Save and close up shop conn.commit() conn.close()
def main(): ghurl = "git@github:apache/%s.git" % cfg.repo_name os.chdir("/x1/repos/asf/%s.git" % cfg.repo_name) try: for ref in git.stream_refs(sys.stdin): print("Syncing %s..." % ref.name) subprocess.check_call( ["git", "push", ghurl, "%s:%s" % (ref.newsha, ref.name)]) except subprocess.CalledProcessError as err: util.abort("Could not sync with GitHub: %s" % err.output)
def main(): # Check if commits are enabled. for lockname in cfg.write_locks: if os.path.exists(lockname): util.abort(WRITE_LOCKED) # Check if the repo is out of sync if os.path.exists("/x1/gitbox/broken/%s.txt" % cfg.repo_name): util.abort(SYNC_BROKEN) # Check committer's authorization for this # repository. authorized_committers = auth.authorized_committers(cfg.repo_name) authorized_committers.add('git-site-role') authorized_committers.add('mergebot-role') if cfg.committer not in authorized_committers: util.abort(NOT_AUTHORIZED) # Mergebot can only commit from a.b.c.d # 207.244.88.152 is mergebot-vm.apache.org for the Beam project if cfg.committer == "mergebot-role" and (cfg.ip != "207.244.88.152"): util.abort(u"mergebot only works from the mergebot VM, tut tut!") # Check individual refs and commits for all of # our various conditions. Track each ref update # so that we can log them if everything is ok. refs = [] for ref in git.stream_refs(sys.stdin): refs.append(ref) # Site writer role if ref.name.find("asf-site") == -1 and cfg.committer == "git-site-role": util.abort(u"git-site-role can only write to asf-site branches!") if ref.is_protected(cfg.protect) and ref.is_rewrite(): util.abort(NO_REWRITES % ref.name) if ref.is_tag(): continue for commit in ref.commits(): if cfg.no_merges and commit.is_merge() \ and ref.is_protected(cfg.protect): util.abort(NO_MERGES % ref.name) # Log pushlogs to sqlite3 conn = sqlite3.connect('/x1/gitbox/db/gitbox.db') cursor = conn.cursor() for ref in refs: cursor.execute("""INSERT INTO pushlog (repository, asfid, githubid, baseref, ref, old, new, date) VALUES (?,?,?,?,?,?,?,DATETIME('now'))""", (cfg.repo_name, cfg.committer, 'asfgit', ref.name, ref.name, ref.oldsha, ref.newsha, )) # Save and close up shop conn.commit() conn.close()
def main(): # Check if commits are enabled. for lockname in cfg.write_locks: if os.path.exists(lockname): util.abort(WRITE_LOCKED) # Check if the repo is out of sync if os.path.exists("/x1/gitbox/broken/%s.txt" % cfg.repo_name): util.abort(SYNC_BROKEN) # Check committer's authorization for this # repository. authorized_committers = auth.authorized_committers(cfg.repo_name) if cfg.committer not in authorized_committers: util.abort(NOT_AUTHORIZED) # Check individual refs and commits for all of # our various conditions. Track each ref update # so that we can log them if everything is ok. refs = [] for ref in git.stream_refs(sys.stdin): refs.append(ref) if ref.is_protected(cfg.protect) and ref.is_rewrite(): util.abort(NO_REWRITES % ref.name) if ref.is_tag(): continue for commit in ref.commits(): if cfg.no_merges and commit.is_merge() \ and ref.is_protected(cfg.protect): util.abort(NO_MERGES % ref.name) # Log pushlogs to sqlite3 conn = sqlite3.connect('/x1/gitbox/db/gitbox.db') cursor = conn.cursor() for ref in refs: cursor.execute( """INSERT INTO pushlog (repository, asfid, githubid, baseref, ref, old, new, date) VALUES (?,?,?,?,?,?,?,DATETIME('now'))""", ( cfg.repo_name, cfg.committer, 'asfgit', ref.name, ref.name, ref.oldsha, ref.newsha, )) # Save and close up shop conn.commit() conn.close()
def main(): ghurl = "git@github:apache/%s.git" % cfg.repo_name os.chdir("/x1/repos/asf/%s.git" % cfg.repo_name) try: for ref in git.stream_refs(sys.stdin): if ref.is_rewrite(): print("Syncing %s (FORCED)..." % ref.name) subprocess.check_output(["git", "push", "-f", ghurl, "%s:%s" % (ref.newsha, ref.name)]) else: print("Syncing %s..." % ref.name) subprocess.check_output(["git", "push", ghurl, "%s:%s" % (ref.newsha, ref.name)]) except subprocess.CalledProcessError as err: what = err.output if type(what) is bytes: what = what.decode('utf-8') util.abort("Could not sync with GitHub: %s" % what)
def main(): for ref in git.stream_refs(sys.stdin): if ref.is_tag(): rname = ref.name if hasattr(ref, 'name') else "unknown" send_json({ "repository": "git", "server": "gitbox", "project": cfg.repo_name, "ref": rname, "hash": "null", "sha": "null", "date": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "authored": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "author": commiter, "email": remote_user, "committer": committer, "commited": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "ref_names": "", "subject": rname, "log": "Create %s" % rname, "body": "", "files": [] }) continue if ref.deleted(): continue for commit in ref.commits(num=10, reverse=True): send_json({ "repository": "git", "server": "gitbox", "project": cfg.repo_name, "ref": commit.ref.name, "hash": commit.commit, "sha": commit.sha, "date": commit.authored, "authored": commit.authored, "author": commit.author_name, "email": commit.author_email, "committer": commit.committer, "commited": commit.committed, "ref_names": commit.ref_names, "subject": commit.subject, "log": commit.subject, "body": commit.body, "files": commit.files() })
def main(): # WIP: FOR NOW, ABORT EVERYTHING! if True: util.abort(NOT_AUTHORIZED) # Check if commits are enabled. for lockname in cfg.write_locks: if os.path.exists(lockname): util.abort(WRITE_LOCKED) # Check if the repo is out of sync if os.path.exists("/x1/gitbox/broken/%s.txt" % cfg.repo_name): util.abort(SYNC_BROKEN) # Check committer's authorization for this # repository. authorized_committers = auth.authorized_committers(cfg.repo_name) if cfg.committer not in authorized_committers: util.abort(NOT_AUTHORIZED) # Check individual refs and commits for all of # our various conditions. Track each ref update # so that we can log them if everything is ok. refs = [] for ref in git.stream_refs(sys.stdin): refs.append(ref) if ref.is_protected(cfg.protect) and ref.is_rewrite(): util.abort(NO_REWRITES % ref.name) if ref.is_tag(): continue for commit in ref.commits(): if cfg.no_merges and commit.is_merge() \ and ref.is_protected(cfg.protect): util.abort(NO_MERGES % ref.name) # Everything is kosher. Log each ref update and exit log_fname = os.path.join(cfg.repo_dir, "ref-updates.log") with open(log_fname, 'a') as log: for ref in refs: stamp = datetime.datetime.now().ctime() oldsha = ref.oldsha[:10] newsha = ref.newsha[:10] mesgfmt = u"[%s] %s %s -> %s %s\n" mesg = mesgfmt % (stamp, ref.name, oldsha, newsha, cfg.remote_user) log.write(util.encode(mesg))
def main(): for ref in git.stream_refs(sys.stdin): rname = ref.name if hasattr(ref, 'name') else "unknown" via_asfyaml = has_publishing_via_asfyaml(rname) send_json( { "repository": "git", "server": "gitbox", "project": cfg.repo_name, "ref": rname, "type": "tag" if ref.is_tag() else "branch", "from": ref.oldsha if not ref.created() else None, "to": ref.newsha if not ref.deleted() else None, "action": "created" if ref.created() else "deleted" if ref.deleted() else "updated", "actor": cfg.committer, "date": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), }, "push") if ref.is_tag(): send_json({ "repository": "git", "server": "gitbox", "project": cfg.repo_name, "ref": rname, "hash": "null", "sha": "null", "date": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "authored": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "author": cfg.committer, "email": cfg.remote_user, "committer": cfg.committer, "commited": time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()), "ref_names": "", "subject": rname, "log": "Create %s" % rname, "body": "", "files": [] }) continue for commit in ref.commits(num=10, reverse=True): send_json({ "autopublish": via_asfyaml, "repository": "git", "server": "gitbox", "project": cfg.repo_name, "ref": commit.ref.name, "hash": commit.commit, "sha": commit.sha, "date": commit.authored, "authored": commit.authored, "author": commit.author_name, "email": commit.author_email, "committer": commit.committer, "commited": commit.committed, "ref_names": commit.ref_names, "subject": commit.subject, "log": commit.subject, "body": commit.body, "files": commit.files() })