cli/pkg/httpmock/legacy.go
Babak K. Shandiz 5e2b2779d1
refactor(api): add IssueRepoInfo for minimal issue repo queries
Add a new IssueRepoInfo function that fetches only the fields needed
for issue creation (id, name, owner, hasIssuesEnabled, viewerPermission),
avoiding defaultBranchRef and other fields that require Contents:Read.

Also add StubIssueRepoInfoResponse helper to httpmock for testing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-09 11:30:02 +00:00

59 lines
1.5 KiB
Go

package httpmock
import (
"fmt"
)
// TODO: clean up methods in this file when there are no more callers
func (r *Registry) StubRepoInfoResponse(owner, repo, branch string) {
r.Register(
GraphQL(`query RepositoryInfo\b`),
StringResponse(fmt.Sprintf(`
{ "data": { "repository": {
"id": "REPOID",
"name": "%s",
"owner": {"login": "%s"},
"description": "",
"defaultBranchRef": {"name": "%s"},
"hasIssuesEnabled": true,
"viewerPermission": "WRITE"
} } }
`, repo, owner, branch)))
}
func (r *Registry) StubIssueRepoInfoResponse(owner, repo string) {
r.Register(
GraphQL(`query IssueRepositoryInfo\b`),
StringResponse(fmt.Sprintf(`
{ "data": { "repository": {
"id": "REPOID",
"name": "%s",
"owner": {"login": "%s"},
"hasIssuesEnabled": true,
"viewerPermission": "WRITE"
} } }
`, repo, owner)))
}
func (r *Registry) StubRepoResponse(owner, repo string) {
r.StubRepoResponseWithPermission(owner, repo, "WRITE")
}
func (r *Registry) StubRepoResponseWithPermission(owner, repo, permission string) {
r.Register(GraphQL(`query RepositoryNetwork\b`), StringResponse(RepoNetworkStubResponse(owner, repo, "master", permission)))
}
func RepoNetworkStubResponse(owner, repo, defaultBranch, permission string) string {
return fmt.Sprintf(`
{ "data": { "repo_000": {
"id": "REPOID",
"name": "%s",
"owner": {"login": "%s"},
"defaultBranchRef": {
"name": "%s"
},
"viewerPermission": "%s"
} } }
`, repo, owner, defaultBranch, permission)
}