Class: Organizations

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assiglistObject

Returns the value of attribute assiglist.



11
12
13
# File 'lib/actions/orgs.rb', line 11

def assiglist
  @assiglist
end

#orgslistObject

Returns the value of attribute orgslist.



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

def orgslist
  @orgslist
end

Instance Method Details

#add_group_to_assig(client, config, assig) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/actions/orgs.rb', line 260

def add_group_to_assig(client,config,assig)
  list=self.load_assig()

  groups=self.assignment_groups(client,config)
  if groups!=""
    groups.each do |i|
      list["orgs"].detect{|aux| aux["name"]==config["Org"]}["assigs"].detect{|aux2| aux2["name_assig"]==assig}["groups"].push(i)
    end
    Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
  end
end

#add_repo_to_assig(client, config, assig) ⇒ Object



273
274
275
276
277
278
279
280
281
# File 'lib/actions/orgs.rb', line 273

def add_repo_to_assig(client,config,assig)
  list=self.load_assig()

  reponame=self.assignment_repository(client,config,assig["name_assig"])
  if reponame!=""
    list["orgs"].detect{|aux| aux["name"]==config["Org"]}["assigs"].detect{|aux2| aux2["name_assig"]==assig}["repo"]=reponame
    Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
  end
end

#add_team_to_assig(client, config, assig, data) ⇒ Object



254
255
256
257
258
# File 'lib/actions/orgs.rb', line 254

def add_team_to_assig(client,config,assig,data)
  assig=self.get_single_assig(config,assig)


end

#assignment_groups(client, config) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/actions/orgs.rb', line 114

def assignment_groups(client,config)
  team=Teams.new()
  groupslist=team.get_groupslist(config)
  groupsadd=[]
  teamlist=team.read_teamlist(client,config)

  puts "\n"
  puts "Groups currently available:\n\n"
  puts groupslist
  puts "\nAdd groups to your assignment (Press enter to skip): "
  op=gets.chomp
  if op==""
    puts "Do you want to create a new group? (Press any key to preceed, or only enter to skip)"
    an=gets.chomp

    if an!=""
      time=Time.new
      puts "Put the name of the group (If you skip with enter, the group's name will be \"Group-#{time.ctime}\")"
      name=gets.chomp
      if name==""
         name="Group-#{time.ctime}"
         name=name.split(" ").join("-")
      end
      puts "Teams currently available:\n\n"
      teamlist.each do |aux|
        print "#{aux[0]} "
      end
      puts "\n\nPut a list of Teams: "

      list=gets.chomp
      list=list.split(" ")
      team.new_group(client,config,name,list)
      groupsadd.push(name)
    else
      groupsadd=[]
    end

  else
    groupsadd=op.split(" ")
    groupsadd.each do |item|
      if groupslist.detect{|aux| aux==item}==nil
        groupsadd.delete(item)
      end
    end
  end
  return groupsadd
end

#assignment_repository(client, config, name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/actions/orgs.rb', line 48

def assignment_repository(client,config,name)
  ex=false
  until ex==true
    puts "\n"
    puts "Assignment: #{name}"
    puts "1) Add a repository already created "
    puts "2) Create a new empty repository"
    puts "3) Don't assign a repository yet"
    print "option => "
    op=gets.chomp
    puts "\n"
    if op=="3" or op=="1" or op=="2"
      ex=true
    end
  end
  case
  when op=="1" || op=="2"

    if op=="1"
      ex2=false
      until ex2==true
        exname=false
        until exname==true
          puts "Name of the repository -> Owner/Repository or Organization/Repository :"
          reponame=gets.chomp
          if reponame.split("/").size!=2 and reponame!=""
            puts "Please introduce a valid format."
          else
            exname=true
          end
          if reponame==""
            exname=true
            ex2=true
          end
        end
        if reponame!=""
          if client.repository?("#{reponame}")==false
            puts "The repository #{reponame} doesn't exist\n"
            puts "\nName of the repository (To skip and add the repository later, only press enter): "
            if reponame==""
              ex2=true
            end
          else
            ex2=true
          end
        end
      end
    end
    if op=="2"
      ex2=false
      until ex2==true
        ex2=Repositories.new().create_repository(client,config,reponame,false,ORGS)
        if ex2==false
          puts "Name of the repository (To skip and add the repository later, press enter): "
          reponame=gets.chomp
          if reponame==""
            ex2=true
          end
        end
      end
    end
  when op=="3" then reponame=""
  end
  return reponame
end

#create_assig(client, config, name) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/actions/orgs.rb', line 162

def create_assig(client,config,name)
  list=self.load_assig()
  assigs=list["orgs"].detect{|aux| aux["name"]==config["Org"]}

  if assigs==nil
    list["orgs"].push({"name"=>config["Org"],"assigs"=>[]})
    Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
  end

  reponame=self.assignment_repository(client,config,name)
  groupsadd=self.assignment_groups(client,config)

  begin
    list["orgs"][list["orgs"].index{|aux| aux["name"]==config["Org"]}]["assigs"].push({"name_assig"=>name,"teams"=>[],"groups"=>groupsadd,"repo"=>reponame})
  rescue Exception => e
    puts e
  end
  Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
