Esempio n. 1
0
def commit(
    repo: pygit2.Repository,
    message: str,
    pathspecs: typing.Optional[typing.List[typing.Union[str,
                                                        pathlib.Path]]] = None,
) -> None:
    if pathspecs is None:
        pathspecs = []

    pathspecs = [(str(
        pathspec.relative_to(repo.workdir) if pathspec.is_absolute(
        ) else pathspec) if isinstance(pathspec, pathlib.Path) else pathspec)
                 for pathspec in pathspecs]

    repo.index.add_all(pathspecs=pathspecs)
    repo.index.write()
    tree = repo.index.write_tree()

    try:
        parent, ref = repo.resolve_refish(refish=repo.head.name)
    except pygit2.GitError:
        parents = []
        ref_name = 'refs/heads/master'
    else:
        parents = [parent.oid]
        ref_name = ref.name

    repo.create_commit(ref_name, repo.default_signature,
                       repo.default_signature, message, tree, parents)
Esempio n. 2
0
parser = argparse.ArgumentParser(description='Run Kiln for every commit on the default branch in a git repo')
parser.add_argument('dir')
parser.add_argument('app_name')
parser.add_argument('data_collector_url')
args = parser.parse_args()
proj_dir = vars(args)['dir']
app_name = vars(args)['app_name']
url = vars(args)['data_collector_url']

repo_path = discover_repository(proj_dir)
if repo_path == None:
    raise Exception("Project directory isn't a git repo. Exiting!")

repo = Repository(repo_path)
default_branch = repo.resolve_refish('origin/HEAD')[1].shorthand
walker = repo.walk(repo.branches[default_branch].peel().id, GIT_SORT_REVERSE | GIT_SORT_TIME)
walker.simplify_first_parent()
all_commits = [x.id for x in walker]
kiln_config_path = os.path.abspath(os.path.join(proj_dir, "kiln.toml"))
for commit in all_commits:
    if commit == "":
        continue
    subprocess.check_call(["git", "reset", "--hard", "HEAD"], cwd=proj_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    subprocess.check_call(["git", "checkout", str(commit)], cwd=proj_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

    if not os.path.exists(os.path.abspath(os.path.join(proj_dir, "Gemfile.lock"))):
        print("No Gemfile.lock, skipping commit ", str(commit))
        continue

    with open(kiln_config_path, 'w') as f: