Beispiel #1
0
def apply_patch(repo_directory, patch_filepath, repo, patch, flags, use_apply):
    """ Apply the `patch` in `patch_filepath` to the `repo` in
        `repo_directory` using git am or git apply. The commit
        with the user running the script (adabot if credentials are set
        for that).

        When `use_apply` is true, the `--apply` flag is automatically added
        to ensure that any passed flags that turn off apply (e.g. `--check`)
        are overridden.
    """
    if not os.getcwd() == repo_directory:
        os.chdir(repo_directory)

    if not use_apply:
        try:
            git.am(flags, patch_filepath)
        except sh.ErrorReturnCode as Err:
            apply_errors.append(
                dict(repo_name=repo, patch_name=patch, error=Err.stderr))
            return False
    else:
        apply_flags = ["--apply"]
        for flag in flags:
            if not flag == "--signoff":
                apply_flags.append(flag)
        try:
            git.apply(apply_flags, patch_filepath)
        except sh.ErrorReturnCode as Err:
            apply_errors.append(
                dict(repo_name=repo, patch_name=patch, error=Err.stderr))
            return False

        with open(patch_filepath) as f:
            for line in f:
                if "[PATCH]" in line:
                    message = '"' + line[(line.find("]") + 2):] + '"'
                    break
        try:
            git.commit("-a", "-m", message)
        except sh.ErrorReturnCode as Err:
            apply_errors.append(
                dict(repo_name=repo, patch_name=patch, error=Err.stderr))
            return False

    try:
        git.push()
    except sh.ErrorReturnCode as Err:
        apply_errors.append(
            dict(repo_name=repo, patch_name=patch, error=Err.stderr))
        return False
    return True
def commit_updates(bundle_path, update_info):
    working_directory = os.path.abspath(os.getcwd())
    message = ["Automated update by Adabot (adafruit/adabot@{})"
               .format(repo_version())]
    os.chdir(bundle_path)
    for url, old_commit, new_commit, summary in update_info:
        url_parts = url.split("/")
        user, repo = url_parts[-2:]
        summary = summary.replace("#", "{}/{}#".format(user, repo))
        message.append("Updating {} to {} from {}:\n{}".format(url,
                                                               new_commit,
                                                               old_commit,
                                                               summary))
    message = "\n\n".join(message)
    git.add(".")
    git.commit(message=message)
    os.chdir(working_directory)
Beispiel #3
0
def main():
    with tempfile.TemporaryDirectory() as tmpdir:
        info('Created tmp directory ' + tmpdir)
        os.chdir(tmpdir)
        git.clone(WIKI_DIR, 'openafs-wiki', _fg=True)
        os.chdir('openafs-wiki')
        git.remote('add', 'gerrit', 'ssh://gerrit.openafs.org/openafs-wiki.git')
        git.fetch('gerrit', _fg=True)
        git.reset('gerrit/master', '--hard', _fg=True)
        update_page('devel/GerritsForMaster.mdwn', 'master')
        update_page('devel/GerritsForStable.mdwn', 'openafs-stable-1_8_x')
        update_page('devel/GerritsForOldStable.mdwn', 'openafs-stable-1_6_x')
        try:
            git.commit('-m', 'update gerrit list', _fg=True)
        except ErrorReturnCode_1:
            print('No changes')
        else:
            git.push('gerrit', 'HEAD:refs/heads/master', _fg=True)
Beispiel #4
0
def update_json_file(working_directory, cp_org_dir, output_filename,
                     json_string):
    """ Clone the circuitpython-org repo, update libraries.json, and push the updates
        in a commit.
    """
    if "TRAIVS" in os.environ:
        if not os.path.isdir(cp_org_dir):
            os.makedirs(cp_org_dir, exist_ok=True)
            git_url = "https://" + os.environ[
                "ADABOT_GITHUB_ACCESS_TOKEN"] + "@github.com/adafruit/circuitpython-org.git"
            git.clone("-o", "adafruit", git_url, cp_org_dir)
        os.chdir(cp_org_dir)
        git.pull()
        git.submodule("update", "--init", "--recursive")

        with open(output_filename, "w") as json_file:
            json.dump(json_string, json_file, indent=2)

        commit_day = date.date.strftime(datetime.datetime.today(), "%Y-%m-%d")
        commit_msg = "adabot: auto-update of libraries.json ({})".format(
            commit_day)
        git.commit("-a", "-m", commit_msg)
        git_push = git.push("adafruit", "master")
        print(git_push)
Beispiel #5
0
def empty_commit(repo):
    """Commits an empty commit and pushes."""
    with sh.pushd(repo):
        git.commit("--allow-empty", "--only", "--message",
                   "Initial empty commit.")
        git.push()