Repository: jenkins-x/lighthouse (go)

Issue:
Panic in util.ExternalPluginsForEvent when there is no agent configuration
```
2020/08/18 13:17:24 http: panic serving [::1]:63875: runtime error: invalid memory address or nil pointer dereference
goroutine 100 [running]:
net/http.(*conn).serve.func1(0xc0000db0e0)
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:1795 +0x139
panic(0x22c6300, 0x3399f90)
        /Users/hardy/.gvm/gos/go1.13.15/src/runtime/panic.go:679 +0x1b2
github.com/jenkins-x/lighthouse/pkg/util.ExternalPluginsForEvent(0xc0001fb790, 0x24d36bb, 0x4, 0xc0004e5f40, 0x1a, 0xc0004fb970, 0xf, 0xc0004e5f40)
        /Users/hardy/work/go/src/github.com/jenkins-x/lighthouse/pkg/util/externalplugins.go:262 +0xb4
github.com/jenkins-x/lighthouse/pkg/webhook.(*Options).handleWebHookRequests(0xc0000f0420, 0x27687c0, 0xc0004c01c0, 0xc000474200)
        /Users/hardy/work/go/src/github.com/jenkins-x/lighthouse/pkg/webhook/webhook.go:251 +0x94a
net/http.HandlerFunc.ServeHTTP(0xc000407180, 0x27687c0, 0xc0004c01c0, 0xc000474200)
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:2036 +0x44
net/http.(*ServeMux).ServeHTTP(0xc0000ec6c0, 0x27687c0, 0xc0004c01c0, 0xc000474200)
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:2416 +0x1bd
net/http.serverHandler.ServeHTTP(0xc0004c00e0, 0x27687c0, 0xc0004c01c0, 0xc000474200)
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:2831 +0xa4
net/http.(*conn).serve(0xc0000db0e0, 0x276ea80, 0xc0000eda40)
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:1919 +0x875
created by net/http.(*Server).Serve
        /Users/hardy/.gvm/gos/go1.13.15/src/net/http/server.go:2957 +0x384
```


Pull request:
fix: adding nil check for pluginConfig.Config() in util.ExternalPluginsForEvent
fixes #934

Patch:
diff --git a/pkg/util/externalplugins.go b/pkg/util/externalplugins.go
index 8626c72c..4e9753b2 100644
--- a/pkg/util/externalplugins.go
+++ b/pkg/util/externalplugins.go
@@ -253,6 +253,10 @@ func dispatch(endpoint string, payload []byte, h http.Header) error {
 // get the present event.
 func ExternalPluginsForEvent(pluginConfig *plugins.ConfigAgent, eventKind string, srcRepo string) []plugins.ExternalPlugin {
 	var matching []plugins.ExternalPlugin
+	if pluginConfig.Config() == nil {
+		return matching
+	}
+
 	srcOrg := strings.Split(srcRepo, "/")[0]
 
 	for repo, extPlugins := range pluginConfig.Config().ExternalPlugins {


Test patch:
diff --git a/pkg/util/externalplugins_test.go b/pkg/util/externalplugins_test.go
new file mode 100644
index 00000000..5d10f74b
--- /dev/null
+++ b/pkg/util/externalplugins_test.go
@@ -0,0 +1,15 @@
+package util_test
+
+import (
+	"testing"
+
+	"github.com/jenkins-x/lighthouse/pkg/plugins"
+	"github.com/jenkins-x/lighthouse/pkg/util"
+	"github.com/stretchr/testify/require"
+)
+
+func Test_ExternalPluginsForEvent_returns_empty_slice_for_nil_configuration(t *testing.T) {
+	configAgent := &plugins.ConfigAgent{}
+	plugins := util.ExternalPluginsForEvent(configAgent, util.LighthousePayloadTypeActivity, "myorg/myrepo")
+	require.Empty(t, plugins)
+}