Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions git-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This module allows you to automatically clone a repository by URL and skip if it
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
}
Expand All @@ -27,7 +27,7 @@ module "git-clone" {
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
base_dir = "~/projects/coder"
Expand All @@ -41,7 +41,7 @@ To use with [Git Authentication](https://coder.com/docs/v2/latest/admin/git-prov
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
}
Expand All @@ -66,15 +66,15 @@ data "coder_parameter" "git_repo" {
# Clone the repository for branch `feat/example`
module "git_clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = data.coder_parameter.git_repo.value
}

# Create a code-server instance for the cloned repository
module "code-server" {
source = "registry.coder.com/modules/code-server/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
order = 1
folder = "/home/${local.username}/${module.git_clone.folder_name}"
Expand All @@ -98,7 +98,7 @@ Configuring `git-clone` for a self-hosted GitHub Enterprise Server running at `g
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.example.com/coder/coder/tree/feat/example"
git_providers = {
Expand All @@ -116,7 +116,7 @@ To GitLab clone with a specific branch like `feat/example`
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://gitlab.com/coder/coder/-/tree/feat/example"
}
Expand All @@ -127,7 +127,7 @@ Configuring `git-clone` for a self-hosted GitLab running at `gitlab.example.com`
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://gitlab.example.com/coder/coder/-/tree/feat/example"
git_providers = {
Expand All @@ -147,7 +147,7 @@ For example, to clone the `feat/example` branch:
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
branch_name = "feat/example"
Expand All @@ -163,7 +163,7 @@ For example, this will clone into the `~/projects/coder/coder-dev` folder:
```tf
module "git-clone" {
source = "registry.coder.com/modules/git-clone/coder"
version = "1.0.18"
version = "1.0.20"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
folder_name = "coder-dev"
Expand Down
2 changes: 1 addition & 1 deletion git-clone/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +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.git_provider.value).toEqual("github");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what changed in the Terraform code that requires the test update?

I'm guessing what was happening before was:

  1. git_providers (plural) map gets defined with the "https://github.com/" and "https://gitlab.com/" keys
  2. git_provider (singular) tried to access a value from the map. There was no match, so the output became an empty string for a zero value
  3. Adding new keys for this PR now makes it so that the output does access a value from the map

That's just a guess, though. I'm still not clear on how defining git_provider as local.provider would allow it to access the map in the first place

Copy link
Contributor Author

@djarbz djarbz Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular test provided a git@github URL for the repo, but the module originally wasn't configured to match these types of URLs so the output would be a blank string as it did not match.

My PR matches on these types of URLs and so will now output the provider properly as GitHub or Gitlab.

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);
Expand Down
6 changes: 6 additions & 0 deletions git-clone/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ variable "git_providers" {
"https://github.com/" = {
provider = "github"
},
"[email protected]:" = {
provider = "github"
},
"https://gitlab.com/" = {
provider = "gitlab"
},
"[email protected]:" = {
provider = "gitlab"
},
}
validation {
error_message = "Allowed values for provider are \"github\" or \"gitlab\"."
Expand Down