Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .github/workflows/reusable-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ jobs:
PRIOR_REVIEW_SHA: ${{ steps.prior-review.outputs.prior_sha }}
PRIOR_REVIEW_FILE: ${{ steps.prior-review.outputs.prior_review_file }}
PRIOR_REVIEW_PROVENANCE: ${{ steps.prior-review.outputs.prior_review_provenance }}
FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET }}
Comment thread
ralphbean marked this conversation as resolved.
Resolved
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }}
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT }}
OTEL_EXPORTER_OTLP_TRACES_HEADERS: ${{ secrets.OTEL_EXPORTER_OTLP_TRACES_HEADERS }}
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ The `admin` command group's `uninstall`/`analyze`/`enable`/`disable` subcommands

The commands below have lighter documentation footprints. Apply the general `grep` rule when changing them:

`dispatch`, `scan`, `lock`, `poll`, `fetch-skill`, `post-review`, `post-comment`, `reconcile-status`, `resolve-mr-source`, `check-protected-branch`
`dispatch`, `scan`, `lock`, `poll`, `fetch-skill`, `fetch-review-threads`, `post-review`, `post-comment`, `reconcile-status`, `resolve-mr-source`, `check-protected-branch`

The most comprehensive single reference for all commands (including minor ones) is `docs/guides/dev/cli-internals.md`, which documents the full command tree with flags.
16 changes: 16 additions & 0 deletions docs/guides/dev/cli-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ fullsend
│ ├── --dry-run # Print what would be posted without API calls
│ ├── --keep-history # Append previous content as collapsed history (default true)
│ └── --fullsend-dir <path> # .fullsend config directory (default: $FULLSEND_DIR; resolves keep_history default)
├── fetch-review-threads # Fetch PR/MR review threads as JSON
│ ├── --repo <owner/repo> # Repository in owner/repo format (required)
│ ├── --pr <int> # Pull request / merge request number (required)
│ ├── --forge <forge> # Forge backend: github (default) or gitlab
│ ├── --token <string> # Forge token (default: forge environment token)
│ └── --base-url <url> # Forge API base URL
├── post-comment # Post issue/PR comments to GitHub (deprecated)
│ └── --token <string> # GitHub token (default: $GH_TOKEN / $GITHUB_TOKEN / gh auth token)
├── eval-measure # Score wild-run traces (eval measurements)
Expand Down Expand Up @@ -206,6 +212,16 @@ fullsend

### Command Decomposition

`fetch-review-threads` emits a JSON object containing `threads` and a
`truncated` flag. GitHub review threads are capped at 20 pages; consumers
must treat `truncated: true` as an incomplete result. GitLab merge-request
discussions are mapped to the same thread model, including resolution state,
comments, positions, and resolver identity when GitLab provides it. Each comment
also includes `author_role` and `author_role_verified`; resolved threads include
`resolved_by_role` and `resolved_by_role_verified`. A role is `none` with
`verified: true` for an authoritative non-member result, and `verified: false`
when the actor is a bot/unknown or the permission lookup fails.

The `mint`, `inference`, and `github` subcommands decompose setup into role-specific operations for organizations that separate GCP and GitHub responsibilities:

| Install Phase | Standalone Command | Required Access |
Expand Down
54 changes: 54 additions & 0 deletions internal/cli/fetchreviewthreads.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cli

import (
"encoding/json"
"fmt"
"strings"

"github.com/fullsend-ai/fullsend/internal/repos"
"github.com/spf13/cobra"
)

func newFetchReviewThreadsCmd() *cobra.Command {
var (
repo string
pr int
forgeName string
token string
baseURL string
)

cmd := &cobra.Command{
Use: "fetch-review-threads",
Comment thread
csoceanu marked this conversation as resolved.
Resolved
Short: "Fetch pull-request review threads through the forge client",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
if pr <= 0 {
return fmt.Errorf("--pr must be a positive integer, got %d", pr)
}
parts := strings.SplitN(repo, "/", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return fmt.Errorf("--repo must be in owner/repo format, got %q", repo)
}

client, err := resolvePostReviewClient(forgeName, token, baseURL)
if err != nil {
return err
}
threads, err := client.ListPullRequestReviewThreads(cmd.Context(), parts[0], parts[1], pr)
if err != nil {
return err
}
return json.NewEncoder(cmd.OutOrStdout()).Encode(threads)
},
}

