diff --git a/git-clone/README.md b/git-clone/README.md index 054e30c..7121ff8 100644 --- a/git-clone/README.md +++ b/git-clone/README.md @@ -50,3 +50,61 @@ data "coder_git_auth" "github" { id = "github" } ``` + +## Github clone with branch name + +To github clone a url at a specific branch like `feat/example` + +```tf +module "git-clone" { + source = "registry.coder.com/modules/git-clone/coder" + version = "1.0.11" + agent_id = coder_agent.example.id + url = "https://github.com/coder/coder/tree/feat/example" +} +``` + +Self host github + +```tf +module "git-clone" { + source = "registry.coder.com/modules/git-clone/coder" + version = "1.0.11" + agent_id = coder_agent.example.id + url = "https://github.example.com/coder/coder/tree/feat/example" + git_providers = { + "https://github.example.com/" = { + tree_path = "/tree/" + } + } +} +``` + +## Gitlab clone with branch name + +To gitlab clone a url at a specific branch like `feat/example` + +```tf +module "git-clone" { + source = "registry.coder.com/modules/git-clone/coder" + version = "1.0.11" + agent_id = coder_agent.example.id + url = "https://gitlab.com/coder/coder/-/tree/feat/example" +} +``` + +Self host gitlab + +```tf +module "git-clone" { + source = "registry.coder.com/modules/git-clone/coder" + version = "1.0.11" + agent_id = coder_agent.example.id + url = "https://gitlab.example.com/coder/coder/-/tree/feat/example" + git_providers = { + "https://gitlab.example.com/" = { + tree_path = "/-/tree/" + } + } +} +``` diff --git a/git-clone/main.test.ts b/git-clone/main.test.ts index 1ee1c13..678766a 100644 --- a/git-clone/main.test.ts +++ b/git-clone/main.test.ts @@ -104,7 +104,7 @@ describe("git-clone", async () => { expect(state.outputs.branch_name.value).toEqual("feat/branch"); }); - it("gitlab tree url branch_name should match", async () => { + it("gitlab url with branch should match", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", base_dir: "/tmp", @@ -117,7 +117,7 @@ describe("git-clone", async () => { expect(state.outputs.branch_name.value).toEqual("feat/branch"); }); - it("github tree url branch_name should match", async () => { + it("github url with branch should match", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", base_dir: "/tmp", @@ -130,6 +130,25 @@ describe("git-clone", async () => { expect(state.outputs.branch_name.value).toEqual("feat/branch"); }); + it("self-host git url with branch should match", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + base_dir: "/tmp", + url: "https://git.example.com/example/project/-/tree/feat/example", + git_providers: ` + { + "https://git.example.com/" = { + tree_path = "/-/tree/" + } + }`, + }); + expect(state.outputs.repo_dir.value).toEqual("/tmp/project"); + const https_url = "https://git.example.com/example/project"; + expect(state.outputs.clone_url.value).toEqual(https_url); + expect(state.outputs.web_url.value).toEqual(https_url); + expect(state.outputs.branch_name.value).toEqual("feat/example"); + }); + it("handle unsupported git provider", async () => { const url = "https://git.unknown.com/coder/coder"; const state = await runTerraformApply(import.meta.dir, {