diff options
author | Andrey Filippov <afilippov1985@users.noreply.github.com> | 2020-01-26 01:42:38 +0400 |
---|---|---|
committer | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-01-26 05:42:38 +0800 |
commit | 0a461b829af1ff54994287505012bd07fbf3bf44 (patch) | |
tree | 0c50d69577ee9bf02ab829c7d49b072d5fd93dc8 /internal/context | |
parent | 91e9495148378ccb2766a63c1e8191d6787fab02 (diff) |
repo: fix redirect after opening/closing milestone (#5903)
* Fix milestone redirect
* gosimple
* Apply suggestions from code review
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* fix typo
* Update docstring of MakeURL
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Diffstat (limited to 'internal/context')
-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 { |