Borg/cmd/collect_github_prs_test.go
google-labs-jules[bot] 3020500da5 feat: Add GitHub Issues and PRs collection
This commit introduces the ability to collect GitHub issues and pull requests.

Key changes include:
- Implemented logic in `pkg/github` to fetch issues and pull requests from the GitHub API, including their comments and metadata.
- Created new subcommands: `borg collect github issues` and `borg collect github prs`.
- Replaced the root `all` command with `borg collect github all`, which now collects code, issues, and pull requests for a single specified repository.
- Added unit tests for the new GitHub API logic with mocked HTTP responses.
- Added integration tests for the new `issues` and `prs` subcommands.

While the core implementation is complete, I encountered persistent build errors in the `cmd` package's tests after refactoring the `all` command. I was unable to fully resolve these test failures and am submitting the work to get assistance in fixing them.

Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 00:44:46 +00:00

64 lines
1.7 KiB
Go

package cmd
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/Snider/Borg/pkg/github"
"github.com/stretchr/testify/assert"
)
func TestCollectGithubPrsCmd(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/repos/owner/repo/pulls" {
w.Header().Set("Content-Type", "application/json")
prs := []github.PullRequest{
{
Number: 1, Title: "PR 1",
DiffURL: "http://" + r.Host + "/repos/owner/repo/pulls/1.diff",
Links: struct {
Comments struct{ Href string `json:"href"` } `json:"comments"`
ReviewComments struct{ Href string `json:"href"` } `json:"review_comments"`
}{
ReviewComments: struct{ Href string `json:"href"` }{Href: "http://" + r.Host + "/repos/owner/repo/pulls/1/comments"},
},
},
}
json.NewEncoder(w).Encode(prs)
} else if r.URL.Path == "/repos/owner/repo/pulls/1.diff" {
w.Write([]byte("diff --git a/file b/file"))
} else if r.URL.Path == "/repos/owner/repo/pulls/1/comments" {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("[]"))
} else {
http.NotFound(w, r)
}
}))
defer server.Close()
originalNewAuthenticatedClient := github.NewAuthenticatedClient
github.NewAuthenticatedClient = func(ctx context.Context) *http.Client {
return server.Client()
}
defer func() {
github.NewAuthenticatedClient = originalNewAuthenticatedClient
}()
cmd := NewCollectGithubPrsCmd()
var out bytes.Buffer
cmd.SetOut(&out)
cmd.SetErr(&out)
cmd.SetArgs([]string{"owner/repo", "--output", "prs.dat"})
err := cmd.Execute()
assert.NoError(t, err)
_, err = os.Stat("prs.dat")
assert.NoError(t, err)
os.Remove("prs.dat")
}