lib/lita/handlers/github_repo.rb in lita-github-0.1.2 vs lib/lita/handlers/github_repo.rb in lita-github-0.2.0

- old
+ new

@@ -275,27 +275,39 @@ 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) + first_team, other_teams = filter_teams(default_teams(org)) + + begin + t_id = team_id_by_slug(opts.fetch(:team), org) + rescue KeyError + t_id = first_team + opts[:other_teams] = other_teams unless other_teams.empty? + ensure opts[:team_id] = t_id unless t_id.nil? - else - t_id = default_team(org) - opts[:team_id] = t_id unless t_id.nil? end unless opts.key?(:team_id) opts[:private] = should_repo_be_private?(opts[:private]) opts end - def default_team(org) - config.default_team_slug.nil? ? nil : team_id_by_slug(config.default_team_slug, org) + def filter_teams(teams) + [teams.first, teams[1..-1].reject(&:nil?)] # Filter invalid team IDs end + def default_teams(org) + teams = config.default_team_slugs + # If default_team_slugs is either a non-array (e.g. nil) or an empty + # array, return an array containing nil + return [nil] if !teams.is_a?(Array) || teams.empty? + # If it's a populated array, return an array of corresponding team IDs + teams.map { |team| team_id_by_slug(team, org) } + end + def should_repo_be_private?(value) if value.nil? || value.empty? config.repo_private_default else privacy_decider(value) @@ -306,19 +318,22 @@ case value.downcase when 'true' true when 'false' false - else # when some invalud value... + else # when some invalid value... config.repo_private_default end end def create_repo(org, repo, opts) full_name = rpo(org, repo) reply = nil begin octo.create_repository(repo, opts) + opts[:other_teams].each do |team| + add_team_to_repo(full_name, team) + end if opts.key?(:other_teams) ensure if repo?(full_name) repo_url = "https://github.com/#{full_name}" reply = t('repo_create.pass', org: org, repo: repo, repo_url: repo_url) else