refactor: move repository file URL generation to Repository method
1 file changed, 24 insertions(+), 0 deletions(-)
changed files
M internal/config/repository.go → internal/config/repository.go
@@ -22,6 +22,30 @@ Repo string Revision string `toml:"-"` } +func (r *Repository) GetFileURL(path string, line ...string) (string, errors.E) { + switch r.Type { + case GitHub: + ref := r.Revision + if ref == "" { + ref = "master" + } + u, err := url.JoinPath("https://github.com/", r.Owner, r.Repo, "blob", ref, path) + if err != nil { + return "", errors.Wrap(err, "failed to join path") + } + if len(line) > 0 { + u += fmt.Sprintf("#L%s", line[0]) + } + + return u, nil + default: + return "", errors.Errorf( + "don't know how to generate a repository URL for %s", + r.Type.String(), + ) + } +} + func (r *Repository) String() string { switch r.Type { case GitHub: