diff options
Diffstat (limited to 'internal/context/repo.go')
-rw-r--r-- | internal/context/repo.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/context/repo.go b/internal/context/repo.go index 587005c2..6e4a3bc1 100644 --- a/internal/context/repo.go +++ b/internal/context/repo.go @@ -7,6 +7,7 @@ package context import ( "fmt" "io/ioutil" + "net/url" "strings" "github.com/editorconfig/editorconfig-core-go/v2" @@ -96,6 +97,22 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) { return editorconfig.ParseBytes(data) } +// MakeURL accepts a string or url.URL as argument and returns escaped URL prepended with repository URL. +func (r *Repository) MakeURL(location interface{}) string { + switch location := location.(type) { + case string: + tempURL := url.URL{ + Path: r.RepoLink + "/" + location, + } + return tempURL.String() + case url.URL: + location.Path = r.RepoLink + "/" + location.Path + return location.String() + default: + panic("location type must be either string or url.URL") + } +} + // PullRequestURL returns URL for composing a pull request. // This function does not check if the repository can actually compose a pull request. func (r *Repository) PullRequestURL(baseBranch, headBranch string) string { |