Browse Source

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.
kegan/text-logging
Kegan Dougal 8 years ago
parent
commit
db5683d6f5
  1. 6
      src/github.com/matrix-org/go-neb/services/travisci/travisci.go

6
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,
}
})
}
Loading…
Cancel
Save