|
@ -221,7 +221,7 @@ func (s *githubService) OnReceiveWebhook(w http.ResponseWriter, req *http.Reques |
|
|
//
|
|
|
//
|
|
|
// Hooks can get out of sync if a user manually deletes a hook in the Github UI. In this case, toggling the repo configuration will
|
|
|
// Hooks can get out of sync if a user manually deletes a hook in the Github UI. In this case, toggling the repo configuration will
|
|
|
// force NEB to recreate the hook.
|
|
|
// force NEB to recreate the hook.
|
|
|
func (s *githubService) Register(oldService types.Service) error { |
|
|
|
|
|
|
|
|
func (s *githubService) Register(oldService types.Service, client *matrix.Client) error { |
|
|
if s.RealmID == "" { |
|
|
if s.RealmID == "" { |
|
|
return fmt.Errorf("RealmID is required") |
|
|
return fmt.Errorf("RealmID is required") |
|
|
} |
|
|
} |
|
@ -250,15 +250,17 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
|
|
|
|
|
|
// Fetch the old service list and work out the difference between the two.
|
|
|
// Fetch the old service list and work out the difference between the two.
|
|
|
var oldRepos []string |
|
|
var oldRepos []string |
|
|
old, ok := oldService.(*githubService) |
|
|
|
|
|
if !ok { |
|
|
|
|
|
log.WithFields(log.Fields{ |
|
|
|
|
|
"service_id": oldService.ServiceID(), |
|
|
|
|
|
"service_type": oldService.ServiceType(), |
|
|
|
|
|
}).Print("Cannot case old github service to GithubService") |
|
|
|
|
|
// non-fatal though, we'll just make the hooks
|
|
|
|
|
|
} else { |
|
|
|
|
|
oldRepos = old.repoList() |
|
|
|
|
|
|
|
|
if oldService != nil { |
|
|
|
|
|
old, ok := oldService.(*githubService) |
|
|
|
|
|
if !ok { |
|
|
|
|
|
log.WithFields(log.Fields{ |
|
|
|
|
|
"service_id": oldService.ServiceID(), |
|
|
|
|
|
"service_type": oldService.ServiceType(), |
|
|
|
|
|
}).Print("Cannot cast old github service to GithubService") |
|
|
|
|
|
// non-fatal though, we'll just make the hooks
|
|
|
|
|
|
} else { |
|
|
|
|
|
oldRepos = old.repoList() |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Add the repos in the new service but not the old service
|
|
|
// Add the repos in the new service but not the old service
|
|
@ -272,6 +274,10 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
} |
|
|
} |
|
|
logger.Info("Created webhook") |
|
|
logger.Info("Created webhook") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := s.joinWebhookRooms(client); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.Infof("%+v", s) |
|
|
log.Infof("%+v", s) |
|
@ -279,6 +285,16 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *githubService) joinWebhookRooms(client *matrix.Client) error { |
|
|
|
|
|
for roomID := range s.Rooms { |
|
|
|
|
|
if _, err := client.JoinRoom(roomID, ""); err != nil { |
|
|
|
|
|
// TODO: Leave the rooms we successfully joined?
|
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (s *githubService) repoList() []string { |
|
|
func (s *githubService) repoList() []string { |
|
|
var repos []string |
|
|
var repos []string |
|
|
if s.Rooms == nil { |
|
|
if s.Rooms == nil { |
|
|