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

Using git providers hosted without https fails to clone repositories #690

Closed
Tpuljak opened this issue Jun 17, 2024 · 8 comments · Fixed by #704
Closed

Using git providers hosted without https fails to clone repositories #690

Tpuljak opened this issue Jun 17, 2024 · 8 comments · Fixed by #704
Labels
backlog backlog until further notice bug Something isn't working never stale An issue that never goes stale

Comments

@Tpuljak
Copy link
Member

Tpuljak commented Jun 17, 2024

Describe the bug
When a git provider API is not available through https, Daytona fails to clone the repo because it defaults to https

To Reproduce
Steps to reproduce the behavior:

  1. Add a git provider (e.g. Gitea) hosted only with http
  2. Create a repo from any URL of that git provider
  3. Notice that the repo fails to clone because it defaulted to https

Expected behavior
The repo can be cloned successfully via http

Desktop (please complete the following information):

  • OS: any
  • Daytona Version: v0.19.0

Additional context
The issue is directly related to this function https://github.com/daytonaio/daytona/blob/main/pkg/gitprovider/git_provider.go#L131

@Tpuljak Tpuljak added bug Something isn't working never stale An issue that never goes stale backlog backlog until further notice labels Jun 17, 2024
@RS-labhub
Copy link
Contributor

Hi @Tpuljak

Lemme know if this works! If it is, then I'll raise a PR, so that you could be able to merge it into main.

// checkHTTPSAvailable checks if the given URL is accessible via HTTPS
func checkHTTPSAvailable(source, owner, repo string) bool {
	url := fmt.Sprintf("https://%s/%s/%s.git", source, owner, repo)
	resp, err := http.Head(url)
	if err != nil || resp.StatusCode != http.StatusOK {
		return false
	}
	return true
}

// getCloneUrl constructs the clone URL using the appropriate protocol
func getCloneUrl(source, owner, repo string) string {
	if checkHTTPSAvailable(source, owner, repo) {
		return fmt.Sprintf("https://%s/%s/%s.git", source, owner, repo)
	}
	return fmt.Sprintf("https://%s/%s/%s.git", source, owner, repo)
}

@Tpuljak
Copy link
Member Author

Tpuljak commented Jun 18, 2024

@RS-labhub seems great! If you tested the changes, you can raise a PR and we'll review asap.

@RS-labhub
Copy link
Contributor

Done!

@RS-labhub
Copy link
Contributor

RS-labhub commented Jun 21, 2024

Hii @Tpuljak , when I'm passing the parameters (protocol, source, owner, name) to the getCloneUrl function inside the pkg > gitprovider, the bitbuckettest.go is throwing error.
A/c the error, the expected protocol should be this: Protocol:"https", while the actual protocol is: Protocol:""

PS: Getting no clue

May I change it to expected???

  • Protocol: (string) (len=5) "https", (expected)
  • Protocol: (string) "", (actual)

@RS-labhub
Copy link
Contributor

By the way, I fixed my old functions, where that gitlab_test.go file was throwing an error... Unit tests are passed.
Now, I'm waiting for your respond @Tpuljak, then only I'll proceed further🙂

@Tpuljak
Copy link
Member Author

Tpuljak commented Jun 21, 2024

@RS-labhub I don't see a PR I can review.

@RS-labhub
Copy link
Contributor

@RS-labhub I don't see a PR I can review.

Which one PR I raise?? The one with parameters (protocol, source, owner, name) or another one? Or both??

@Tpuljak
Copy link
Member Author

Tpuljak commented Jun 21, 2024

Which one PR I raise?? The one with parameters (protocol, source, owner, name) or another one? Or both??

@RS-labhub as I said. Issue comments are not the place to paste and discuss code. Open a PR that passes all test with your proposed solution and we'll comment there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog backlog until further notice bug Something isn't working never stale An issue that never goes stale
Projects
None yet
2 participants