Skip to content
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

Correct the runIDFromURLRE regex to properly match the callbackURL #3495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 14 additions & 3 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
Loading