@@ -21,22 +21,18 @@ import (
2121	webhook_service "code.gitea.io/gitea/services/webhook" 
2222)
2323
24- // getBoolFromMap extracts a boolean value from a map with a default fallback 
25- // 
26- //nolint:unparam // defaultValue is needed for generic helper function 
27- func  getBoolFromMap (m  map [string ]any , defaultValue  bool ) bool  {
24+ // getPayloadOptimizationEnable extracts the "enable" boolean value from a payload optimization config map 
25+ func  getPayloadOptimizationEnable (m  map [string ]any ) bool  {
2826	if  val , ok  :=  m ["enable" ]; ok  {
2927		if  boolVal , ok  :=  val .(bool ); ok  {
3028			return  boolVal 
3129		}
3230	}
33- 	return  defaultValue 
31+ 	return  false 
3432}
3533
36- // getIntFromMap extracts an integer value from a map with a default fallback 
37- // 
38- //nolint:unparam // defaultValue is needed for generic helper function 
39- func  getIntFromMap (m  map [string ]any , defaultValue  int ) int  {
34+ // getPayloadOptimizationLimit extracts the "limit" integer value from a payload optimization config map 
35+ func  getPayloadOptimizationLimit (m  map [string ]any ) int  {
4036	if  val , ok  :=  m ["limit" ]; ok  {
4137		switch  v  :=  val .(type ) {
4238		case  int :
@@ -49,7 +45,7 @@ func getIntFromMap(m map[string]any, defaultValue int) int {
4945			}
5046		}
5147	}
52- 	return  defaultValue 
48+ 	return  0 
5349}
5450
5551// ListOwnerHooks lists the webhooks of the provided owner 
@@ -270,8 +266,8 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
270266			// Parse files config 
271267			if  filesConfig , ok  :=  payloadOptMap ["files" ].(map [string ]any ); ok  {
272268				payloadOptConfig .Files  =  & webhook.PayloadOptimizationItem {
273- 					Enable : getBoolFromMap (filesConfig ,  false ),
274- 					Limit :  getIntFromMap (filesConfig ,  0 ),
269+ 					Enable : getPayloadOptimizationEnable (filesConfig ),
270+ 					Limit :  getPayloadOptimizationLimit (filesConfig ),
275271				}
276272			} else  {
277273				payloadOptConfig .Files  =  & webhook.PayloadOptimizationItem {Enable : false , Limit : 0 }
@@ -280,8 +276,8 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
280276			// Parse commits config 
281277			if  commitsConfig , ok  :=  payloadOptMap ["commits" ].(map [string ]any ); ok  {
282278				payloadOptConfig .Commits  =  & webhook.PayloadOptimizationItem {
283- 					Enable : getBoolFromMap (commitsConfig ,  false ),
284- 					Limit :  getIntFromMap (commitsConfig ,  0 ),
279+ 					Enable : getPayloadOptimizationEnable (commitsConfig ),
280+ 					Limit :  getPayloadOptimizationLimit (commitsConfig ),
285281				}
286282			} else  {
287283				payloadOptConfig .Commits  =  & webhook.PayloadOptimizationItem {Enable : false , Limit : 0 }
@@ -471,8 +467,8 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
471467			// Parse files config 
472468			if  filesConfig , ok  :=  payloadOptMap ["files" ].(map [string ]any ); ok  {
473469				payloadOptConfig .Files  =  & webhook.PayloadOptimizationItem {
474- 					Enable : getBoolFromMap (filesConfig ,  false ),
475- 					Limit :  getIntFromMap (filesConfig ,  0 ),
470+ 					Enable : getPayloadOptimizationEnable (filesConfig ),
471+ 					Limit :  getPayloadOptimizationLimit (filesConfig ),
476472				}
477473			} else  {
478474				payloadOptConfig .Files  =  & webhook.PayloadOptimizationItem {Enable : false , Limit : 0 }
@@ -481,8 +477,8 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
481477			// Parse commits config 
482478			if  commitsConfig , ok  :=  payloadOptMap ["commits" ].(map [string ]any ); ok  {
483479				payloadOptConfig .Commits  =  & webhook.PayloadOptimizationItem {
484- 					Enable : getBoolFromMap (commitsConfig ,  false ),
485- 					Limit :  getIntFromMap (commitsConfig ,  0 ),
480+ 					Enable : getPayloadOptimizationEnable (commitsConfig ),
481+ 					Limit :  getPayloadOptimizationLimit (commitsConfig ),
486482				}
487483			} else  {
488484				payloadOptConfig .Commits  =  & webhook.PayloadOptimizationItem {Enable : false , Limit : 0 }
0 commit comments