cmd.Flags().StringVar(&repo, "repo", "", "repository in owner/repo format (required)")
cmd.Flags().IntVar(&pr, "pr", 0, "pull request number (required)")
cmd.Flags().StringVar(&forgeName, "forge", repos.ForgeGitHub, "forge backend (github or gitlab)")
cmd.Flags().StringVar(&token, "token", "", "forge token (defaults to the forge environment token)")
cmd.Flags().StringVar(&baseURL, "base-url", "", "forge API base URL")
_ = cmd.MarkFlagRequired("repo")
_ = cmd.MarkFlagRequired("pr")
return cmd
}
94 changes: 94 additions & 0 deletions internal/cli/fetchreviewthreads_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package cli

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/fullsend-ai/fullsend/internal/forge"
"github.com/fullsend-ai/fullsend/internal/repos"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFetchReviewThreadsCommand(t *testing.T) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
assert.Equal(t, "/api/graphql", r.URL.Path)
_, _ = w.Write([]byte(`{"data":{"repository":{"pullRequest":{"reviewThreads":{"pageInfo":{"hasNextPage":false,"endCursor":""},"nodes":[{"id":"thread-1","isResolved":true,"path":"main.go","line":12,"originalLine":11,"resolvedBy":{"login":"reviewer"},"comments":{"pageInfo":{"hasNextPage":false},"nodes":[]}}]}}}}}`))
}))
defer srv.Close()

var output bytes.Buffer
cmd := newFetchReviewThreadsCmd()
cmd.SetOut(&output)
cmd.SetErr(&output)
cmd.SetArgs([]string{"--repo", "owner/repo", "--pr", "42", "--token", "test-token", "--base-url", srv.URL})
cmd.SetContext(context.Background())

// The forge client owns its HTTP transport, so point the GitHub client at
// the TLS test server through the environment used by the command factory.
// The command's client uses the default transport; install the test server's
// transport for the duration of this test.
oldTransport := http.DefaultTransport
http.DefaultTransport = srv.Client().Transport
t.Cleanup(func() { http.DefaultTransport = oldTransport })

require.NoError(t, cmd.Execute())
var got forge.ReviewThreadPage
require.NoError(t, json.Unmarshal(output.Bytes(), &got))
require.Len(t, got.Threads, 1)
assert.Equal(t, "thread-1", got.Threads[0].ID)
assert.True(t, got.Threads[0].IsResolved)
}

func TestFetchReviewThreadsCommand_DefaultsToGitHubForge(t *testing.T) {
cmd := newFetchReviewThreadsCmd()

flag := cmd.Flags().Lookup("forge")
require.NotNil(t, flag)
assert.Equal(t, repos.ForgeGitHub, flag.DefValue)
}

func TestFetchReviewThreadsCommand_ReturnsForgeError(t *testing.T) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusForbidden)
_, _ = w.Write([]byte(`{"message":"denied"}`))
}))
defer srv.Close()
oldTransport := http.DefaultTransport
http.DefaultTransport = srv.Client().Transport
t.Cleanup(func() { http.DefaultTransport = oldTransport })

cmd := newFetchReviewThreadsCmd()
cmd.SetArgs([]string{"--repo", "owner/repo", "--pr", "42", "--token", "test-token", "--base-url", srv.URL})
cmd.SetContext(context.Background())

err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "list pull request review threads page 1")
}

