Class: Lita::Handlers::GithubOrg

Inherits:
Handler
  • Object
show all
Includes:
LitaGithub::Config, LitaGithub::Filters, LitaGithub::General, LitaGithub::Octo, LitaGithub::Org
Defined in:
lib/lita/handlers/github_org.rb

Overview

GitHub Lita Handler

Constant Summary collapse

KNOWN_PERMS =
%w(pull push admin)

Instance Method Summary collapse

Methods included from LitaGithub::Filters

#func_disabled?

Methods included from LitaGithub::Org

#organization, #sort_by_name, #team?, #team_id, #team_id_by_slug

Methods included from LitaGithub::Octo

#access_token, #octo, #setup_octo

Methods included from LitaGithub::Config

#config

Methods included from LitaGithub::General

#e_opts_parse, #opts_parse

Instance Method Details

#org_team_add(response) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/lita/handlers/github_org.rb', line 93

def org_team_add(response)
  return response.reply(t('method_disabled')) if func_disabled?(__method__)

  opts = e_opts_parse(response.message.body)
  vo = validate_team_add_opts(opts)
  return response.reply(vo[:msg]) unless vo[:success]

  md = response.match_data
  org, perm, name = [organization(md['org'].strip), opts[:perms].strip.downcase, opts[:name]]

  return response.reply(
    t('org_team_add.perm_not_permitted', perms: config.org_team_add_allowed_perms.join(', '))
  ) unless permission_allowed?(perm)

  begin
    resp = octo.create_team(org, name: name, permission: perm)
  rescue Octokit::NotFound
    return response.reply(t('org_not_found', org: org))
  end

  response.reply(t('org_team_add.created_team', resp.to_h))
end

#org_team_rm(response) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/lita/handlers/github_org.rb', line 116

def org_team_rm(response)
  return response.reply(t('method_disabled')) if func_disabled?(__method__)

  md = response.match_data
  org, team = [organization(md['org'].strip), md['team'].strip]

  t_id = team_id(team, org)
  t = team?(t_id)

  return response.reply(t('team_not_found', team: team)) unless t

  if octo.delete_team(t_id)
    response.reply(t('org_team_rm.pass', t.to_h))
  else
    response.reply(t('org_team_rm.fail', t.to_h))
  end
end

#org_teams_list(response) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lita/handlers/github_org.rb', line 71

def org_teams_list(response)
  md = response.match_data
  org = md[:org].nil? ? config.default_org : organization(md[:org].strip)

  begin
    teams = octo.organization_teams(org)
  rescue Octokit::NotFound
    return response.reply(t('org_not_found', org: org))
  end

  tl = teams.length

  o = teams.shift

  reply = t('org_teams_list.header', org: org, num_teams: tl)
  reply << t('org_teams_list.team', o.to_h)

  sort_by_name(teams).each { |team| reply << t('org_teams_list.team', team.to_h) }

  response.reply(reply)
end