[WIP] Add fallback to unauthenticated REST API call#3957
[WIP] Add fallback to unauthenticated REST API call#3957
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add ExecGHWithRESTFallback function that attempts gh CLI first, then falls back to direct REST API calls - Implement callGitHubRESTAPI for unauthenticated GitHub API requests - Implement applyJQFilter for basic jq-style field extraction - Update action_resolver.go to use REST API fallback when resolving action SHAs - Add comprehensive unit tests for jq filtering and fallback logic - Add integration tests (skip in restricted environments) - All existing tests continue to pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Change cmd.Output() to cmd.CombinedOutput() to capture gh CLI messages - Check both combined output and stderr for authentication error indicators - Add check for "GH_TOKEN" string in output (gh CLI's auth error message) - Fix error return to use exitErr instead of err for consistency - All unit tests pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot keep working |
After merge with main, action_pins.json now contains 20 entries instead of 18. Updated TestGetActionPinsSorting to reflect the current count. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed failing test after merge with main. All unit tests now pass ✅ (commit 14bee46) Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
pkg/workflow/gh_helper.go
Outdated
| // Usage: | ||
| // | ||
| // output, fromREST, err := ExecGHWithRESTFallback("api", "/repos/actions/checkout/git/ref/tags/v4", "--jq", ".object.sha") | ||
| func ExecGHWithRESTFallback(args ...string) ([]byte, bool, error) { |
There was a problem hiding this comment.
@copilot this helper only applies to gh api so specialize it.
There was a problem hiding this comment.
Specialized function for gh api commands only. Renamed to ExecGHAPIWithRESTFallback(apiPath, jqFilter) with explicit parameters instead of generic args. (commit 6d148ce)
Renamed to ExecGHAPIWithRESTFallback with specialized signature: - Removed generic args parameter - Now requires apiPath and jqFilter as explicit parameters - Function signature makes it clear this is only for API calls - Updated all usages in action_resolver.go and tests - Removed obsolete tests for non-API commands - All unit tests pass ✅ Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Task: Add REST API Fallback for GitHub API Calls ✅
Add fallback to unauthenticated REST API calls when GitHub token is not available.
Completed ✅
gh apicommandExecGHwrapper with fallback capabilityImplementation Summary
Core Changes:
pkg/workflow/gh_helper.go- Added REST API fallback functions:ExecGHAPIWithRESTFallback(apiPath, jqFilter)- Specialized for gh api commandscallGitHubRESTAPI()- Makes unauthenticated HTTP GET requestsapplyJQFilter()- Simple jq-style JSON field extractionpkg/workflow/action_resolver.go- Updated to use REST fallback:resolveFromGitHub()to callExecGHAPIWithRESTFallback()Test Coverage:
How It Works
gh api <path>with optional --jq filterFunction Signature
The specialized signature makes it clear this function is only for GitHub API calls, removing the need for runtime validation of command type.
Limitations
.object.sha,.name.nested.field)Testing Notes
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.