diff --git a/github/github.go b/github/github.go index d163b32d2cd..e78810df123 100644 --- a/github/github.go +++ b/github/github.go @@ -1772,7 +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(`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) { diff --git a/github/github_test.go b/github/github_test.go index 683012adc53..46245ff76a6 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, @@ -3117,9 +3117,20 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) { t.Errorf("want %#v, got %#v", want, got) } - want = -1 - url = "repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule" + want = 123456789 + url = "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() if err == nil { t.Errorf("Expected error to be returned")