Skip to content

Commit c2c43a9

Browse files
committed
test(github): add DirectWebhook support in CRD helper
Configure CreateCRDIncoming to set up secrets and GitProvider for direct webhook tests. Sets explicit provider type to prevent the controller from assuming GitHub App mode and looking for the global pipelines-as-code-secret which doesn't exist in direct webhook scenarios. Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
1 parent 1b043c5 commit c2c43a9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/pkg/github/crd.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,38 @@ func CreateCRDIncoming(ctx context.Context, t *testing.T, repoinfo *github.Repos
8282

8383
err := repository.CreateNS(ctx, targetNS, run)
8484
assert.NilError(t, err)
85+
86+
if opts.DirectWebhook {
87+
token, _ := os.LookupEnv("TEST_GITHUB_TOKEN")
88+
webhookSecret, _ := os.LookupEnv("TEST_EL_WEBHOOK_SECRET")
89+
apiURL, _ := os.LookupEnv("TEST_GITHUB_API_URL")
90+
err := secret.Create(ctx, run,
91+
map[string]string{
92+
"webhook-secret": webhookSecret,
93+
"token": token,
94+
},
95+
targetNS,
96+
"webhook-token")
97+
assert.NilError(t, err)
98+
repo.Spec.GitProvider = &v1alpha1.GitProvider{
99+
// Type must be set explicitly so the incoming webhook handler
100+
// (adapter.detectIncoming) knows this is a direct webhook setup.
101+
// Without it, GitProvider.Type == "" causes the controller to
102+
// assume GitHub App mode and attempt to fetch the global
103+
// pipelines-as-code-secret, which doesn't exist for direct webhooks.
104+
Type: "github",
105+
URL: apiURL,
106+
Secret: &v1alpha1.Secret{
107+
Name: "webhook-token",
108+
Key: "token",
109+
},
110+
WebhookSecret: &v1alpha1.Secret{
111+
Name: "webhook-token",
112+
Key: "webhook-secret",
113+
},
114+
}
115+
}
116+
85117
err = repository.CreateRepo(ctx, targetNS, run, repo)
86118
assert.NilError(t, err)
87119
return err

0 commit comments

Comments
 (0)