Module: LitaGithub::Org

Overview

Github handler common-use Organization methods

Author:

Instance Method Summary collapse

Instance Method Details

#organization(name) ⇒ String

Uses default organization if one provided is nil or empty string

Parameters:

  • name (String, Nil)

    the name of the organization

Returns:

  • (String)

    the name of the organization to use

Author:


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

Parameters:

  • teams (Array<Teams>)

    pass in the teams you want to sort by name

Returns:

  • (Array)

    the teams but sorted by name

Author:


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

Parameters:

  • id (Integer)

    the id number for the team

Returns:

  • (Sawyer::Resource(Github team))

    if team exists

  • (FalseClass)

    if team does not exist


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

Parameters:

  • team (String, Integer)

    this is either the team's slug or the team's id

Returns:

  • (Integer)

    the team's id

Author:


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

Parameters:

  • slug (String)

    the slug of the team you're getting the ID for

  • org (String)

    the organization this team should belong in

Returns:

  • (Nil)

    if no team was found nil is returned

  • (Integer)

    if a team is found the team's ID is returned

Author:


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