github.com/argoproj/argo-events@v1.9.1/eventsources/sources/github/hook_util.go (about)

     1  package github
     2  
     3  import (
     4  	gh "github.com/google/go-github/v50/github"
     5  
     6  	"github.com/argoproj/argo-events/common"
     7  )
     8  
     9  // compareHook returns true if the hook matches the url and event.
    10  func compareHook(hook *gh.Hook, url string, events []string) bool {
    11  	if hook == nil {
    12  		return false
    13  	}
    14  
    15  	if hook.Config["url"] != url {
    16  		return false
    17  	}
    18  
    19  	// Webhook events are equal if both old events slice and new events slice
    20  	// contain the same events, or if both have "*" event.
    21  	return common.ElementsMatch(hook.Events, events) ||
    22  		(common.SliceContains(hook.Events, "*") && common.SliceContains(events, "*"))
    23  }
    24  
    25  // getHook returns the hook that matches the url and event, or nil if not found.
    26  func getHook(hooks []*gh.Hook, url string, event []string) *gh.Hook {
    27  	for _, hook := range hooks {
    28  		if compareHook(hook, url, event) {
    29  			return hook
    30  		}
    31  	}
    32  
    33  	return nil
    34  }