def approve(commit): """Merge the rendered template from ght/master to master """ repo_path = resolve_repository_path(".") ght = GHT(repo_path=repo_path) with stashed_checkout(ght.repo, "master"): click.echo(ght.repo.git.merge("--no-squash", "--no-ff", commit))
def render(url, refspec, dest_branch): """Render the template. \b REFSPEC: The template branch/refspec to use for rendering [default=master] GHT_BRANCH: The destination branch of the rendered results [default=ght/master] """ if not dest_branch.startswith("ght/"): raise click.ClickException( "Refusing to render the template." f"The destination branch `{dest_branch}` does not begin ght/.") repo_path = resolve_repository_path(".") ght = GHT(repo_path=repo_path, template_url=url, template_ref=refspec) ght.load_config() if ght.template_url is None: raise click.ClickException( "Could not detect the template repository url. " "Please set it manually with -u/--url") with stashed_checkout(ght.repo, dest_branch): ght.render_tree() return 0
def configure(repo_path): """Edit an existing template configuration file A git commit is created if the file is modified. """ # Open the repo repo_path = resolve_repository_path(repo_path) ght = GHT(repo_path, None) with stashed_checkout(ght.repo, "ght/master"): click.edit(filename=f"{repo_path}/.github/ght.yaml") ght.repo.index.add(".github/ght.yaml") ght.repo.index.commit("[ght]: Update configuration file.", skip_hooks=True)
def ght(tmpdir, template: Repo): ght = GHT.init( path=os.path.join(tmpdir, "ght"), config=dict( ght=dict( template=dict(url=f"file://{template.working_tree_dir}", ref="master"), hello="Hello World!", a="alpha", b="beta", c="charlie", abc="{{ght.a}}/{{ght.b}}/{{ght.c}}", abcd="{{ght.abc}}/delta", ) ), ) assert not ght.repo.bare ght.fetch_template() ght.load_config() ght.prepare_tree_for_rendering() ght.repo.index.commit("[ght]: imported ght/template") return ght
def test_render_tree(ght: GHT): ght.render_tree() assert "ght/template" not in ght.repo.heads
def test_prepare_tree_for_rendering(ght: GHT): ght.prepare_tree_for_rendering() assert "ght/template" not in ght.repo.heads
def test_render_ght_conf(ght: GHT): ght.render_ght_conf() ght.load_config() assert ght.config["ght"]["abc"] == "alpha/beta/charlie" assert ght.config["ght"]["abcd"] == "alpha/beta/charlie/delta"