|
|
@ -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
|
|
|
|
// 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 == "" { |
|
|
|
return fmt.Errorf("RealmID is required") |
|
|
|
} |
|
|
@ -250,16 +250,18 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
|
|
|
|
|
// Fetch the old service list and work out the difference between the two.
|
|
|
|
var oldRepos []string |
|
|
|
if oldService != nil { |
|
|
|
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") |
|
|
|
}).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
|
|
|
|
newRepos, _ := util.Difference(reposForWebhooks, oldRepos) |
|
|
@ -272,6 +274,10 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
|
} |
|
|
|
logger.Info("Created webhook") |
|
|
|
} |
|
|
|
|
|
|
|
if err := s.joinWebhookRooms(client); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.Infof("%+v", s) |
|
|
@ -279,6 +285,16 @@ func (s *githubService) Register(oldService types.Service) error { |
|
|
|
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 { |
|
|
|
var repos []string |
|
|
|
if s.Rooms == nil { |
|
|
|