func TestFetchReviewThreadsCommand_ValidatesFlags(t *testing.T) {
tests := []struct {
name string
args []string
want string
}{
{name: "non-positive pull request", args: []string{"--repo", "owner/repo", "--pr", "0"}, want: "positive integer"},
{name: "invalid repository", args: []string{"--repo", "owner", "--pr", "1"}, want: "owner/repo format"},
{name: "unsupported forge", args: []string{"--repo", "owner/repo", "--pr", "1", "--forge", "bitbucket", "--token", "token"}, want: "unsupported forge"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := newFetchReviewThreadsCmd()
cmd.SetArgs(tt.args)
err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), tt.want)
})
}
}
1 change: 1 addition & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func newRootCmd() *cobra.Command {
cmd.AddCommand(newScanCmd())
cmd.AddCommand(newReposCmd())
cmd.AddCommand(newPostReviewCmd())
cmd.AddCommand(newFetchReviewThreadsCmd())
cmd.AddCommand(newIssuesCmd())
cmd.AddCommand(newPostCommentCmd())
cmd.AddCommand(newReconcileStatusCmd())
Expand Down
18 changes: 18 additions & 0 deletions internal/forge/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ type FakeClient struct {
// Pull request reviews for ListPullRequestReviews.
PRReviews map[string][]PullRequestReview // key: "owner/repo/number"

// Pull request review threads for ListPullRequestReviewThreads.
PRReviewThreads map[string]ReviewThreadPage // key: "owner/repo/number"

// WorkflowRunJobs for ListWorkflowRunJobs.
WorkflowRunJobs map[int][]WorkflowJob // key: runID

Expand Down Expand Up @@ -1950,6 +1953,21 @@ func (f *FakeClient) ListPullRequestReviews(_ context.Context, owner, repo strin
return nil, nil
}

func (f *FakeClient) ListPullRequestReviewThreads(_ context.Context, owner, repo string, number int) (ReviewThreadPage, error) {
f.mu.Lock()
defer f.mu.Unlock()
if e := f.err("ListPullRequestReviewThreads"); e != nil {
return ReviewThreadPage{}, e
}
if f.PRReviewThreads != nil {
key := fmt.Sprintf("%s/%s/%d", owner, repo, number)
if threads, ok := f.PRReviewThreads[key]; ok {
return threads, nil
}
}
return ReviewThreadPage{}, nil
}

func (f *FakeClient) DismissPullRequestReview(_ context.Context, owner, repo string, number, reviewID int, message string) error {
f.mu.Lock()
defer f.mu.Unlock()
Expand Down
21 changes: 21 additions & 0 deletions internal/forge/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ func TestFakeClient_ListPullRequestCommits(t *testing.T) {
require.Error(t, err)
}

func TestFakeClient_ListPullRequestReviewThreads(t *testing.T) {
page := ReviewThreadPage{
Threads: []ReviewThread{{ID: "thread-1", IsResolved: true, Path: "main.go"}},
Truncated: true,
}
f := NewFakeClient()
f.PRReviewThreads = map[string]ReviewThreadPage{"o/r/7": page}

got, err := f.ListPullRequestReviewThreads(context.Background(), "o", "r", 7)
require.NoError(t, err)
assert.Equal(t, page, got)

got, err = f.ListPullRequestReviewThreads(context.Background(), "o", "r", 8)
require.NoError(t, err)
assert.Empty(t, got.Threads)

f.Errors["ListPullRequestReviewThreads"] = errors.New("boom")
_, err = f.ListPullRequestReviewThreads(context.Background(), "o", "r", 7)
require.Error(t, err)
}

func TestFakeClient_ListOrgRepos(t *testing.T) {
ctx := context.Background()
fc := &FakeClient{
Expand Down
41 changes: 41 additions & 0 deletions internal/forge/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"os"
"strings"
"time"

"github.com/fullsend-ai/fullsend/internal/normevent"
)

// ConfigRepoName is the conventional name for the org-level fullsend
Expand Down Expand Up @@ -466,6 +468,41 @@ type ReviewComment struct {
Body string // comment body (Markdown)
}

// ReviewThreadComment is a comment belonging to a pull-request review thread.
// AuthorType is the forge's actor type (for example, "Bot" or "User").
type ReviewThreadComment struct {
Author string `json:"author"`
AuthorType string `json:"author_type"`
AuthorRole normevent.ActorRole `json:"author_role"`
AuthorRoleVerified bool `json:"author_role_verified"`
Body string `json:"body"`
CreatedAt string `json:"created_at"`
}

// ReviewThread represents the resolution state and comments of a pull-request
// review thread. Forges that do not expose review threads return
// ErrNotSupported.
type ReviewThread struct {
ID string `json:"id"`
IsResolved bool `json:"is_resolved"`
Path string `json:"path"`
Line *int `json:"line"`
OriginalLine *int `json:"original_line"`
ResolvedBy string `json:"resolved_by"`
ResolvedByType string `json:"resolved_by_type"`
ResolvedByRole normevent.ActorRole `json:"resolved_by_role"`
ResolvedByRoleVerified bool `json:"resolved_by_role_verified"`
Comments []ReviewThreadComment `json:"comments"`
CommentsTruncated bool `json:"comments_truncated"`
}

// ReviewThreadPage contains a complete fetch of a pull request's review
// threads. Truncated is true when the implementation hit its safety cap.
type ReviewThreadPage struct {
Threads []ReviewThread `json:"threads"`
Truncated bool `json:"truncated"`
}

// PullRequestFileDiff represents a file changed in a pull request along
// with its unified diff patch. The patch may be empty for binary files,
// rename-only changes, or when GitHub truncates large diffs.
Expand Down Expand Up @@ -933,6 +970,10 @@ type Client interface {
// comments, when non-nil, attaches inline diff comments to the review.
CreatePullRequestReview(ctx context.Context, owner, repo string, number int, event, body, commitSHA string, comments []ReviewComment) error
ListPullRequestReviews(ctx context.Context, owner, repo string, number int) ([]PullRequestReview, error)
// ListPullRequestReviewThreads returns review threads, including their
// resolution state and comments. It returns ErrNotSupported when the forge
// has no equivalent review-thread API.
ListPullRequestReviewThreads(ctx context.Context, owner, repo string, number int) (ReviewThreadPage, error)
DismissPullRequestReview(ctx context.Context, owner, repo string, number, reviewID int, message string) error

// Change proposal merge
Expand Down
Loading
Loading