Skip to content

Commit e9d8a58

Browse files
Correct the runIDFromURLRE regex to properly match the callbackURL (#3495)
1 parent a25b53e commit e9d8a58

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ func (fn roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
17721772
return fn(r)
17731773
}
17741774

1775-
var runIDFromURLRE = regexp.MustCompile(`^repos/.*/actions/runs/(\d+)/deployment_protection_rule$`)
1775+
var runIDFromURLRE = regexp.MustCompile(`repos/.*/actions/runs/(\d+)/deployment_protection_rule$`)
17761776

17771777
// GetRunID is a Helper Function used to extract the workflow RunID from the *DeploymentProtectionRuleEvent.DeploymentCallBackURL.
17781778
func (e *DeploymentProtectionRuleEvent) GetRunID() (int64, error) {

github/github_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) {
31063106
t.Parallel()
31073107

31083108
var want int64 = 123456789
3109-
url := "repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule"
3109+
url := "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule"
31103110

31113111
e := DeploymentProtectionRuleEvent{
31123112
DeploymentCallbackURL: &url,
@@ -3117,9 +3117,20 @@ func TestDeploymentProtectionRuleEvent_GetRunID(t *testing.T) {
31173117
t.Errorf("want %#v, got %#v", want, got)
31183118
}
31193119

3120-
want = -1
3121-
url = "repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule"
3120+
want = 123456789
3121+
url = "repos/dummy-org/dummy-repo/actions/runs/123456789/deployment_protection_rule"
31223122

3123+
e = DeploymentProtectionRuleEvent{
3124+
DeploymentCallbackURL: &url,
3125+
}
3126+
3127+
got, _ = e.GetRunID()
3128+
if got != want {
3129+
t.Errorf("want %#v, got %#v", want, got)
3130+
}
3131+
3132+
want = -1
3133+
url = "https://api.github.com/repos/dummy-org/dummy-repo/actions/runs/abc123/deployment_protection_rule"
31233134
got, err := e.GetRunID()
31243135
if err == nil {
31253136
t.Errorf("Expected error to be returned")

0 commit comments

Comments
 (0)