Skip to content

Commit 9b93714

Browse files
Copilotpelikhan
andauthored
fix: honor default GH host for pin fallback guard
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 30ea576 commit 9b93714

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

pkg/workflow/compiler_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,11 @@ func (d *WorkflowData) PinContext() *actionpins.PinContext {
644644
if ghHost := os.Getenv("GH_HOST"); ghHost != "" && ghHost != "github.com" {
645645
pinCtx.SkipHardcodedFallback = true
646646
}
647+
// Also disable fallback when a non-github.qkg1.top default host has been set
648+
// programmatically (for example from auto-detected git remotes).
649+
if defaultHost := getDefaultGHHost(); defaultHost != "" && defaultHost != "github.com" {
650+
pinCtx.SkipHardcodedFallback = true
651+
}
647652
return pinCtx
648653
}
649654

pkg/workflow/compiler_types_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
)
1212

1313
func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
14+
originalDefaultHost := getDefaultGHHost()
15+
t.Cleanup(func() {
16+
SetDefaultGHHost(originalDefaultHost)
17+
})
18+
1419
t.Run("sets SkipHardcodedFallback when GH_HOST is a non-github.qkg1.top host", func(t *testing.T) {
1520
t.Setenv("GH_HOST", "myorg.ghe.com")
1621

@@ -33,6 +38,7 @@ func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
3338

3439
t.Run("does not set SkipHardcodedFallback when GH_HOST is not set", func(t *testing.T) {
3540
require.NoError(t, os.Unsetenv("GH_HOST"))
41+
SetDefaultGHHost("")
3642

3743
d := &WorkflowData{}
3844
ctx := d.PinContext()
@@ -41,6 +47,28 @@ func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
4147
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when GH_HOST is not set")
4248
})
4349

50+
t.Run("sets SkipHardcodedFallback when default GH host is a non-github.qkg1.top host", func(t *testing.T) {
51+
require.NoError(t, os.Unsetenv("GH_HOST"))
52+
SetDefaultGHHost("myorg.ghe.com")
53+
54+
d := &WorkflowData{}
55+
ctx := d.PinContext()
56+
57+
require.NotNil(t, ctx)
58+
assert.True(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be true when default GH host is a GHE host")
59+
})
60+
61+
t.Run("does not set SkipHardcodedFallback when default GH host is github.com", func(t *testing.T) {
62+
require.NoError(t, os.Unsetenv("GH_HOST"))
63+
SetDefaultGHHost("github.com")
64+
65+
d := &WorkflowData{}
66+
ctx := d.PinContext()
67+
68+
require.NotNil(t, ctx)
69+
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when default GH host is github.com")
70+
})
71+
4472
t.Run("returns nil for nil WorkflowData", func(t *testing.T) {
4573
var d *WorkflowData
4674
ctx := d.PinContext()

0 commit comments

Comments
 (0)