Class: Teams

Inherits:
Object
  • Object
show all
Defined in:
lib/actions/teams.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTeams

Returns a new instance of Teams.



10
11
12
# File 'lib/actions/teams.rb', line 10

def initialize
  @teamlist=Hash.new
end

Instance Attribute Details

#teamlistObject

Returns the value of attribute teamlist.



8
9
10
# File 'lib/actions/teams.rb', line 8

def teamlist
  @teamlist
end

Instance Method Details

#add_to_group(config, name) ⇒ Object



193
194
# File 'lib/actions/teams.rb', line 193

def add_to_group(config,name)
end

#add_to_team(client, config, path) ⇒ Object



14
15
16
# File 'lib/actions/teams.rb', line 14

def add_to_team(client,config,path)
  client.add_team_member(config["TeamID"],path)
end

#create_team(client, config, name) ⇒ Object



31
32
33
# File 'lib/actions/teams.rb', line 31

def create_team(client,config,name)
  client.create_team(config["Org"],{:name=>name,:permission=>'push'})
end

#create_team_with_members(client, config, name, members) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/actions/teams.rb', line 35

def create_team_with_members(client,config,name,members)
  t=self.create_team(client,config,name)
  config["TeamID"]=t[:id]

    for i in 0..members.size
      self.add_to_team(client,config,members[i])
    end
end

#del_of_group(config, name) ⇒ Object



196
197
198
199
# File 'lib/actions/teams.rb', line 196

def del_of_group(config,name)
  #list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  #list["orgs"].detect{|aux| aux["name"]==config["Org"]}["groups"].delete(groups["groups"].detect{|aux2| aux2["name_group"]==name})
end

#delete_group(config, name) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/actions/teams.rb', line 168

def delete_group(config,name)
  sys=Sys.new()
  list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  groups=list["orgs"].detect{|aux| aux["name"]==config["Org"]}

  if groups!=nil
    if groups["groups"].empty?
      puts "No groups are available yet"
    else
      del=groups["groups"].detect{|aux| aux["name_group"]==name}
      if del==nil
        puts "Group not found"
      else
        puts "Group #{name} will be deleted Are your sure? (Press y to confirm)"
        op=gets.chomp
        if op=="y"
          list["orgs"].detect{|aux| aux["name"]==config["Org"]}["groups"].delete(groups["groups"].detect{|aux2| aux2["name_group"]==name})
          sys.save_groups("#{ENV['HOME']}/.ghedsh",list)
        end
      end
    end
  end

end

#delete_team(client, name) ⇒ Object



48
49
50
# File 'lib/actions/teams.rb', line 48

def delete_team(client,name)
  client.delete_team(name)
end

#get_groupslist(config) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/actions/teams.rb', line 118

def get_groupslist(config)
  sys=Sys.new()
  grouplist=[]
  list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  groups=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  groups["groups"].each do |i|
    grouplist.push(i["name_group"])
  end
  return grouplist
end

#get_single_group(config, wanted) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/actions/teams.rb', line 129

def get_single_group(config,wanted)
  sys=Sys.new()
  list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  w=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  w=w["groups"].detect{|aux| aux["name_group"]==wanted}
  return w["teams"]
end

#get_team_members(client, config, team) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/actions/teams.rb', line 75

def get_team_members(client,config,team)
  memberlist=[]
  if @teamlist.empty?
    self.read_teamlist(client,config)
  end

  if @teamlist["#{team}"]!=nil
    mem=client.team_members(@teamlist["#{team}"])
    mem.each do |i|
      m=eval(i.inspect)
      memberlist.push(m[:login])
    end
  end
  return memberlist
end

#get_teamlistObject



27
28
29
# File 'lib/actions/teams.rb', line 27

def get_teamlist()
  return @teamlist
end

#list_groups(client, config) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/actions/teams.rb', line 91

def list_groups(client,config)
  sys=Sys.new()
  list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  groups=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  if groups!=nil
    if groups["groups"].empty?
      puts "No groups are available yet"
    else
      puts "\nGroup\tTeams\tMembers"
      groups["groups"].each do |i|
        puts "\n"
        puts i["name_group"]
        i["teams"].each do |j|
            puts "\t#{j}"
            self.get_team_members(client,config,j).each do |k|
              puts "\t\t#{k}"
            end
        end
      end
    end
  else
    puts "No groups are available yet"
    list["orgs"].push({"name"=>config["Org"],"groups"=>[]})
    sys.save_groups("#{ENV['HOME']}/.ghedsh",list)
  end
end

#new_group(client, config, name, listgroups) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/actions/teams.rb', line 137

def new_group(client,config,name,listgroups)
  sys=Sys.new()
  list=sys.load_groups("#{ENV['HOME']}/.ghedsh")
  groups=list["orgs"].detect{|aux| aux["name"]==config["Org"]}

  if groups==nil
    list["orgs"].push({"name"=>config["Org"],"groups"=>[]})
    sys.save_groups("#{ENV['HOME']}/.ghedsh",list)
  end

  if @teamlist.empty?
    self.read_teamlist(client,config)
  end

  listgroups.each do |item|
    if @teamlist["#{item}"]==nil
      listgroups.delete(item)
      puts "#{item} is not a team available."
    end
  end

  if listgroups.empty? == false
    begin
      list["orgs"][list["orgs"].index{|aux| aux["name"]==config["Org"]}]["groups"].push({"name_group"=>name,"teams"=>listgroups})
    rescue Exception => e
      puts e
    end
    sys.save_groups("#{ENV['HOME']}/.ghedsh",list)
  end
end

#read_teamlist(client, config) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/actions/teams.rb', line 18

def read_teamlist(client,config)
  @teamlist=Hash.new
  mem=client.organization_teams(config["Org"])
    mem.each do |i|
      @teamlist[i.name]=i[:id]
    end
  return @teamlist
end

#show_team_members_bs(client, config) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/actions/teams.rb', line 61

def show_team_members_bs(client,config)
  print "\n"
  memberlist=[]
  mem=client.team_members(config["TeamID"])
  mem.each do |i|
    m=eval(i.inspect)
    puts m[:login]
    memberlist.push(m[:login])
  end
  print "\n"
  return memberlist
  print "\n"
end

#show_teams_bs(client, config) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/actions/teams.rb', line 52

def show_teams_bs(client,config)
  print "\n"
  mem=client.organization_teams(config["Org"])
    mem.each do |i|
      puts i.name
    end
  print "\n"
end