-
Notifications
You must be signed in to change notification settings - Fork 475
Add unauthenticated REST API fallback for remote workflow imports #4106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9027f8f
0dce1b3
dc8141b
bb8319a
f47d79c
407e621
70b8221
4c638dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package parser | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestJSONParsing(t *testing.T) { | ||
| // Test SHA resolution JSON parsing | ||
| t.Run("parse SHA from commit response", func(t *testing.T) { | ||
| response := `{"sha":"1e366aa4518cf83d25defd84e454b9a41e87cf7c","node_id":"C_kwDOKr1234","commit":{"message":"test"}}` | ||
|
|
||
| var parsed struct { | ||
| SHA string `json:"sha"` | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| if err := json.Unmarshal([]byte(response), &parsed); err != nil { | ||
| t.Fatalf("Failed to parse JSON: %v", err) | ||
| } | ||
|
|
||
| if parsed.SHA != "1e366aa4518cf83d25defd84e454b9a41e87cf7c" { | ||
| t.Errorf("Expected SHA 1e366aa4518cf83d25defd84e454b9a41e87cf7c, got %s", parsed.SHA) | ||
| } | ||
| }) | ||
|
|
||
| // Test file content JSON parsing | ||
| t.Run("parse content from file response", func(t *testing.T) { | ||
| response := `{"content":"IyBUZXN0IGNvbnRlbnQ=\n","encoding":"base64","name":"test.md"}` | ||
|
|
||
| var parsed struct { | ||
| Content string `json:"content"` | ||
| Encoding string `json:"encoding"` | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| if err := json.Unmarshal([]byte(response), &parsed); err != nil { | ||
| t.Fatalf("Failed to parse JSON: %v", err) | ||
| } | ||
|
|
||
| if parsed.Encoding != "base64" { | ||
| t.Errorf("Expected encoding base64, got %s", parsed.Encoding) | ||
| } | ||
|
|
||
| if parsed.Content == "" { | ||
| t.Error("Expected non-empty content") | ||
| } | ||
| }) | ||
|
|
||
| // Test error response parsing | ||
| t.Run("parse error response", func(t *testing.T) { | ||
| response := `{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}` | ||
|
|
||
| var parsed struct { | ||
| SHA string `json:"sha"` | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| if err := json.Unmarshal([]byte(response), &parsed); err != nil { | ||
| t.Fatalf("Failed to parse JSON: %v", err) | ||
| } | ||
|
|
||
| if parsed.Message != "Not Found" { | ||
| t.Errorf("Expected message 'Not Found', got %s", parsed.Message) | ||
| } | ||
|
|
||
| if parsed.SHA != "" { | ||
| t.Errorf("Expected empty SHA for error response, got %s", parsed.SHA) | ||
| } | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,16 @@ import ( | |||||||||||||||||||
| // These functions are responsible for constructing the various jobs that make up | ||||||||||||||||||||
| // a compiled agentic workflow, including activation, main, safe outputs, and custom jobs. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // getRequiredActionPin gets an action pin and returns an error if it's not found | ||||||||||||||||||||
| // This ensures that required system actions always have pins defined | ||||||||||||||||||||
| func getRequiredActionPin(actionRepo string) (string, error) { | ||||||||||||||||||||
| pin := GetActionPin(actionRepo) | ||||||||||||||||||||
| if pin == "" { | ||||||||||||||||||||
| return "", fmt.Errorf("action pin not found for %s - this action must be added to .github/aw/actions-lock.json", actionRepo) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return pin, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+18
to
+27
|
||||||||||||||||||||
| // getRequiredActionPin gets an action pin and returns an error if it's not found | |
| // This ensures that required system actions always have pins defined | |
| func getRequiredActionPin(actionRepo string) (string, error) { | |
| pin := GetActionPin(actionRepo) | |
| if pin == "" { | |
| return "", fmt.Errorf("action pin not found for %s - this action must be added to .github/aw/actions-lock.json", actionRepo) | |
| } | |
| return pin, nil | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback detection logic only checks for specific strings in error output. This approach may be fragile and could miss authentication failures with different error messages.
Issue: The string matching uses
||(OR) logic, which means any single match triggers the fallback, but the condition checks three different patterns:"GH_TOKEN"- could appear in various contexts"authentication"- generic word that might appear in non-auth errors"not logged into"- most specific patternPotential problem: If GitHub changes its error messages or if there's a different error that happens to contain one of these strings, the fallback could be triggered incorrectly.
Recommendation: Consider making the detection more specific by:
See below for a potential fix: