Unified · Split
| @@ -216,6 +216,51 @@ func TestParseLocalGHAPIArgsDeclinesBehaviorChangingFlags(t *testing.T) { · 215 unmodified lines | ||
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | +func TestParseLocalGHAPIArgsAcceptedForms(t *testing.T) { | |
| 220 | + route, jqExpr, ok := parseLocalGHAPIArgs([]string{"api", "--method", "GET", "--cache", "1h", "repos/openclaw/openclaw/pulls/12", "--jq=.number"}) | |
| 221 | + if !ok || route != "repos/openclaw/openclaw/pulls/12" || jqExpr != ".number" { | |
| 222 | + t.Fatalf("parseLocalGHAPIArgs long flags = %q %q %v", route, jqExpr, ok) | |
| 223 | + } | |
| 224 | + route, jqExpr, ok = parseLocalGHAPIArgs([]string{"api", "--method=GET", "--cache=1h", "repos/openclaw/openclaw/pulls/12?foo=bar", "-q", ".title"}) | |
| 225 | + if !ok || route != "repos/openclaw/openclaw/pulls/12?foo=bar" || jqExpr != ".title" { | |
| 226 | + t.Fatalf("parseLocalGHAPIArgs equals flags = %q %q %v", route, jqExpr, ok) | |
| 227 | + } | |
| 228 | + if _, _, ok := parseLocalGHAPIArgs([]string{"api", "--method", "POST", "repos/openclaw/openclaw/pulls/12"}); ok { | |
| 229 | + t.Fatal("POST should not be locally handled") | |
| 230 | + } | |
| 231 | +} | |
| 232 | + | |
| 233 | +func TestParsePullAPIRouteAndRESTPullID(t *testing.T) { | |
| 234 | + owner, repo, number, ok := parsePullAPIRoute("/repos/openclaw/gitcrawl/pulls/42?ignored=true") | |
| 235 | + if !ok || owner != "openclaw" || repo != "gitcrawl" || number != 42 { | |
| 236 | + t.Fatalf("parsePullAPIRoute = %q %q %d %v", owner, repo, number, ok) | |
| 237 | + } | |
| 238 | + for _, route := range []string{"repos/openclaw/gitcrawl/issues/42", "repos/openclaw/gitcrawl/pulls/nope", "repos/openclaw//pulls/42"} { | |
| 239 | + if _, _, _, ok := parsePullAPIRoute(route); ok { | |
| 240 | + t.Fatalf("parsePullAPIRoute(%q) ok, want false", route) | |
| 241 | + } | |
| 242 | + } | |
| 243 | + for _, tc := range []struct { | |
| 244 | + raw any | |
| 245 | + fallback string | |
| 246 | + want any | |
| 247 | + ok bool | |
| 248 | + }{ | |
| 249 | + {float64(12), "", float64(12), true}, | |
| 250 | + {int(13), "", int(13), true}, | |
| 251 | + {int64(14), "", int64(14), true}, | |
| 252 | + {"15", "", int64(15), true}, | |
| 253 | + {"node-id", "", "node-id", true}, | |
| 254 | + {nil, "16", int64(16), true}, | |
| 255 | + {nil, "", nil, false}, | |
| 256 | + } { | |
| 257 | + got, ok := restPullID(tc.raw, tc.fallback) | |
| 258 | + if ok != tc.ok || got != tc.want { | |
| 259 | + t.Fatalf("restPullID(%#v,%q) = %#v %v, want %#v %v", tc.raw, tc.fallback, got, ok, tc.want, tc.ok) | |
| 260 | + } | |
| 261 | + } | |
| 262 | +} | |
| 263 | + | |
| 219 | 264 | func TestGHPRMergedFieldsUseRawPullDetail(t *testing.T) { |
| 220 | 265 | cache := store.PullRequestCache{ |
| 221 | 266 | Detail: store.PullRequestDetail{RawJSON: `{"merged":true,"merged_at":"2026-04-27T03:00:00Z","merge_commit_sha":"final123","auto_merge":{"enabled_by":{"login":"alice"},"merge_method":"SQUASH","commit_title":"ship it","commit_message":"details"}}`}, |