From 12efc56ccf1cdc4abbfb99dd05f26762ad9cb0e5 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sun, 7 Apr 2024 02:33:27 -0700 Subject: [PATCH] feat(git-clone): add outputs for folder_name and git_provider --- git-clone/main.test.ts | 9 +++++++-- git-clone/main.tf | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/git-clone/main.test.ts b/git-clone/main.test.ts index e7fffa4..c7d6e81 100644 --- a/git-clone/main.test.ts +++ b/git-clone/main.test.ts @@ -45,6 +45,7 @@ describe("git-clone", async () => { url, }); expect(state.outputs.repo_dir.value).toEqual("/tmp/coder"); + expect(state.outputs.folder_name.value).toEqual("coder"); expect(state.outputs.clone_url.value).toEqual(url); expect(state.outputs.web_url.value).toEqual(url); expect(state.outputs.branch_name.value).toEqual(""); @@ -71,6 +72,7 @@ describe("git-clone", async () => { url, }); expect(state.outputs.repo_dir.value).toEqual("/tmp/coder"); + expect(state.outputs.git_provider.value).toEqual(""); expect(state.outputs.clone_url.value).toEqual(url); const https_url = "https://github.com/coder/coder.git"; expect(state.outputs.web_url.value).toEqual(https_url); @@ -80,10 +82,10 @@ describe("git-clone", async () => { it("branch_name should not include query string", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", - base_dir: "/tmp", url: "https://gitlab.com/mike.brew/repo-tests.log/-/tree/feat/branch?ref_type=heads", }); - expect(state.outputs.repo_dir.value).toEqual("/tmp/repo-tests.log"); + expect(state.outputs.repo_dir.value).toEqual("~/repo-tests.log"); + expect(state.outputs.folder_name.value).toEqual("repo-tests.log"); const https_url = "https://gitlab.com/mike.brew/repo-tests.log"; expect(state.outputs.clone_url.value).toEqual(https_url); expect(state.outputs.web_url.value).toEqual(https_url); @@ -110,6 +112,7 @@ describe("git-clone", async () => { url: "https://gitlab.com/mike.brew/repo-tests.log/-/tree/feat/branch", }); expect(state.outputs.repo_dir.value).toEqual("/tmp/repo-tests.log"); + expect(state.outputs.git_provider.value).toEqual("gitlab"); const https_url = "https://gitlab.com/mike.brew/repo-tests.log"; expect(state.outputs.clone_url.value).toEqual(https_url); expect(state.outputs.web_url.value).toEqual(https_url); @@ -123,6 +126,7 @@ describe("git-clone", async () => { url: "https://github.com/michaelbrewer/repo-tests.log/tree/feat/branch", }); expect(state.outputs.repo_dir.value).toEqual("/tmp/repo-tests.log"); + expect(state.outputs.git_provider.value).toEqual("github"); const https_url = "https://github.com/michaelbrewer/repo-tests.log"; expect(state.outputs.clone_url.value).toEqual(https_url); expect(state.outputs.web_url.value).toEqual(https_url); @@ -142,6 +146,7 @@ describe("git-clone", async () => { }`, }); expect(state.outputs.repo_dir.value).toEqual("/tmp/project"); + expect(state.outputs.git_provider.value).toEqual("gitlab"); 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); diff --git a/git-clone/main.tf b/git-clone/main.tf index b29979c..fc72809 100644 --- a/git-clone/main.tf +++ b/git-clone/main.tf @@ -70,6 +70,16 @@ output "repo_dir" { description = "Full path of cloned repo directory" } +output "git_provider" { + value = local.provider + description = "The git provider of the repository" +} + +output "folder_name" { + value = local.folder_name + description = "The name of the folder that will be created" +} + output "clone_url" { value = local.clone_url description = "The exact Git repository URL that will be cloned"