lib/lita/handlers/github_repo.rb in lita-github-0.0.10 vs lib/lita/handlers/github_repo.rb in lita-github-0.0.11

- old
+ new

@@ -14,10 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. require 'uri' require 'lita-github/r' +require 'lita-github/general' require 'lita-github/config' require 'lita-github/octo' require 'lita-github/org' require 'lita-github/repo' require 'lita-github/filters' @@ -25,10 +26,11 @@ module Lita # Lita Handler module Handlers # GitHub Lita Handler class GithubRepo < Handler + include LitaGithub::General # Github handler common-use methods include LitaGithub::Config # Github handler Lita configuration methods include LitaGithub::Octo # Github handler common-use Octokit methods include LitaGithub::Org # Github handler common-use Organization methods include LitaGithub::Repo # Github handler common-use Repository methods include LitaGithub::Filters # Github handler common-use method filters @@ -102,11 +104,11 @@ if repo?(rpo(org, repo)) return response.reply(t('repo_create.exists', org: org, repo: repo)) end - opts = extrapolate_create_opts(command_opts(response.args.join(' ')), org) + opts = extrapolate_create_opts(opts_parse(response.message.body), org) response.reply(create_repo(org, repo, opts)) end def repo_delete(response) @@ -243,20 +245,10 @@ end t('repo_update_homepage.updated', repo: full_name, url: resp[:homepage]) end - def command_opts(cmd) - o = {} - cmd.scan(LitaGithub::R::OPT_REGEX).flatten.compact.each do |opt| - k, v = opt.strip.split(':') - k = k.to_sym - o[k] = v unless o.key?(k) - end - o - end - def extrapolate_create_opts(opts, org) opts[:organization] = org if opts.key?(:team) t_id = team_id_by_slug(opts[:team], org) || default_team(org) @@ -269,17 +261,10 @@ opts[:private] = should_repo_be_private?(opts[:private]) opts end - def team_id_by_slug(slug, org) - octo.organization_teams(org).each do |team| - return team[:id] if team[:slug] == slug - end - nil - end - def default_team(org) config.default_team_slug.nil? ? nil : team_id_by_slug(config.default_team_slug, org) end def should_repo_be_private?(value) @@ -331,15 +316,15 @@ end reply end def gh_team(org, team) - team_id = /^\d+$/.match(team.to_s) ? team : team_id_by_slug(team, org) + t_id = team_id(team, org) - return nil if team_id.nil? + return nil if t_id.nil? begin - octo.team(team_id) + octo.team(t_id) rescue Octokit::NotFound nil end end