Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,7 @@ func (s *bitbucketRepoService) ActionsURL(repoHTMLURL string) string {
func (s *bitbucketRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/downloads"
}

func (s *bitbucketRepoService) BlobURL(repoHTMLURL, ref, path string) string {
return repoHTMLURL + "/src/" + ref + "/" + path
}
12 changes: 12 additions & 0 deletions bitbucket/urls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package bitbucket

import "testing"

func TestBitbucketRepoBlobURL(t *testing.T) {
s := &bitbucketRepoService{}
got := s.BlobURL("https://bitbucket.org/owner/repo", "master", "README.md")
want := "https://bitbucket.org/owner/repo/src/master/README.md"
if got != want {
t.Errorf("BlobURL = %q, want %q", got, want)
}
}
4 changes: 4 additions & 0 deletions forges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ func (m *mockRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}

func (m *mockRepoService) BlobURL(repoHTMLURL, ref, path string) string {
return repoHTMLURL + "/blob/" + ref + "/" + path
}

type mockIssueService struct {
issue *Issue
issues []Issue
Expand Down
4 changes: 4 additions & 0 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,8 @@ func (s *giteaRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}

func (s *giteaRepoService) BlobURL(repoHTMLURL, ref, path string) string {
return repoHTMLURL + "/src/branch/" + ref + "/" + path
}

func boolPtr(b bool) *bool { return &b }
12 changes: 12 additions & 0 deletions gitea/urls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gitea

import "testing"

func TestGiteaRepoBlobURL(t *testing.T) {
s := &giteaRepoService{}
got := s.BlobURL("https://codeberg.org/owner/repo", "main", "README.md")
want := "https://codeberg.org/owner/repo/src/branch/main/README.md"
if got != want {
t.Errorf("BlobURL = %q, want %q", got, want)
}
}
4 changes: 4 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,7 @@ func (s *gitHubRepoService) ActionsURL(repoHTMLURL string) string {
func (s *gitHubRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}

func (s *gitHubRepoService) BlobURL(repoHTMLURL, ref, path string) string {
return repoHTMLURL + "/blob/" + ref + "/" + path
}
12 changes: 12 additions & 0 deletions github/urls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package github

import "testing"

func TestGitHubRepoBlobURL(t *testing.T) {
s := &gitHubRepoService{}
got := s.BlobURL("https://github.com/owner/repo", "main", "cmd/main.go")
want := "https://github.com/owner/repo/blob/main/cmd/main.go"
if got != want {
t.Errorf("BlobURL = %q, want %q", got, want)
}
}
4 changes: 4 additions & 0 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,7 @@ func (s *gitLabRepoService) ActionsURL(repoHTMLURL string) string {
func (s *gitLabRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/releases"
}

func (s *gitLabRepoService) BlobURL(repoHTMLURL, ref, path string) string {
return repoHTMLURL + "/-/blob/" + ref + "/" + path
}
12 changes: 12 additions & 0 deletions gitlab/urls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gitlab

import "testing"

func TestGitLabRepoBlobURL(t *testing.T) {
s := &gitLabRepoService{}
got := s.BlobURL("https://gitlab.com/group/project", "main", "src/app.go")
want := "https://gitlab.com/group/project/-/blob/main/src/app.go"
if got != want {
t.Errorf("BlobURL = %q, want %q", got, want)
}
}
2 changes: 1 addition & 1 deletion internal/cli/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var browseCmd = &cobra.Command{
if branch == "" {
branch = repo.DefaultBranch
}
url = repoURL + fmt.Sprintf("/blob/%s/%s", branch, args[0])
url = forge.Repos().BlobURL(repoURL, branch, args[0])
}
} else {
url = repoURL
Expand Down
1 change: 1 addition & 0 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type RepoService interface {
WikiURL(repoHTMLURL string) string
ActionsURL(repoHTMLURL string) string
ReleasesURL(repoHTMLURL string) string
BlobURL(repoHTMLURL, ref, path string) string
}

// PullRequestService provides operations on pull requests (merge requests on GitLab).
Expand Down
Loading