Class: TeachersPet::ClientDecorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/teachers_pet/client_decorator.rb

Instance Method Summary collapse

Instance Method Details

#add_users_to_team(organization, team, usernames) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/teachers_pet/client_decorator.rb', line 46

def add_users_to_team(organization, team, usernames)
  # Minor optimization, mostly for testing
  if usernames.any?
    team_members = self.get_team_member_logins(team[:id])
    usernames.each do |username|
      if team_members.include?(username)
        puts " -> @#{username} is already on @#{organization}/#{team[:name]}"
      else
        # https://github.com/octokit/octokit.rb/pull/518
        self.add_team_membership(team[:id], username, accept: 'application/vnd.github.the-wasp-preview+json')
        puts " -> @#{username} has been added to @#{organization}/#{team[:name]}"
      end
    end
  end
end

#create_team(organization, name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/teachers_pet/client_decorator.rb', line 38

def create_team(organization, name)
  puts "Creating team @#{organization}/#{name} ..."
  super(organization,
    name: name,
    permission: 'push'
  )
end

#existing_teams_by_name(organization) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/teachers_pet/client_decorator.rb', line 28

def existing_teams_by_name(organization)
  results = Hash.new
  teams = self.organization_teams(organization)
  teams.each do |team|
    results[team[:name]] = team
  end

  results
end

#get_team_member_logins(team_id) ⇒ Object



22
23
24
25
26
# File 'lib/teachers_pet/client_decorator.rb', line 22

def get_team_member_logins(team_id)
  self.team_members(team_id).map do |member|
    member[:login]
  end
end

#get_teams_by_name(organization) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/teachers_pet/client_decorator.rb', line 13

def get_teams_by_name(organization)
  org_teams = self.organization_teams(organization)
  teams = Hash.new
  org_teams.each do |team|
    teams[team[:name]] = team
  end
  return teams
end

#repository?(organization, repo_name) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'lib/teachers_pet/client_decorator.rb', line 5

def repository?(organization, repo_name)
  begin
    self.repository("#{organization}/#{repo_name}")
  rescue
    return false
  end
end