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
16 changes: 16 additions & 0 deletions bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,19 @@ func (s *bitbucketRepoService) Search(ctx context.Context, opts forge.SearchRepo
// The closest is searching within a workspace, which requires an owner.
return nil, forge.ErrNotSupported
}

func (s *bitbucketRepoService) SettingsURL(repoHTMLURL string) string {
return repoHTMLURL + "/admin"
}

func (s *bitbucketRepoService) WikiURL(repoHTMLURL string) string {
return repoHTMLURL + "/wiki"
}

func (s *bitbucketRepoService) ActionsURL(repoHTMLURL string) string {
return repoHTMLURL + "/pipelines"
}

func (s *bitbucketRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/downloads"
}
4 changes: 4 additions & 0 deletions bitbucket/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,7 @@ func (s *bitbucketIssueService) ListComments(ctx context.Context, owner, repo st
}
return all, nil
}

func (s *bitbucketIssueService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/issues"
}
4 changes: 4 additions & 0 deletions bitbucket/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func (s *bitbucketLabelService) Update(_ context.Context, _, _, _ string, _ forg
func (s *bitbucketLabelService) Delete(_ context.Context, _, _, _ string) error {
return forge.ErrNotSupported
}

func (s *bitbucketLabelService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/issues"
}
4 changes: 4 additions & 0 deletions bitbucket/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,7 @@ func (s *bitbucketPRService) ListComments(ctx context.Context, owner, repo strin
}
return all, nil
}

func (s *bitbucketPRService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/pull-requests"
}
3 changes: 3 additions & 0 deletions forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var ErrOwnerNotFound = errors.New("owner not found")
// ErrNotSupported is returned when a forge does not support an operation.
var ErrNotSupported = errors.New("not supported by this forge")

// ErrLabelExists is returned when creating a label that already exists.
var ErrLabelExists = errors.New("label already exists")

// HTTPError represents a non-OK HTTP response from a forge API.
type HTTPError struct {
StatusCode int
Expand Down
28 changes: 28 additions & 0 deletions forges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,22 @@ func (m *mockRepoService) Search(_ context.Context, opts SearchRepoOpts) ([]Repo
return m.repos, nil
}

func (m *mockRepoService) SettingsURL(repoHTMLURL string) string {
return repoHTMLURL + "/settings"
}

func (m *mockRepoService) WikiURL(repoHTMLURL string) string {
return repoHTMLURL + "/wiki"
}

func (m *mockRepoService) ActionsURL(repoHTMLURL string) string {
return repoHTMLURL + "/actions"
}

func (m *mockRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}

type mockIssueService struct {
issue *Issue
issues []Issue
Expand Down Expand Up @@ -681,6 +697,10 @@ func (m *mockIssueService) AddReaction(_ context.Context, owner, repo string, nu
return nil, nil
}

func (m *mockIssueService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/issues"
}

type mockPRService struct {
pr *PullRequest
prs []PullRequest
Expand Down Expand Up @@ -768,6 +788,10 @@ func (m *mockPRService) AddReaction(_ context.Context, owner, repo string, numbe
return nil, nil
}

func (m *mockPRService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/pulls"
}

type mockLabelService struct {
label *Label
labels []Label
Expand Down Expand Up @@ -809,6 +833,10 @@ func (m *mockLabelService) Delete(_ context.Context, owner, repo, name string) e
return nil
}

func (m *mockLabelService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/labels"
}

type mockMilestoneService struct {
milestone *Milestone
milestones []Milestone
Expand Down
16 changes: 16 additions & 0 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,20 @@ func (s *giteaRepoService) Search(ctx context.Context, opts forge.SearchRepoOpts
return repos, nil
}

func (s *giteaRepoService) SettingsURL(repoHTMLURL string) string {
return repoHTMLURL + "/settings"
}

func (s *giteaRepoService) WikiURL(repoHTMLURL string) string {
return repoHTMLURL + "/wiki"
}

func (s *giteaRepoService) ActionsURL(repoHTMLURL string) string {
return repoHTMLURL + "/actions"
}

func (s *giteaRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}

func boolPtr(b bool) *bool { return &b }
4 changes: 4 additions & 0 deletions gitea/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,7 @@ func (s *giteaIssueService) ListComments(ctx context.Context, owner, repo string
}
return all, nil
}

func (s *giteaIssueService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/issues"
}
13 changes: 11 additions & 2 deletions gitea/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ func (s *giteaLabelService) Create(ctx context.Context, owner, repo string, opts

l, resp, err := s.client.CreateLabel(owner, repo, gOpts)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, forge.ErrNotFound
if resp != nil {
switch resp.StatusCode {
case http.StatusNotFound:
return nil, forge.ErrNotFound
case http.StatusConflict, http.StatusUnprocessableEntity:
return nil, forge.ErrLabelExists
}
}
return nil, err
}
Expand Down Expand Up @@ -210,3 +215,7 @@ func (s *giteaLabelService) Delete(ctx context.Context, owner, repo, name string
}
return nil
}

func (s *giteaLabelService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/labels"
}
4 changes: 4 additions & 0 deletions gitea/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ func (s *giteaPRService) ListComments(ctx context.Context, owner, repo string, n
}
return all, nil
}

func (s *giteaPRService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/pulls"
}
16 changes: 16 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,19 @@ func (s *gitHubRepoService) Search(ctx context.Context, opts forge.SearchRepoOpt
}
return repos, nil
}

