コード例 #1
0
ファイル: sync.py プロジェクト: jpirek/infrastructure-puppet
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!"
        )
コード例 #2
0
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)
コード例 #3
0
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()
コード例 #4
0
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)
コード例 #5
0
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/git/git-dual/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))
コード例 #6
0
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 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()