test: expand routing and compact coverage
This commit is contained in:
committed by
Steve Yegge
parent
cb280b0fad
commit
12b797781d
@@ -5,6 +5,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var gitCommandRunner = func(repoPath string, args ...string) ([]byte, error) {
|
||||
cmd := exec.Command("git", args...)
|
||||
if repoPath != "" {
|
||||
cmd.Dir = repoPath
|
||||
}
|
||||
return cmd.Output()
|
||||
}
|
||||
|
||||
// UserRole represents whether the user is a maintainer or contributor
|
||||
type UserRole string
|
||||
|
||||
@@ -22,11 +30,7 @@ const (
|
||||
// 3. Fall back to contributor if uncertain
|
||||
func DetectUserRole(repoPath string) (UserRole, error) {
|
||||
// First check for explicit role in git config
|
||||
cmd := exec.Command("git", "config", "--get", "beads.role")
|
||||
if repoPath != "" {
|
||||
cmd.Dir = repoPath
|
||||
}
|
||||
output, err := cmd.Output()
|
||||
output, err := gitCommandRunner(repoPath, "config", "--get", "beads.role")
|
||||
if err == nil {
|
||||
role := strings.TrimSpace(string(output))
|
||||
if role == string(Maintainer) {
|
||||
@@ -38,18 +42,10 @@ func DetectUserRole(repoPath string) (UserRole, error) {
|
||||
}
|
||||
|
||||
// Check push access by examining remote URL
|
||||
cmd = exec.Command("git", "remote", "get-url", "--push", "origin")
|
||||
if repoPath != "" {
|
||||
cmd.Dir = repoPath
|
||||
}
|
||||
output, err = cmd.Output()
|
||||
output, err = gitCommandRunner(repoPath, "remote", "get-url", "--push", "origin")
|
||||
if err != nil {
|
||||
// Fallback to standard fetch URL if push URL fails (some git versions/configs)
|
||||
cmd = exec.Command("git", "remote", "get-url", "origin")
|
||||
if repoPath != "" {
|
||||
cmd.Dir = repoPath
|
||||
}
|
||||
output, err = cmd.Output()
|
||||
output, err = gitCommandRunner(repoPath, "remote", "get-url", "origin")
|
||||
if err != nil {
|
||||
// No remote or error - default to contributor
|
||||
return Contributor, nil
|
||||
@@ -57,13 +53,13 @@ func DetectUserRole(repoPath string) (UserRole, error) {
|
||||
}
|
||||
|
||||
pushURL := strings.TrimSpace(string(output))
|
||||
|
||||
|
||||
// Check if URL indicates write access
|
||||
// SSH URLs (git@github.com:user/repo.git) typically indicate write access
|
||||
// HTTPS with token/password also indicates write access
|
||||
if strings.HasPrefix(pushURL, "git@") ||
|
||||
strings.HasPrefix(pushURL, "ssh://") ||
|
||||
strings.Contains(pushURL, "@") {
|
||||
if strings.HasPrefix(pushURL, "git@") ||
|
||||
strings.HasPrefix(pushURL, "ssh://") ||
|
||||
strings.Contains(pushURL, "@") {
|
||||
return Maintainer, nil
|
||||
}
|
||||
|
||||
@@ -73,11 +69,11 @@ func DetectUserRole(repoPath string) (UserRole, error) {
|
||||
|
||||
// RoutingConfig defines routing rules for issues
|
||||
type RoutingConfig struct {
|
||||
Mode string // "auto" or "explicit"
|
||||
DefaultRepo string // Default repo for new issues
|
||||
MaintainerRepo string // Repo for maintainers (in auto mode)
|
||||
ContributorRepo string // Repo for contributors (in auto mode)
|
||||
ExplicitOverride string // Explicit --repo flag override
|
||||
Mode string // "auto" or "explicit"
|
||||
DefaultRepo string // Default repo for new issues
|
||||
MaintainerRepo string // Repo for maintainers (in auto mode)
|
||||
ContributorRepo string // Repo for contributors (in auto mode)
|
||||
ExplicitOverride string // Explicit --repo flag override
|
||||
}
|
||||
|
||||
// DetermineTargetRepo determines which repo should receive a new issue
|
||||
|
||||
Reference in New Issue
Block a user