From db5683d6f5f5ac13589d24d7243fd1270b209d15 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 17 Nov 2016 14:23:43 +0000 Subject: [PATCH] HACK: Have private/public fields for the webhook URL We can't just use a public field because the caller may clobber it. If they do clobber it, we've then lost the ability to set it back to what it was because we don't store another copy anywhere. This patch fixes it by keeping a private ref and always clobbering on Register(). This is horrible. We need to separate internal-storage and external-fields better. --- .../matrix-org/go-neb/services/travisci/travisci.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/services/travisci/travisci.go b/src/github.com/matrix-org/go-neb/services/travisci/travisci.go index 47c661b..5f2392d 100644 --- a/src/github.com/matrix-org/go-neb/services/travisci/travisci.go +++ b/src/github.com/matrix-org/go-neb/services/travisci/travisci.go @@ -50,8 +50,9 @@ var httpClient = &http.Client{} // } type Service struct { types.DefaultService + webhookEndpointURL string // The URL which should be added to .travis.yml - Populated by Go-NEB after Service registration. - WebhookEndpointURL string `json:"webhook_url"` + WebhookURL string `json:"webhook_url"` // A map from Matrix room ID to Github-style owner/repo repositories. Rooms map[string]struct { // A map of "owner/repo" to configuration information @@ -237,6 +238,7 @@ func (s *Service) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli // Register makes sure the Config information supplied is valid. func (s *Service) Register(oldService types.Service, client *matrix.Client) error { + s.WebhookURL = s.webhookEndpointURL for _, roomData := range s.Rooms { for repo := range roomData.Repos { match := ownerRepoRegex.FindStringSubmatch(repo) @@ -283,7 +285,7 @@ func init() { types.RegisterService(func(serviceID, serviceUserID, webhookEndpointURL string) types.Service { return &Service{ DefaultService: types.NewDefaultService(serviceID, serviceUserID, ServiceType), - WebhookEndpointURL: webhookEndpointURL, + webhookEndpointURL: webhookEndpointURL, } }) }