Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add repo 'name' property to 'git_repository' #304

Open
cringdahl opened this issue Nov 12, 2024 · 1 comment
Open

add repo 'name' property to 'git_repository' #304

cringdahl opened this issue Nov 12, 2024 · 1 comment

Comments

@cringdahl
Copy link

I'd like to get the name of a repository from the 'git' provider. The path basename is not guaranteed to be the repo name, so I'd rather not rely on it.

The closest thing git gives to a canonical repo name is via the remote origin url:

basename -s .git $(git config --get remote.origin.url)

It seems like a fairly straightforward datum to report back, but I'm no Go coder.

Thanks!

sebhoss added a commit that referenced this issue Nov 13, 2024
Signed-off-by: Sebastian Hoß <[email protected]>
sebhoss added a commit that referenced this issue Nov 13, 2024
Signed-off-by: Sebastian Hoß <[email protected]>
@sebhoss
Copy link
Member

sebhoss commented Nov 13, 2024

Hey, thanks for opening this!

It's currently possible to get what you want using some built-in terraform/tofu functions. I've pushed an example to https://github.com/metio/terraform-provider-git/blob/main/terratest/data-sources/git_remote/single_remote/outputs.tf#L20-L29 which uses the git_remote data source. Although be aware that remotes can have more than one URL and Git allows to use aliases, thus a remote URL might not even contain a '/'.

Does the example code work for you? Otherwise I would probably add a provider defined function to this provider instead of adding a property to an existing resource, since extracting the basename of a remote URL might be useful in various scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants