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
27 changes: 25 additions & 2 deletions cmd/roborev/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,31 @@ func postCIComment(
body string,
upsert bool,
) error {
client, err := ciGitHubClient()
if err != nil {
return err
}
if upsert {
return ghpkg.UpsertPRComment(ctx, ghRepo, prNumber, body, nil)
return client.UpsertPRComment(ctx, ghRepo, prNumber, body)
}
return client.CreatePRComment(ctx, ghRepo, prNumber, body)
}

func ciGitHubClient() (*ghpkg.Client, error) {
// Resolve the API base URL from GITHUB_API_URL (GitHub Actions
// Enterprise) or GH_HOST. Without this, Enterprise tokens would
// be sent to api.github.com instead of the configured host.
rawBase := os.Getenv("GITHUB_API_URL")
apiBaseURL, err := ghpkg.GitHubAPIBaseURL(rawBase)
if err != nil {
return nil, err
}
// Derive hostname from the resolved API base URL so the
// gh auth token fallback targets the same host as the client.
host := ghpkg.HostnameFromAPIBaseURL(apiBaseURL)
token := ghpkg.ResolveAuthToken(context.Background(), ghpkg.EnvironmentToken(), host)
if token == "" {
return nil, fmt.Errorf("GitHub authentication required: set GH_TOKEN or GITHUB_TOKEN, or authenticate with gh auth login")
}
return ghpkg.CreatePRComment(ctx, ghRepo, prNumber, body, nil)
return ghpkg.NewClient(token, ghpkg.WithBaseURL(apiBaseURL))
}
35 changes: 35 additions & 0 deletions cmd/roborev/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ import (
"github.com/stretchr/testify/require"
)

func installFakeGHAuthToken(t *testing.T, token string) {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("skipping fake gh helper on Windows")
}

dir := t.TempDir()
scriptPath := filepath.Join(dir, "gh")
script := "#!/bin/sh\nif [ \"$1\" = \"auth\" ] && [ \"$2\" = \"token\" ]; then\n printf '%s\\n' " + "'" + token + "'\n exit 0\nfi\nexit 1\n"
require.NoError(t, os.WriteFile(scriptPath, []byte(script), 0755))
t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH"))
}

func TestCIReviewCmd_Help(t *testing.T) {
cmd := ciCmd()
cmd.SetArgs([]string{"review", "--help"})
Expand Down Expand Up @@ -279,6 +292,28 @@ func TestResolveCIReasoning(t *testing.T) {
})
}

func TestCIGitHubClient_UsesGHAuthTokenFallback(t *testing.T) {
installFakeGHAuthToken(t, "gh-auth-token")
t.Setenv("GH_TOKEN", "")
t.Setenv("GITHUB_TOKEN", "")

client, err := ciGitHubClient()
require.NoError(t, err)
require.NotNil(t, client)
}

func TestCIGitHubClient_UsesGitHubAPIURLForHostname(t *testing.T) {
installFakeGHAuthToken(t, "enterprise-token")
t.Setenv("GH_TOKEN", "")
t.Setenv("GITHUB_TOKEN", "")
t.Setenv("GH_HOST", "")
t.Setenv("GITHUB_API_URL", "https://ghe.example.com/api/v3/")

client, err := ciGitHubClient()
require.NoError(t, err)
require.NotNil(t, client)
}

func TestResolveCIMinSeverity(t *testing.T) {
t.Run("explicit flag wins", func(t *testing.T) {
got, err := config.ResolveCIMinSeverity("HIGH", nil, nil)
Expand Down
4 changes: 2 additions & 2 deletions cmd/roborev/tui/handlers_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ func (m model) handleReconnectMsg(msg reconnectMsg) (tea.Model, tea.Cmd) {
m.daemonVersion = msg.version
}
m.clearFetchFailed()
m.fetchGen++ // invalidate pre-reconnect status/fix-jobs responses
m.fetchSeq++ // invalidate pre-reconnect jobs responses
m.fetchGen++ // invalidate pre-reconnect status/fix-jobs responses
m.fetchSeq++ // invalidate pre-reconnect jobs responses
m.loadingJobs = true
m.loadingMore = false
cmds := []tea.Cmd{m.fetchJobs(), m.fetchRepoNames()}
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

src = ./.;

vendorHash = "sha256-50FOt54JquBbUoFWJGsAxOpIB0nnwumhG1lCiKnsY4Y=";
vendorHash = "sha256-1aduKyNYpTt0ZVw14BsZLQsqp8XTJ2fy4zA8HCWbZWs=";

subPackages = [ "cmd/roborev" ];

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ require (
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/google/go-github/v84 v84.0.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v73 v73.0.0 h1:aR+Utnh+Y4mMkS+2qLQwcQ/cF9mOTpdwnzlaw//rG24=
github.com/google/go-github/v73 v73.0.0/go.mod h1:fa6w8+/V+edSU0muqdhCVY7Beh1M8F1IlQPZIANKIYw=
github.com/google/go-github/v84 v84.0.0 h1:I/0Xn5IuChMe8TdmI2bbim5nyhaRFJ7DEdzmD2w+yVA=
github.com/google/go-github/v84 v84.0.0/go.mod h1:WwYL1z1ajRdlaPszjVu/47x1L0PXukJBn73xsiYrRRQ=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down
Loading
Loading