         
 
 getMembers = (community, callback) ->
-  ghAdmin = github.client nconf.get "GIHUB_ADMIN_TOKEN"
-  ghAdmin.get "/orgs/communities/teams", (err, status, teams) ->
+  getGitHubTeams (err, teams) ->
     console.log("teams", teams);
     if err 
       callback err

app.post "/communities/:community/join", (req, res) ->
  community = req.params.community
  ghAdmin = github.client nconf.get "GIHUB_ADMIN_TOKEN"
  ghAdmin.get "/orgs/communities/teams", (err, status, teams) ->
    console.log("teams", teams);
    membersTeam = team for team in teams when team.name == "#{community}-members"
    console.log "membersTeam", membersTeam

    adminsTeam = team for team in teams when team.name == "#{community}-admins"
    workers = {}
    if membersTeam
      workers.members = async.apply getGitHubTeamMembers, membersTeam.id
    if adminsTeam
      workers.admins = async.apply getGitHubTeamMembers, adminsTeam.id
    async.parallel workers, callback  

getGitHubTeamMembers = (id, callback) ->
  ghAdmin = github.client nconf.get "GIHUB_ADMIN_TOKEN"
  ghAdmin.get "/teams/#{id}/members", {}, (err, status, members) ->
  if err
    callback err
    return
  callback undefined, members 


getGitHubTeams = (callback) ->
  ghAdmin = github.client nconf.get "GIHUB_ADMIN_TOKEN"
  ghAdmin.get "/orgs/communities/teams", (err, status, teams) ->
    callback err, teams

getTopicMeta = (community, topic, callback) ->
  github.client().get "/repos/communities/#{community}/git/refs/heads/#{topic}", {}, (err, status, ref) ->