func (s *gitHubRepoService) SettingsURL(repoHTMLURL string) string {
return repoHTMLURL + "/settings"
}

func (s *gitHubRepoService) WikiURL(repoHTMLURL string) string {
return repoHTMLURL + "/wiki"
}

func (s *gitHubRepoService) ActionsURL(repoHTMLURL string) string {
return repoHTMLURL + "/actions"
}

func (s *gitHubRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/releases"
}
4 changes: 4 additions & 0 deletions github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,7 @@ func (s *gitHubIssueService) ListComments(ctx context.Context, owner, repo strin
}
return all, nil
}

func (s *gitHubIssueService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/issues"
}
13 changes: 11 additions & 2 deletions github/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ func (s *gitHubLabelService) Create(ctx context.Context, owner, repo string, opt

l, resp, err := s.client.Issues.CreateLabel(ctx, owner, repo, ghLabel)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, forge.ErrNotFound
if resp != nil {
switch resp.StatusCode {
case http.StatusNotFound:
return nil, forge.ErrNotFound
case http.StatusUnprocessableEntity:
return nil, forge.ErrLabelExists
}
}
return nil, err
}
Expand Down Expand Up @@ -133,3 +138,7 @@ func (s *gitHubLabelService) Delete(ctx context.Context, owner, repo, name strin
}
return nil
}

func (s *gitHubLabelService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/labels"
}
4 changes: 4 additions & 0 deletions github/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,7 @@ func (s *gitHubPRService) ListComments(ctx context.Context, owner, repo string,
}
return all, nil
}

func (s *gitHubPRService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/pulls"
}
16 changes: 16 additions & 0 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,19 @@ func (s *gitLabRepoService) Search(ctx context.Context, opts forge.SearchRepoOpt
}
return repos, nil
}

func (s *gitLabRepoService) SettingsURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/settings"
}

func (s *gitLabRepoService) WikiURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/wikis"
}

func (s *gitLabRepoService) ActionsURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/pipelines"
}

func (s *gitLabRepoService) ReleasesURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/releases"
}
4 changes: 4 additions & 0 deletions gitlab/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@ func (s *gitLabIssueService) ListComments(ctx context.Context, owner, repo strin
}
return all, nil
}

func (s *gitLabIssueService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/issues"
}
13 changes: 11 additions & 2 deletions gitlab/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ func (s *gitLabLabelService) Create(ctx context.Context, owner, repo string, opt

l, resp, err := s.client.Labels.CreateLabel(pid, glOpts)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, forge.ErrNotFound
if resp != nil {
switch resp.StatusCode {
case http.StatusNotFound:
return nil, forge.ErrNotFound
case http.StatusConflict:
return nil, forge.ErrLabelExists
}
}
return nil, err
}
Expand Down Expand Up @@ -140,3 +145,7 @@ func (s *gitLabLabelService) Delete(ctx context.Context, owner, repo, name strin
}
return nil
}

func (s *gitLabLabelService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/labels"
}
4 changes: 4 additions & 0 deletions gitlab/prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,7 @@ func (s *gitLabPRService) ListComments(ctx context.Context, owner, repo string,
}
return all, nil
}

func (s *gitLabPRService) ListURL(repoHTMLURL string) string {
return repoHTMLURL + "/-/merge_requests"
}
29 changes: 18 additions & 11 deletions internal/cli/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,40 @@ var browseCmd = &cobra.Command{
return err
}

url := repo.HTMLURL
if url == "" {
url = fmt.Sprintf("https://%s/%s/%s", domain, owner, repoName)
repoURL := repo.HTMLURL
if repoURL == "" {
repoURL = fmt.Sprintf("https://%s/%s/%s", domain, owner, repoName)
}

var url string
if flagBrowseSettings {
url += "/settings"
url = forge.Repos().SettingsURL(repoURL)
} else if flagBrowseWiki {
url += "/wiki"
url = forge.Repos().WikiURL(repoURL)
} else if flagBrowseActions {
url += "/actions"
url = forge.Repos().ActionsURL(repoURL)
} else if flagBrowseReleases {
url += "/releases"
url = forge.Repos().ReleasesURL(repoURL)
} else if flagBrowseIssues {
url += "/issues"
url = forge.Issues().ListURL(repoURL)
} else if flagBrowsePulls {
url += "/pulls"
url = forge.PullRequests().ListURL(repoURL)
} else if len(args) > 0 {
if n, err := strconv.Atoi(args[0]); err == nil {
url += fmt.Sprintf("/issues/%d", n)
issue, err := forge.Issues().Get(cmd.Context(), owner, repoName, n)
if err != nil {
return fmt.Errorf("getting issue #%d: %w", n, err)
}
url = issue.HTMLURL
} else {
branch := flagBrowseBranch
if branch == "" {
branch = repo.DefaultBranch
}
url += fmt.Sprintf("/blob/%s/%s", branch, args[0])
url = repoURL + fmt.Sprintf("/blob/%s/%s", branch, args[0])
}
} else {
url = repoURL
}

if flagNoBrowser {
Expand Down
Loading
Loading