Module: LitaGithub::Org
- Included in:
- Lita::Handlers::GithubIssues, Lita::Handlers::GithubOrg, Lita::Handlers::GithubPR, Lita::Handlers::GithubRepo
- Defined in:
- lib/lita-github/org.rb
Overview
Github handler common-use Organization methods
Instance Method Summary collapse
-
#organization(name) ⇒ String
Uses default organization if one provided is nil or empty string.
-
#sort_by_name(teams) ⇒ Array
Sorts a list of Github team objects by name.
-
#team?(id) ⇒ Sawyer::Resource(Github team), FalseClass
Check if a team exists.
-
#team_id(team, org) ⇒ Integer
Get the team id based on either the team slug or the team id.
-
#team_id_by_slug(slug, org) ⇒ Nil, Integer
Get the Github team ID using its slug.
Instance Method Details
#organization(name) ⇒ String
Uses default organization if one provided is nil or empty string
27 28 29 |
# File 'lib/lita-github/org.rb', line 27 def organization(name) name.nil? || name.empty? ? config.default_org : name end |
#sort_by_name(teams) ⇒ Array
Sorts a list of Github team objects by name
36 37 38 |
# File 'lib/lita-github/org.rb', line 36 def sort_by_name(teams) teams.sort_by { |h| h[:name].downcase } end |
#team?(id) ⇒ Sawyer::Resource(Github team), FalseClass
Check if a team exists
70 71 72 73 74 |
# File 'lib/lita-github/org.rb', line 70 def team?(id) octo.team(id) rescue Octokit::NotFound false end |
#team_id(team, org) ⇒ Integer
Get the team id based on either the team slug or the team id
61 62 63 |
# File 'lib/lita-github/org.rb', line 61 def team_id(team, org) /^\d+$/.match(team.to_s) ? team : team_id_by_slug(team, org) end |
#team_id_by_slug(slug, org) ⇒ Nil, Integer
Get the Github team ID using its slug
This depends on the ‘octo()` method from LitaGithub::Octo being within the same scope
49 50 51 52 53 54 |
# File 'lib/lita-github/org.rb', line 49 def team_id_by_slug(slug, org) octo.organization_teams(org).each do |team| return team[:id] if team[:slug] == slug end nil end |