From 1bf7188794bf59c72e62319060ffe97103049492 Mon Sep 17 00:00:00 2001 From: pputman-clabs Date: Tue, 25 Feb 2025 12:20:09 -0600 Subject: [PATCH 1/4] correct the regex to properly match the callbackURL --- github/github.go | 3 +-- github/github_test.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/github/github.go b/github/github.go index d163b32d2cd..da42358ea44 100644 --- a/github/github.go +++ b/github/github.go @@ -1772,8 +1772,7 @@ func (fn roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { return fn(r) } -var runIDFromURLRE = regexp.MustCompile(`^repos/.*/actions/runs/(\d+)/deployment_protection_rule$`) - +var runIDFromURLRE = regexp.MustCompile(`^https://api.github.com/repos/.*/actions/runs/(\d+)/deployment_protection_rule$`) // GetRunID is a Helper Function used to extract the workflow RunID from the *DeploymentProtectionRuleEvent.DeploymentCallBackURL. func (e *DeploymentProtectionRuleEvent) GetRunID() (int64, error) { match := runIDFromURLRE.FindStringSubmatch(*e.DeploymentCallbackURL) diff --git a/github/github_test.go b/github/github_test.go index 683012adc53..118dc8580c2 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -3106,7 +3106,7 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { t.Parallel() var want int64 = 123456789 - url := "repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule" + url := "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule" e := DeploymentProtectionRuleEvent{ DeploymentCallbackURL: &url, @@ -3118,8 +3118,7 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { } want = -1 - url = "repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule" - + url = "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule" got, err := e.GetRunID() if err == nil { t.Errorf("Expected error to be returned") From ac8c9239e254b0eb290b55d76d842335dfadb753 Mon Sep 17 00:00:00 2001 From: pputman-clabs Date: Tue, 25 Feb 2025 13:00:55 -0600 Subject: [PATCH 2/4] revert regex back to not include hardcoded hostname in the url and remove the carat(^) to match any url, along with tests for both https://api.github.com along with a dummy url for enterprise Github --- github/github.go | 3 ++- github/github_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/github/github.go b/github/github.go index da42358ea44..e78810df123 100644 --- a/github/github.go +++ b/github/github.go @@ -1772,7 +1772,8 @@ func (fn roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { return fn(r) } -var runIDFromURLRE = regexp.MustCompile(`^https://api.github.com/repos/.*/actions/runs/(\d+)/deployment_protection_rule$`) +var runIDFromURLRE = regexp.MustCompile(`repos/.*/actions/runs/(\d+)/deployment_protection_rule$`) + // GetRunID is a Helper Function used to extract the workflow RunID from the *DeploymentProtectionRuleEvent.DeploymentCallBackURL. func (e *DeploymentProtectionRuleEvent) GetRunID() (int64, error) { match := runIDFromURLRE.FindStringSubmatch(*e.DeploymentCallbackURL) diff --git a/github/github_test.go b/github/github_test.go index 118dc8580c2..28cc7d17658 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -3117,6 +3117,19 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { t.Errorf("want %#v, got %#v", want, got) } + want = 123456789 + url = "https://local.dummyhost.net/repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule" + + e = DeploymentProtectionRuleEvent{ + DeploymentCallbackURL: &url, + } + + got, _ = e.GetRunID() + if got != want { + t.Errorf("want %#v, got %#v", want, got) + } + + want = -1 url = "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule" got, err := e.GetRunID() From 64f71c56234f653da0b62b3875963ce7c8c5d39e Mon Sep 17 00:00:00 2001 From: pputman-clabs Date: Tue, 25 Feb 2025 13:10:02 -0600 Subject: [PATCH 3/4] remove unnecessary whitespace --- github/github_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/github_test.go b/github/github_test.go index 28cc7d17658..64bc37ea9fe 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -3129,7 +3129,6 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { t.Errorf("want %#v, got %#v", want, got) } - want = -1 url = "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule" got, err := e.GetRunID() From 2cb7af7015aa2e2e75cbeb72c811a53c426df240 Mon Sep 17 00:00:00 2001 From: pputman-clabs Date: Tue, 25 Feb 2025 17:14:00 -0600 Subject: [PATCH 4/4] revert the url for the test for github enterprise to not include hostname --- github/github_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/github_test.go b/github/github_test.go index 64bc37ea9fe..46245ff76a6 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -3118,7 +3118,7 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { } want = 123456789 - url = "https://local.dummyhost.net/repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule" + url = "repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule" e = DeploymentProtectionRuleEvent{ DeploymentCallbackURL: &url,