From 98a539bf7eed1b16c15de704460fbe04141851c1 Mon Sep 17 00:00:00 2001
From: Brad Nabholz <bnabholz@gmail.com>
Date: Mon, 3 Apr 2023 17:50:03 -0400
Subject: [PATCH 1/2] Use default branch as ref when a delete occurs

---
 services/actions/notifier_helper.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index b0e199fc6bd4e..b08827676b02d 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -127,7 +127,7 @@ func notify(ctx context.Context, input *notifyInput) error {
 	defer gitRepo.Close()
 
 	ref := input.Ref
-	if ref == "" {
+	if ref == "" || input.Event == webhook_module.HookEventDelete {
 		ref = input.Repo.DefaultBranch
 	}
 

From 52dacf0df79e6458cf077da89eb3e526a62af77a Mon Sep 17 00:00:00 2001
From: Jason Song <i@wolfogre.com>
Date: Thu, 6 Apr 2023 10:52:15 +0800
Subject: [PATCH 2/2] Update services/actions/notifier_helper.go

---
 services/actions/notifier_helper.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index b08827676b02d..a6c3ff7ee1cbd 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -127,7 +127,12 @@ func notify(ctx context.Context, input *notifyInput) error {
 	defer gitRepo.Close()
 
 	ref := input.Ref
-	if ref == "" || input.Event == webhook_module.HookEventDelete {
+	if input.Event == webhook_module.HookEventDelete {
+		// The event is deleting a reference, so it will fail to get the commit for a deleted reference.
+		// Set ref to empty string to fall back to the default branch.
+		ref = ""
+	}
+	if ref == "" {
 		ref = input.Repo.DefaultBranch
 	}