Skip to content

Commit

Permalink
Merge pull request #466 from MUzairS15/MUzairS15/url-utils
Browse files Browse the repository at this point in the history
utility functions for `URL`
  • Loading branch information
Mohd Uzair authored Feb 26, 2024
2 parents 9ac6328 + 979a8c2 commit 339076f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (gr GitRepo) extractRepoDetailsFromSourceURL() (owner, repo, branch, root s
root = parts[3]

} else {
err = ErrInvalidGitHubSourceURL(fmt.Errorf("Source URL $s is invalid, specify owner, repo, branch and filepath in the url according to the specified source url format", gr.URL.String()))
err = ErrInvalidGitHubSourceURL(fmt.Errorf("Source URL %s is invalid, specify owner, repo, branch and filepath in the url according to the specified source url format", gr.URL.String()))
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion models/events/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
mathrand "math/rand"
"net/http"
"net/url"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -357,7 +358,7 @@ func WriteJSONToFile[K any](outputPath string, data K) error {
return nil
}

func CreateDirectory(path string) error{
func CreateDirectory(path string) error {
err := os.MkdirAll(path, 0755)
if err != nil {
err = ErrCreateDir(err, path)
Expand All @@ -370,3 +371,12 @@ func CreateDirectory(path string) error{
func ReplaceSpacesAndConvertToLowercase(s string) string {
return strings.ToLower(strings.ReplaceAll(s, " ", ""))
}

func ExtractDomainFromURL(location string) string {
parsedURL, err := url.Parse(location)
// If unable to extract domain return the location as is.
if err != nil {
return location
}
return regexp.MustCompile(`(([a-zA-Z0-9]+\.)([a-zA-Z0-9]+))$`).FindString(parsedURL.Hostname())
}

0 comments on commit 339076f

Please sign in to comment.