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
17 changes: 17 additions & 0 deletions bitbucket/check_runs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bitbucket

import (
"context"

forge "github.com/git-pkgs/forge"
)

type bitbucketCheckRunService struct{}

func (f *bitbucketForge) CheckRuns() forge.CheckRunService {
return &bitbucketCheckRunService{}
}

func (s *bitbucketCheckRunService) List(_ context.Context, _, _, _ string) ([]forge.CheckRun, error) {
return nil, forge.ErrNotSupported
}
10 changes: 10 additions & 0 deletions cmd/forge/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package main

import (
"errors"
"os"

"github.com/git-pkgs/forge/internal/cli"
)

// exitCoder is implemented by command errors that carry a process exit code.
type exitCoder interface {
ExitCode() int
}

func main() {
if err := cli.Execute(); err != nil {
var ec exitCoder
if errors.As(err, &ec) {
os.Exit(ec.ExitCode())
}
os.Exit(1)
}
}
1 change: 1 addition & 0 deletions forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Forge interface {
Files() FileService
Collaborators() CollaboratorService
CommitStatuses() CommitStatusService
CheckRuns() CheckRunService
Commits() CommitService
GetRateLimit(ctx context.Context) (*RateLimit, error)
// ParsePath parses URL path segments into a resource reference.
Expand Down
10 changes: 10 additions & 0 deletions forges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,16 @@ func (m *mockForge) CommitStatuses() CommitStatusService {
return &mockCommitStatusService{}
}

type mockCheckRunService struct{}

func (m *mockCheckRunService) List(context.Context, string, string, string) ([]CheckRun, error) {
return nil, nil
}

func (m *mockForge) CheckRuns() CheckRunService {
return &mockCheckRunService{}
}

func (m *mockForge) Commits() CommitService {
if m.commitService != nil {
return m.commitService
Expand Down
8 changes: 8 additions & 0 deletions gerrit/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type unsupportedSecretService struct{}
type unsupportedNotificationService struct{}
type unsupportedCollaboratorService struct{}
type unsupportedCommitStatusService struct{}
type unsupportedCheckRunService struct{}
type unsupportedCommitService struct{}

func (f *gerritForge) Issues() forge.IssueService { return &unsupportedIssueService{} }
Expand All @@ -38,6 +39,9 @@ func (f *gerritForge) Collaborators() forge.CollaboratorService {
func (f *gerritForge) CommitStatuses() forge.CommitStatusService {
return &unsupportedCommitStatusService{}
}
func (f *gerritForge) CheckRuns() forge.CheckRunService {
return &unsupportedCheckRunService{}
}
func (f *gerritForge) Commits() forge.CommitService { return &unsupportedCommitService{} }
func (f *gerritForge) GetRateLimit(context.Context) (*forge.RateLimit, error) {
return nil, forge.ErrNotSupported
Expand Down Expand Up @@ -224,6 +228,10 @@ func (s *unsupportedCommitStatusService) Set(context.Context, string, string, st
return nil, forge.ErrNotSupported
}

func (s *unsupportedCheckRunService) List(context.Context, string, string, string) ([]forge.CheckRun, error) {
return nil, forge.ErrNotSupported
}

func (s *unsupportedCommitService) ResolveCommit(context.Context, string, string, string) (string, error) {
return "", forge.ErrNotSupported
}
17 changes: 17 additions & 0 deletions gitea/check_runs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gitea

import (
"context"

forge "github.com/git-pkgs/forge"
)

type giteaCheckRunService struct{}

func (f *giteaForge) CheckRuns() forge.CheckRunService {
return &giteaCheckRunService{}
}

func (s *giteaCheckRunService) List(_ context.Context, _, _, _ string) ([]forge.CheckRun, error) {
return nil, forge.ErrNotSupported
}
57 changes: 57 additions & 0 deletions github/check_runs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package github

import (
"context"
"net/http"

forge "github.com/git-pkgs/forge"

"github.com/google/go-github/v82/github"
)

type gitHubCheckRunService struct {
client *github.Client
}

func (f *gitHubForge) CheckRuns() forge.CheckRunService {
return &gitHubCheckRunService{client: f.client}
}

func (s *gitHubCheckRunService) List(ctx context.Context, owner, repo, sha string) ([]forge.CheckRun, error) {
var all []forge.CheckRun
opts := &github.ListCheckRunsOptions{
ListOptions: github.ListOptions{PerPage: defaultPageSize},
}
for {
result, resp, err := s.client.Checks.ListCheckRunsForRef(ctx, owner, repo, sha, opts)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, forge.ErrNotFound
}
return nil, err
}
for _, r := range result.CheckRuns {
cr := forge.CheckRun{
ID: r.GetID(),
Name: r.GetName(),
Status: forge.NormalizeCIStatus(r.GetStatus()),
Conclusion: forge.NormalizeCIConclusion(r.GetConclusion()),
HTMLURL: r.GetHTMLURL(),
}
if r.StartedAt != nil {
t := r.StartedAt.Time
cr.StartedAt = &t
}
if r.CompletedAt != nil {
t := r.CompletedAt.Time
cr.CompletedAt = &t
}
all = append(all, cr)
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return all, nil
}
19 changes: 19 additions & 0 deletions gitlab/check_runs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !tinygo

package gitlab

import (
"context"

forge "github.com/git-pkgs/forge"
)

type gitLabCheckRunService struct{}

func (f *gitLabForge) CheckRuns() forge.CheckRunService {
return &gitLabCheckRunService{}
}

func (s *gitLabCheckRunService) List(_ context.Context, _, _, _ string) ([]forge.CheckRun, error) {
return nil, forge.ErrNotSupported
}
8 changes: 8 additions & 0 deletions gitlab/gitlab_tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ type gitLabCommitStatusService struct{}

func (f *gitLabForge) CommitStatuses() forge.CommitStatusService { return &gitLabCommitStatusService{} }

func (f *gitLabForge) CheckRuns() forge.CheckRunService { return &gitLabCheckRunService{} }

type gitLabCheckRunService struct{}

func (s *gitLabCheckRunService) List(ctx context.Context, owner, repo, sha string) ([]forge.CheckRun, error) {
return nil, errTinyGo
}

func (s *gitLabCommitStatusService) List(ctx context.Context, owner, repo, sha string) ([]forge.CommitStatus, error) {
return nil, errTinyGo
}
Expand Down
1 change: 1 addition & 0 deletions internal/cli/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func init() {
prCmd.AddCommand(prReactionsCmd())
prCmd.AddCommand(prReactCmd())
prCmd.AddCommand(prCheckoutCmd())
prCmd.AddCommand(prChecksCmd())
}

func prViewCmd() *cobra.Command {
Expand Down
16 changes: 10 additions & 6 deletions internal/cli/pr_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ func (m *mockPRService) ListURL(_ string) string {

// mockForge implements forges.Forge for testing.
type mockForge struct {
prService *mockPRService
repoService forges.RepoService
releaseService forges.ReleaseService
webhookService forges.WebhookService
prService *mockPRService
repoService forges.RepoService
releaseService forges.ReleaseService
webhookService forges.WebhookService
ciService forges.CIService
commitStatusService forges.CommitStatusService
checkRunService forges.CheckRunService
}

func (m *mockForge) Repos() forges.RepoService { return m.repoService }
Expand All @@ -96,7 +99,7 @@ func (m *mockForge) PullRequests() forges.PullRequestService { return m.prSer
func (m *mockForge) Labels() forges.LabelService { return nil }
func (m *mockForge) Milestones() forges.MilestoneService { return nil }
func (m *mockForge) Releases() forges.ReleaseService { return m.releaseService }
func (m *mockForge) CI() forges.CIService { return nil }
func (m *mockForge) CI() forges.CIService { return m.ciService }
func (m *mockForge) Branches() forges.BranchService { return nil }
func (m *mockForge) DeployKeys() forges.DeployKeyService { return nil }
func (m *mockForge) Webhooks() forges.WebhookService { return m.webhookService }
Expand All @@ -105,7 +108,8 @@ func (m *mockForge) Notifications() forges.NotificationService { return nil }
func (m *mockForge) Reviews() forges.ReviewService { return nil }
func (m *mockForge) Files() forges.FileService { return nil }
func (m *mockForge) Collaborators() forges.CollaboratorService { return nil }
func (m *mockForge) CommitStatuses() forges.CommitStatusService { return nil }
func (m *mockForge) CommitStatuses() forges.CommitStatusService { return m.commitStatusService }
func (m *mockForge) CheckRuns() forges.CheckRunService { return m.checkRunService }
func (m *mockForge) Commits() forges.CommitService { return nil }
func (m *mockForge) GetRateLimit(_ context.Context) (*forges.RateLimit, error) {
return nil, forges.ErrNotSupported
Expand Down
Loading
Loading