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