end

#get_assigs(client, config) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/actions/orgs.rb', line 182

def get_assigs(client,config)
  list=self.load_assig()
  assiglist=[]
  assig=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  if assig!=nil
    if assig["assigs"].empty?
      puts "No assignments are available yet"
    else
      assig["assigs"].each do |i|
        assiglist.push(i["name_assig"])
      end
    end
  else
    list["orgs"].push({"name"=>config["Org"],"assigs"=>[]})
    Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
  end
  return assiglist
end

#get_single_assig(config, wanted) ⇒ Object



201
202
203
204
205
206
# File 'lib/actions/orgs.rb', line 201

def get_single_assig(config,wanted)
  list=self.load_assig()
  as=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  as=as["assigs"].detect{|aux| aux["name_assig"]==wanted}
  return as
end

#load_assigObject



14
15
16
17
18
# File 'lib/actions/orgs.rb', line 14

def load_assig()
  @assiglist=Hash.new()
  @assiglist=Sys.new.load_assig_db("#{ENV['HOME']}/.ghedsh")
  return @assiglist
end

#make_assig(client, config, assig) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/actions/orgs.rb', line 221

def make_assig(client,config,assig)
  web="https://github.com/"
  web2="[email protected]:"
  repo=Repositories.new()
  team=Teams.new()
  teamlist=team.read_teamlist(client,config)
  assig=self.get_single_assig(config,assig)

  if assig["repo"]!=""

    #system("git clone #{web2}#{config["Org"]}/#{assig["repo"]}.git #{ENV['HOME']}/.ghedsh/#{assig["repo"]}")
    system("git clone #{web2}#{assig["repo"]}.git #{ENV['HOME']}/.ghedsh/#{assig["repo"]}")

    assig["groups"].each do |i|
      teamsforgroup=team.get_single_group(config,i)
      teamsforgroup.each do |y|
        config["TeamID"]=teamlist["#{y}"]
        config["Team"]=y
        repo.create_repository(client,config,"#{y}-#{assig["name_assig"]}",true,TEAM)
        system("git -C #{ENV['HOME']}/.ghedsh/#{assig["repo"]} remote rm origin")
        system("git -C #{ENV['HOME']}/.ghedsh/#{assig["repo"]} remote add origin #{web2}#{config["Org"]}/#{y}-#{assig["name_assig"]}.git")

        system("git -C #{ENV['HOME']}/.ghedsh/#{assig["repo"]} push origin --all")
      end
    end
    system("rm -rf #{ENV['HOME']}/.ghedsh/#{assig["repo"]}")
  else
    puts "No repository is given for this assignment"
  end


end

#read_orgs(client) ⇒ Object



309
310
311
312
313
314
315
316
317
# File 'lib/actions/orgs.rb', line 309

def read_orgs(client)
  orgslist=[]
  org=client.organizations
  org.each do |i|
    o=eval(i.inspect)
    orgslist.push(o[:login])
  end
  return orgslist
end

#show_assig_info(config, assig) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/actions/orgs.rb', line 208

def show_assig_info(config,assig)
  assig=self.get_single_assig(config,assig)
  puts "\n"
  puts assig["name_assig"]
  puts "Repository: #{assig["repo"]}"
  print "Groups: "
  assig["groups"].each do |y|
    print y
    print " "
  end
  puts "\n\n"
end

#show_assignments(client, config) ⇒ Object

client,orgs



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/actions/orgs.rb', line 20

def show_assignments(client, config) #client,orgs
  list=self.load_assig()

  assig=list["orgs"].detect{|aux| aux["name"]==config["Org"]}
  if assig!=nil
    if assig["assigs"].empty?
      puts "No assignments are available yet"
    else
      assig["assigs"].each do |i|
        puts "\n"
        puts i["name_assig"]
        puts "Repository: #{i["repo"]}"
        print "Groups: "
        i["groups"].each do |y|
          print y
          print " "
        end
        print "\n"
      end
    end
  else
    puts "No assignments are available yet"
    list["orgs"].push({"name"=>config["Org"],"assigs"=>[]})
    Sys.new.save_assigs("#{ENV['HOME']}/.ghedsh",list)
  end

end

#show_organization_members_bs(client, config) ⇒ Object

————End assig. stuff————



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/actions/orgs.rb', line 284

def show_organization_members_bs(client,config)
  orgslist=[]
  print "\n"
  mem=client.organization_members(config["Org"])
  mem.each do |i|
    m=eval(i.inspect)
    orgslist.push(m[:login])
    puts m[:login]
  end
  return orgslist
end

#show_orgs(client, config) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/actions/orgs.rb', line 296

def show_orgs(client,config)
  orgslist=[]
  print "\n"
  org=client.organizations
  org.each do |i|
    o=eval(i.inspect)
    puts o[:login]
    orgslist.push(o[:login])
  end
  print "\n"
  return orgslist
end