Skip to content

Commit

Permalink
Fix terraform template name
Browse files Browse the repository at this point in the history
  • Loading branch information
GilbertCherrie committed Jul 11, 2024
1 parent 612ade6 commit 5ea4bac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,12 @@ def sync
# eg.
# https://github.ibm.com/manoj-puthran/sample-scripts/tree/v2.0/terraform/templates/hello-world
# is converted as
# "hello-world(v2.0):github.ibm.com/manoj-puthran/sample-scripts/terraform/templates"
def self.template_name_from_git_repo_url(git_repo_url, branch_name, relative_path)
# templates/hello-world
def self.template_name_from_git_repo_url(git_repo_url, relative_path)
temp_url = git_repo_url
# URI library cannot handle git urls, so just convert it to a standard url.
temp_url = temp_url.sub(':', '/').sub('git@', 'https://') if temp_url.start_with?('git@')
temp_uri = URI.parse(temp_url)
hostname = temp_uri.hostname
path = temp_uri.path
path = path[0...-4] if path.end_with?('.git')
path = path[0...-5] if path.end_with?('.git/')
# if template dir is root, then use repo name as basename
if relative_path == '.'
basename = File.basename(path)
Expand All @@ -64,7 +60,7 @@ def self.template_name_from_git_repo_url(git_repo_url, branch_name, relative_pat
basename = File.basename(relative_path)
parent_path = File.dirname(relative_path)
end
"#{basename}(#{branch_name}):#{hostname}#{path}/#{parent_path}"
"#{parent_path}/#{basename}"
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def files_in_repository(git_repo_dir)
names = names_and_payloads.collect(&:first)
payloads = names_and_payloads.collect(&:second)

expect(names.first).to(eq("hello_world_local(master):#{local_repo}/"))
expect(names.first).to(eq("/hello_world_local"))

expected_hash = {
"relative_path" => File.dirname(*repo_dir_structure),
Expand Down Expand Up @@ -249,7 +249,7 @@ def files_in_repository(git_repo_dir)
describe "#template_name_from_git_repo_url" do
let(:git_url_branch_path) { ["git@example.com:manoj-puthran/sample-scripts.git", "v2.0", "terraform/templates/hello-world"] }
let(:https_url_branch_path) { ["https://example.com/manoj-puthran/sample-scripts.git", "v2.0", "terraform/templates/hello-world"] }
let(:expected_result) { "hello-world(v2.0):example.com/manoj-puthran/sample-scripts/terraform/templates" }
let(:expected_result) { "templates/hello-world" }

it "supports https urls" do
expect(described_class.template_name_from_git_repo_url(*https_url_branch_path)).to(eq(expected_result))
Expand Down

0 comments on commit 5ea4bac

Please sign in to comment.