Class: Organizations
- Inherits:
-
Object
- Object
- Organizations
- Defined in:
- lib/actions/orgs.rb
Instance Attribute Summary collapse
-
#assiglist ⇒ Object
Returns the value of attribute assiglist.
-
#orgslist ⇒ Object
Returns the value of attribute orgslist.
-
#peoplelist ⇒ Object
Returns the value of attribute peoplelist.
Instance Method Summary collapse
- #add_group_to_assig(client, config, assig) ⇒ Object
-
#add_people_info(client, config, file) ⇒ Object
Takes people info froma a csv file and gets into ghedsh people information.
- #add_repo_to_assig(client, config, assig) ⇒ Object
- #add_team_to_assig(client, config, assig, data) ⇒ Object
- #assignment_groups(client, config) ⇒ Object
- #assignment_repository(client, config, name) ⇒ Object
- #create_assig(client, config, name) ⇒ Object
- #get_assigs(client, config) ⇒ Object
- #get_single_assig(config, wanted) ⇒ Object
- #load_assig ⇒ Object
- #load_people ⇒ Object
- #make_assig(client, config, assig) ⇒ Object
- #open_org(client, config) ⇒ Object
- #open_user_url(client, config, user) ⇒ Object
- #read_orgs(client) ⇒ Object
- #show_assig_info(config, assig) ⇒ Object
-
#show_assignments(client, config) ⇒ Object
client,orgs.
-
#show_organization_members_bs(client, config) ⇒ Object
————End assig.
- #show_orgs(client, config) ⇒ Object
- #show_people_info(client, config, user) ⇒ Object
Instance Attribute Details
#assiglist ⇒ Object
Returns the value of attribute assiglist.
14 15 16 |
# File 'lib/actions/orgs.rb', line 14 def assiglist @assiglist end |
#orgslist ⇒ Object
Returns the value of attribute orgslist.
13 14 15 |
# File 'lib/actions/orgs.rb', line 13 def orgslist @orgslist end |
#peoplelist ⇒ Object
Returns the value of attribute peoplelist.
15 16 17 |
# File 'lib/actions/orgs.rb', line 15 def peoplelist @peoplelist end |
Instance Method Details
#add_group_to_assig(client, config, assig) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/actions/orgs.rb', line 276 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_people_info(client, config, file) ⇒ Object
Takes people info froma a csv file and gets into ghedsh people information
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/actions/orgs.rb', line 289 def add_people_info(client,config,file) list=self.load_people() ={:quote_char => "|",:headers=>true} inpeople=list["orgs"].detect{|aux| aux["name"]==config["Org"]} if inpeople==nil list["orgs"].push({"name"=>config["Org"],"users"=>[]}) Sys.new.save_people("#{ENV['HOME']}/.ghedsh",list) end if file.end_with?(".csv")==false file=file+".csv" end if File.exist?(file) begin mem = CSV.read(file,) rescue print "Invalid csv format." end fields=mem.headers users=Hash.new; users=[] puts "\nFields found: " puts fields mem.each do |i| aux=Hash.new fields.each do |j| if i[j]!=nil if GITHUB_LIST.include?(j.gsub("\"", "").downcase) aux["github"]=i[j].gsub("\"", "").strip else aux[j.gsub("\"", "").downcase]=i[j].gsub("\"", "").strip end else aux[j.gsub("\"", "").downcase]=i[j] end end users<< aux end users.each do |i| here=list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"].detect{|aux2| aux2["github"]==i["github"]} if here==nil list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"]<<i else puts "\nAlready exits \e[31m#{i["github"]}\e[0m in database" if here.eql?(i) puts "The information given is the same as in the database, changes are being discard." else puts "The information is different thant the original. Do you want to change it?" puts "\n Github:\t#{here["github"]} -> #{i["github"]}" fields.each do |j| puts " #{j} :\t\t#{here[j.gsub("\"", "").downcase]} -> #{i[j.gsub("\"", "").downcase]}" end puts "\nPress any key and enter to proceed, or only enter to skip: " op=gets.chomp if op!="" index1=list["orgs"].index{|aux| aux["name"]==config["Org"]} index2=list["orgs"][index1]["users"].index{|aux2| aux2["github"]==i["github"]} list["orgs"][index1]["users"].pop(index2) list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"]<<i puts "The information about \e[31m#{i["github"]}\e[0m has been changed" else puts "The new information about \e[31m#{i["github"]}\e[0m has been discarded" end end end end Sys.new.save_people("#{ENV['HOME']}/.ghedsh",list) else print "\n#{file} file not found.\n\n" end end |
#add_repo_to_assig(client, config, assig) ⇒ Object
402 403 404 405 406 407 408 409 410 |
# File 'lib/actions/orgs.rb', line 402 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
272 273 274 |
# File 'lib/actions/orgs.rb', line 272 def add_team_to_assig(client,config,assig,data) assig=self.get_single_assig(config,assig) end |
#assignment_groups(client, config) ⇒ Object
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 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/actions/orgs.rb', line 123 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" groupslist.each do |aux| puts "\t#{aux}" end #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 and enter to proceed, 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 "\nTeams currently available:\n\n" teamlist.each do |aux| puts "\t#{aux[0]}" end puts "\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
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 113 114 115 116 117 118 119 120 121 |
# File 'lib/actions/orgs.rb', line 57 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 "\e[31m The repository #{reponame} doesn't exist\n \e[0m" 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 puts "Name of the repository (To skip and add the repository later, press enter): " reponame=gets.chomp if reponame=="" ex2=true else ex2=Repositories.new().create_repository(client,config,reponame,false,ORGS) reponame="#{config["Org"]}/#{reponame}" end end end when op=="3" then reponame="" end return reponame end |
#create_assig(client, config, name) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/actions/orgs.rb', line 174 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/actions/orgs.rb', line 194 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 "\e[31m No assignments are available yet\e[0m" 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
213 214 215 216 217 218 |
# File 'lib/actions/orgs.rb', line 213 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_assig ⇒ Object
18 19 20 21 22 |
# File 'lib/actions/orgs.rb', line 18 def load_assig() @assiglist=Hash.new() @assiglist=Sys.new.load_assig_db("#{ENV['HOME']}/.ghedsh") return @assiglist end |
#load_people ⇒ Object
24 25 26 27 28 |
# File 'lib/actions/orgs.rb', line 24 def load_people() @peoplelist=Hash.new() @peoplelist=Sys.new.load_people_db("#{ENV['HOME']}/.ghedsh") return @peoplelist end |
#make_assig(client, config, assig) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/actions/orgs.rb', line 237 def make_assig(client,config,assig) web="https://github.com/" web2="[email protected]:" repo=Repositories.new() team=Teams.new() sys=Sys.new() teamlist=team.read_teamlist(client,config) assig=self.get_single_assig(config,assig) if assig["repo"]!="" sys.create_temp("#{ENV['HOME']}/.ghedsh/temp") #system("git clone #{web2}#{config["Org"]}/#{assig["repo"]}.git #{ENV['HOME']}/.ghedsh/#{assig["repo"]}") system("git clone #{web2}#{assig["repo"]}.git #{ENV['HOME']}/.ghedsh/temp/#{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/temp/#{assig["repo"]} remote rm origin") system("git -C #{ENV['HOME']}/.ghedsh/temp/#{assig["repo"]} remote add origin #{web2}#{config["Org"]}/#{y}-#{assig["name_assig"]}.git") system("git -C #{ENV['HOME']}/.ghedsh/temp/#{assig["repo"]} push origin --all") end end #system("rm -rf #{ENV['HOME']}/.ghedsh/temp/#{assig["repo"]}") else puts "\e[31m No repository is given for this assignment\e[0m" end end |
#open_org(client, config) ⇒ Object
449 450 451 452 453 454 455 456 457 |
# File 'lib/actions/orgs.rb', line 449 def open_org(client,config) mem=client.organization(config["Org"]) case when RUBY_PLATFORM.downcase.include?("darwin") system("open #{mem[:html_url]}") when RUBY_PLATFORM.downcase.include?("linux") system("xdg-open #{mem[:html_url]}") end end |
#open_user_url(client, config, user) ⇒ Object
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/actions/orgs.rb', line 459 def open_user_url(client,config,user) list=self.load_people() inpeople=list["orgs"].detect{|aux| aux["name"]==config["Org"]} found=0 if inpeople==nil list["orgs"].push({"name"=>config["Org"],"users"=>[]}) Sys.new.save_people("#{ENV['HOME']}/.ghedsh",list) puts "Extended information has not been added yet" else inuser=list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"].detect{|aux2| aux2["github"]==user} if inuser==nil puts "Not extended information has been added of that user." else inuser.each_value do |j| if j.include?("github.com") case when RUBY_PLATFORM.downcase.include?("darwin") system("open #{j}") when RUBY_PLATFORM.downcase.include?("linux") system("xdg-open #{j}") end found=1 end end if found==0 puts "No github web profile in the aditional information" end end end end |
#read_orgs(client) ⇒ Object
439 440 441 442 443 444 445 446 447 |
# File 'lib/actions/orgs.rb', line 439 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
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/actions/orgs.rb', line 220 def show_assig_info(config,assig) assig=self.get_single_assig(config,assig) team=Teams.new() puts "\n" puts assig["name_assig"] puts "\tRepository: #{assig["repo"]}" puts "\tGroups: " assig["groups"].each do |y| puts "\t\t#{y}" t=team.get_single_group(config,y) t.each do |z| puts "\t\t\t#{z}" end end puts "\n" end |
#show_assignments(client, config) ⇒ Object
client,orgs
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/actions/orgs.rb', line 30 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 "\tRepository: #{i["repo"]}" puts "\tGroups: " i["groups"].each do |y| puts "\t\t#{y}" 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————
413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/actions/orgs.rb', line 413 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 puts return orgslist end |
#show_orgs(client, config) ⇒ Object
426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/actions/orgs.rb', line 426 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 |
#show_people_info(client, config, user) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/actions/orgs.rb', line 366 def show_people_info(client,config,user) list=self.load_people() inpeople=list["orgs"].detect{|aux| aux["name"]==config["Org"]} peopleinfolist=[] if inpeople==nil list["orgs"].push({"name"=>config["Org"],"users"=>[]}) Sys.new.save_people("#{ENV['HOME']}/.ghedsh",list) puts "Extended information has not been added yet" else if user==nil fields=list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"][0].keys list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"].each do |i| puts "\n\e[31m#{i["github"]}\e[0m" fields.each do |j| puts "#{j.capitalize}:\t #{i[j]}" end peopleinfolist<<i["github"] end return peopleinfolist else inuser=list["orgs"].detect{|aux| aux["name"]==config["Org"]}["users"].detect{|aux2| aux2["github"]==user} if inuser==nil puts "Not extended information has been added of that user." else fields=inuser.keys puts "\n\e[31m#{inuser["github"]}\e[0m" fields.each do |j| puts "#{j.capitalize}:\t #{inuser[j]}" end puts end end end end |