Class: Organization
- Inherits:
-
Object
- Object
- Organization
- Defined in:
- lib/actions/orgs.rb
Overview
Class containing actions available inside an organization
Class Method Summary collapse
-
.shell_prompt(config) ⇒ Object
CLI prompt, info about the current (CLI) scope.
Instance Method Summary collapse
-
#add_members(client, config, members) ⇒ Object
Add members typing them separately.
-
#add_members_from_file(client, config, path) ⇒ Object
Add members from file (JSON).
-
#build_cd_syntax(type, name) ⇒ Object
Builds final cd syntax.
-
#cd(type, name, client, enviroment) ⇒ Object
cd method contains a hash representing where user can navigate depending on context.
-
#cd_repo(name, client, enviroment) ⇒ ShellContext
perform cd to repo scope, if ‘name’ is a Regexp, matches are stored and then we let the user select one if is not a Regexp, check that the string provided is a vale repository name.
-
#cd_team(name, client, enviroment) ⇒ ShellContext
perform cd to team scope, first we retrieve all user’s orgs, then we check ‘name’ if its a Regexp then matches are displayed on screen and user selects one (if no match warning is shown and we return nil) if ‘name’ is not a Regexp then it must be the full team’s name so we check that is inside org_teams Last option is showing a warning and return nil (so we dont push to the stack_context).
-
#change_to_private_repo(client, config, params) ⇒ Object
Set organization repos privacy to private.
-
#change_to_public_repo(client, config, params) ⇒ Object
Set organization repos privacy to public.
-
#clone_repository(enviroment, repo_name, custom_path) ⇒ Object
Clone a repository, if repo_name is Regexp it will clone all org repositories matching pattern if repo_name is String searches for that repo and clones it.
-
#create_issue(config) ⇒ Object
Open default browser ready to create an issue with GitHub form.
-
#create_repo(enviroment, repo_name, options) ⇒ Object
Repo creation: creates new repo inside current org.
-
#create_team(client, config, params) ⇒ Object
Team creation: opens team creation page on default browser when calling new_team with no options.
-
#delete_member(client, config, param) ⇒ Object
Removes a group of members form current organization.
-
#foreach_eval(client, config, params) ⇒ Object
Evaluate a bash command in each submodule.
- #foreach_try(client, config, params) ⇒ Object
-
#invite_all_outside_collaborators(client, config, param) ⇒ Object
Invite as members all outside collaborators from organization.
-
#new_eval(client, config, params) ⇒ Object
Create a ‘super repo’ containing assignment repositories as submodules.
-
#open_info(config, params, client) ⇒ Object
Open info on default browser.
- #read_orgs(client) ⇒ Object
-
#remove_org_member ⇒ Object
Removes a group of GitHub users from an organization.
-
#remove_repo(enviroment, repo_name) ⇒ Object
Removes repository by name.
-
#remove_team(config) ⇒ Object
Open org’s team list and delete manually (faster than checking teams IDs and delete it).
- #repo_has_submodules?(client, config) ⇒ Boolean
-
#show_commits(enviroment, params) ⇒ Object
Show commits of current repo.
-
#show_files(client, config, params) ⇒ Object
Display files and directories within a repository.
-
#show_issues(config) ⇒ Object
Open default browser and shows open issues.
-
#show_people(client, config, params) ⇒ Object
Display organization people.
-
#show_repos(client, config, params) ⇒ Object
Display organization repos.
-
#show_teams(client, config, params) ⇒ Object
Display organization teams.
Class Method Details
.shell_prompt(config) ⇒ Object
CLI prompt, info about the current (CLI) scope
16 17 18 19 20 21 22 |
# File 'lib/actions/orgs.rb', line 16 def self.shell_prompt(config) if config['Repo'].nil? Rainbow("#{config['User']}> ").aqua << Rainbow("#{config['Org']}> ").magenta else Rainbow("#{config['User']}> ").aqua << Rainbow("#{config['Org']}> ").magenta << Rainbow("#{config['Repo']}> ").color(236, 151, 21) end end |
Instance Method Details
#add_members(client, config, members) ⇒ Object
Add members typing them separately
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/actions/orgs.rb', line 326 def add_members(client, config, members) if members.empty? puts Rainbow('Please type each member you would like to add.').color(INFO_CODE) else people = split_members(members) spinner = custom_spinner('Adding member(s) :spinner ...') people.each do |i| = { role: 'member', user: i.to_s } client.update_organization_membership(config['Org'].to_s, ) end spinner.stop(Rainbow('done!').color(4, 255, 0)) end rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) end |
#add_members_from_file(client, config, path) ⇒ Object
Add members from file (JSON). File must be located somewhere in HOME.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/actions/orgs.rb', line 346 def add_members_from_file(client, config, path) file_path = "#{Dir.home}#{path}" members_json = File.read(file_path) members_file = JSON.parse(members_json) spinner = custom_spinner('Adding members from file :spinner ...') members_file['members'].each do |member| = { role: 'member', user: member['id'].to_s } client.update_organization_membership(config['Org'].to_s, ) end spinner.stop(Rainbow('done!').color(4, 255, 0)) rescue Errno::ENOENT puts Rainbow('Could not open file, check file location.').color(ERROR_CODE) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) end |
#build_cd_syntax(type, name) ⇒ Object
Builds final cd syntax. Transforms user’s CLI input to valid Ruby expression doing some parsing.
28 29 30 31 32 33 34 35 |
# File 'lib/actions/orgs.rb', line 28 def build_cd_syntax(type, name) syntax_map = { 'repo' => "Organization.new.cd('repo', #{name}, client, env)", 'team' => "Organization.new.cd('team', #{name}, client, env)" } unless syntax_map.key?(type) raise Rainbow("cd #{type} currently not supported.").color(ERROR_CODE) end syntax_map[type] end |
#cd(type, name, client, enviroment) ⇒ Object
cd method contains a hash representing where user can navigate depending on context. In this case
inside an organization user is allowed to change to a org repo and org team.
In order to add new 'cd types' see example below.
615 616 617 618 |
# File 'lib/actions/orgs.rb', line 615 def cd(type, name, client, enviroment) cd_scopes = { 'repo' => method(:cd_repo), 'team' => method(:cd_team) } cd_scopes[type].call(name, client, enviroment) end |
#cd_repo(name, client, enviroment) ⇒ ShellContext
perform cd to repo scope, if ‘name’ is a Regexp, matches are stored and then we let the user select one
if is not a Regexp, check that the string provided is a vale repository name
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/actions/orgs.rb', line 514 def cd_repo(name, client, enviroment) if name.class == Regexp pattern = Regexp.new(name.source, name.) org_repos = [] org_repos_url = {} spinner = custom_spinner("Matching #{enviroment.config['Org']} repositories :spinner ...") spinner.auto_spin client.organization_repositories(enviroment.config['Org'].to_s).each do |org_repo| if pattern.match(org_repo[:name].to_s) org_repos << org_repo[:name] org_repos_url[org_repo[:name].to_s] = org_repo[:html_url] end end spinner.stop(Rainbow('done!').color(4, 255, 0)) if org_repos.empty? puts Rainbow("No repository matched with #{name.source} inside organization #{enviroment.config['Org']}").color(WARNING_CODE) puts return else prompt = TTY::Prompt.new answer = prompt.select('Select desired organization repository', org_repos) enviroment.config['Repo'] = answer enviroment.config['repo_url'] = org_repos_url[answer] enviroment.deep = Organization end else if client.repository?("#{enviroment.config['Org']}/#{name}") org_repo_url = 'https://github.com/' << enviroment.config['Org'].to_s << '/' << name.to_s enviroment.config['Repo'] = name enviroment.config['repo_url'] = org_repo_url enviroment.deep = Organization else puts Rainbow("Maybe #{name} is not an organizaton or currently does not exist.").color(WARNING_CODE) return end end enviroment end |
#cd_team(name, client, enviroment) ⇒ ShellContext
perform cd to team scope, first we retrieve all user’s orgs, then we check ‘name’
if its a Regexp then matches are displayed on screen and user selects one (if no match warning
is shown and we return nil)
if 'name' is not a Regexp then it must be the full team's name so we check that is inside org_teams
Last option is showing a warning and return nil (so we dont push to the stack_context)
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/actions/orgs.rb', line 563 def cd_team(name, client, enviroment) org_teams = [] org_teams_id = {} spinner = custom_spinner("Fetching #{enviroment.config['Org']} teams :spinner ...") spinner.auto_spin client.organization_teams(enviroment.config['Org'].to_s).each do |team| org_teams << team[:name] org_teams_id[team[:name].to_s] = team[:id] end spinner.stop(Rainbow('done!').color(4, 255, 0)) if name.class == Regexp pattern = Regexp.new(name.source, name.) name_matches = [] org_teams.each do |team_name| name_matches << team_name if pattern.match(team_name.to_s) end if name_matches.empty? puts Rainbow("No team matched with \/#{name.source}\/ inside organization #{enviroment.config['Org']}").color(WARNING_CODE) puts return else prompt = TTY::Prompt.new answer = prompt.select('Select desired organization', name_matches) enviroment.config['Team'] = answer enviroment.config['TeamID'] = org_teams_id[answer] enviroment.config['team_url'] = 'https://github.com/orgs/' << enviroment.config['Org'] << '/teams/' << enviroment.config['Team'] enviroment.deep = Team end else if org_teams.include?(name) enviroment.config['Team'] = name enviroment.config['TeamID'] = org_teams_id[name] enviroment.config['team_url'] = 'https://github.com/orgs/' << enviroment.config['Org'] << '/teams/' << enviroment.config['Team'] enviroment.deep = Team else puts Rainbow("Maybe #{name} is not a #{enviroment.config['Org']} team or currently does not exist.").color(WARNING_CODE) puts return end end enviroment end |
#change_to_private_repo(client, config, params) ⇒ Object
Set organization repos privacy to private. You need a paid plan to set private repos inside an organization
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/actions/orgs.rb', line 101 def change_to_private_repo(client, config, params) pattern = build_regexp_from_string(params) spinner = custom_spinner('Setting private repos :spinner ...') spinner.auto_spin repos = [] client.organization_repositories(config['Org'].to_s).each do |repo| repos.push(repo[:name]) if pattern.match(repo[:name]) end repos.each do |i| client.set_private("#{config['Org']}/#{i}") end spinner.stop(Rainbow('done!').color(4, 255, 0)) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) end |
#change_to_public_repo(client, config, params) ⇒ Object
Set organization repos privacy to public.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/actions/orgs.rb', line 122 def change_to_public_repo(client, config, params) pattern = build_regexp_from_string(params) spinner = custom_spinner('Setting public repos :spinner ...') spinner.auto_spin repos = [] client.organization_repositories(config['Org'].to_s).each do |repo| repos.push(repo[:name]) if pattern.match(repo[:name]) end repos.each do |i| client.set_public("#{config['Org']}/#{i}") end spinner.stop(Rainbow('done!').color(4, 255, 0)) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) end |
#clone_repository(enviroment, repo_name, custom_path) ⇒ Object
Clone a repository, if repo_name is Regexp it will clone all org repositories matching pattern
if repo_name is String searches for that repo and clones it
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/actions/orgs.rb', line 274 def clone_repository(enviroment, repo_name, custom_path) client = enviroment.client config = enviroment.config repos_to_clone = [] if repo_name.include?('/') pattern = build_regexp_from_string(repo_name) client.organization_repositories(config['Org'].to_s).each do |repo| repos_to_clone << { name: repo[:name], ssh_url: repo[:clone_url] } if pattern.match(repo[:name]) end puts Rainbow("No repository matched \/#{pattern.source}\/").color(INFO_CODE) if repos_to_clone.empty? else repo = client.repository("#{config['Org']}/#{repo_name}") repos_to_clone << { name: repo[:name], ssh_url: repo[:clone_url] } end unless repos_to_clone.empty? perform_git_clone(repos_to_clone, custom_path) if custom_path.nil? puts Rainbow("Cloned into #{Dir.pwd}").color(INFO_CODE).underline else puts Rainbow("Cloned into #{Dir.home}#{custom_path}").color(INFO_CODE).underline end puts end rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) puts end |
#create_issue(config) ⇒ Object
Open default browser ready to create an issue with GitHub form.
307 308 309 310 311 312 313 314 |
# File 'lib/actions/orgs.rb', line 307 def create_issue(config) if config['Repo'] issue_creation_url = "https://github.com/#{config['Org']}/#{config['Repo']}/issues/new" open_url(issue_creation_url) else puts Rainbow('Change to repo in order to create an issue.').color(INFO_CODE) end end |
#create_repo(enviroment, repo_name, options) ⇒ Object
Repo creation: creates new repo inside current org
661 662 663 664 665 666 667 668 669 |
# File 'lib/actions/orgs.rb', line 661 def create_repo(enviroment, repo_name, ) client = enviroment.client [:organization] = enviroment.config['Org'].to_s client.create_repository(repo_name, ) puts Rainbow('Repository created correctly!').color(79, 138, 16) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) puts end |
#create_team(client, config, params) ⇒ Object
Team creation: opens team creation page on default browser when calling new_team
with no options. If option provided, it must be the directory and name of the JSON file
somewhere in your HOME directory for bulk creation of teams and members.
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/actions/orgs.rb', line 700 def create_team(client, config, params) if params.nil? team_creation_url = "https://github.com/orgs/#{config['Org']}/new-team" open_url(team_creation_url) else members_not_added = [] begin file_path = "#{Dir.home}#{params}" teams_json = File.read(file_path) teams_file = JSON.parse(teams_json) spinner = custom_spinner("Creating teams in #{config['Orgs']} :spinner ...") teams_file['teams'].each do |team| # assigned to 'created_team' to grab the ID (and use it for adding members) # of the newly created team created_team = client.create_team(config['Org'].to_s, name: team['name'].to_s, privacy: team['privacy']) team['members'].each do |member| member_addition = client.add_team_member(created_team[:id], member) members_not_added.push(member) if member_addition == false # if !!member_adition end end spinner.stop(Rainbow('done!').color(4, 255, 0)) puts Rainbow('Teams created correctly!').color(79, 138, 16) puts Rainbow("Could not add following members: #{members_not_added}").color(WARNING_CODE) unless members_not_added.empty? rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end end end |
#delete_member(client, config, param) ⇒ Object
Removes a group of members form current organization. It is possible to specify them in a file or with Regexp to match GitHub IDs.
if Regexp will remove matching GitHub IDs from organization
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 401 |
# File 'lib/actions/orgs.rb', line 369 def delete_member(client, config, param) = client.organization_membership(config['Org'], opts = { user: client.login }) unless [:role] == 'admin' puts Rainbow("You must have Admin permissions on #{config['Org']} to run this command.").underline.color(WARNING_CODE) return end if is_file?("#{Dir.home}#{param}") puts 'Removing member/members from file.' file_path = "#{Dir.home}#{param}" remove_json = File.read(file_path) remove_member_file = JSON.parse(remove_json) remove_member_file['remove'].each do |member| client.remove_organization_member(congif['Org'], member['id'].to_s) end elsif eval(param).is_a?(Regexp) members_to_remove = [] pattern = build_regexp_from_string(param) client.organization_members(config['Org'].to_s).each do |member| members_to_remove.push(member[:login]) if pattern.match(member[:login]) end if members_to_remove.empty? puts Rainbow("No members to remove matched with \/#{pattern.source}\/").color(WARNING_CODE) else members_to_remove.each do |i| client.remove_organization_member(congif['Org'], i.to_s) end end end rescue SyntaxError => e puts Rainbow('Parameter is not a file and there was a Syntax Error building Regexp.').color(ERROR_CODE) rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end |
#foreach_eval(client, config, params) ⇒ Object
Evaluate a bash command in each submodule
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/actions/orgs.rb', line 190 def foreach_eval(client, config, params) if config['Repo'] return unless repo_has_submodules?(client, config) command = params.join(' ') FileUtils.cd(Dir.pwd) do system("git submodule foreach '#{command} || :'") end else puts Rainbow('Please change to an organization repository to run this command.').color(INFO_CODE) return end rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end |
#foreach_try(client, config, params) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/actions/orgs.rb', line 205 def foreach_try(client, config, params) if config['Repo'] return unless repo_has_submodules?(client, config) command = params.join(' ') FileUtils.cd(Dir.pwd) do system("git submodule foreach '#{command}'") end else puts Rainbow('Please change to an organization repository to run this command.').color(INFO_CODE) return end rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end |
#invite_all_outside_collaborators(client, config, param) ⇒ Object
Invite as members all outside collaborators from organization. This action needs admin permissions on the organization. This method checks first if parameter is an existing file, then checks Regexp, else invites all outside collaborators of current organization.
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/actions/orgs.rb', line 411 def invite_all_outside_collaborators(client, config, param) = client.organization_membership(config['Org'], opts = { user: client.login }) unless [:role] == 'admin' puts Rainbow("You must have Admin permissions on #{config['Org']} to run this command.").underline.color(WARNING_CODE) return end outside_collaborators = [] spinner = custom_spinner('Sending invitations :spinner ...') if is_file?("#{Dir.home}#{param}") puts 'Adding outside collaborators from file' file_path = "#{Dir.home}#{param}" collab_json = File.read(file_path) collab_file = JSON.parse(collab_json) collab_file['collabs'].each do |collab| outside_collaborators.push(collab['id']) end elsif eval(param).is_a?(Regexp) pattern = build_regexp_from_string(param) client.outside_collaborators(config['Org']).each do |i| outside_collaborators.push(i[:login]) if pattern.match(i[:login]) end else begin client.outside_collaborators(config['Org']).each do |i| outside_collaborators.push(i[:login]) end rescue StandardError => exception puts Rainbow('If you entered file path, please ensure that is the correct path.').color(ERROR_CODE) end end outside_collaborators.each do |j| = { role: 'member', user: j.to_s } client.update_organization_membership(config['Org'], ) end spinner.stop(Rainbow('done!').color(4, 255, 0)) rescue SyntaxError => e puts Rainbow('Parameter is not a file and there was a Syntax Error building Regexp.').color(ERROR_CODE) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) end |
#new_eval(client, config, params) ⇒ Object
Create a ‘super repo’ containing assignment repositories as submodules
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 |
# File 'lib/actions/orgs.rb', line 145 def new_eval(client, config, params) = { private: true, organization: config['Org'].to_s, description: 'Evaluation repository created using ghedsh.' } repo_name = params[0] submodules = [] evaluation_repo = client.create_repository(repo_name, ) pattern = build_regexp_from_string(params[1]) client.organization_repositories(config['Org'].to_s).each do |repo| submodules << repo[:ssh_url] if pattern.match(repo[:name]) && (repo[:name] != repo_name) end unless submodules.empty? local_repo_path = "#{Dir.pwd}/#{repo_name}" FileUtils.mkdir_p(local_repo_path) FileUtils.cd(local_repo_path) do system('git init') submodules.each do |i| system("git submodule add #{i}") end system('git add .') system('git commit -m "First commit"') system("git remote add origin #{evaluation_repo[:ssh_url]}") system('git push -u origin master') end end puts Rainbow("No submodule found with /#{pattern.source}/") if submodules.empty? rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end |
#open_info(config, params, client) ⇒ Object
Open info on default browser.
If ‘params’ is String or Regexp user selects referred organization members
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/actions/orgs.rb', line 48 def open_info(config, params, client) unless params.nil? # looking for org member by regexp pattern = build_regexp_from_string(params) member_url = select_member(config, pattern, client) open_url(member_url.to_s) unless member_url.nil? return end if config['Repo'].nil? open_url(config['org_url'].to_s) else open_url(config['repo_url'].to_s) end rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) puts end |
#read_orgs(client) ⇒ Object
740 741 742 743 744 745 746 747 748 |
# File 'lib/actions/orgs.rb', line 740 def read_orgs(client) orgslist = [] org = client.organizations org.each do |i| o = eval(i.inspect) orgslist.push(o[:login]) end orgslist end |
#remove_org_member ⇒ Object
Removes a group of GitHub users from an organization
687 |
# File 'lib/actions/orgs.rb', line 687 def remove_org_member; end |
#remove_repo(enviroment, repo_name) ⇒ Object
Removes repository by name
675 676 677 678 679 680 681 682 |
# File 'lib/actions/orgs.rb', line 675 def remove_repo(enviroment, repo_name) client = enviroment.client client.delete_repository("#{enviroment.config['Org']}/#{repo_name}") puts Rainbow('Repository deleted.').color(INFO_CODE) rescue StandardError => exception puts Rainbow(exception..to_s).color(ERROR_CODE) puts end |
#remove_team(config) ⇒ Object
Open org’s team list and delete manually (faster than checking teams IDs and delete it)
735 736 737 738 |
# File 'lib/actions/orgs.rb', line 735 def remove_team(config) teams_url = "https://github.com/orgs/#{config['Org']}/teams" open_url(teams_url) end |
#repo_has_submodules?(client, config) ⇒ Boolean
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/actions/orgs.rb', line 173 def repo_has_submodules?(client, config) repo_content = [] client.contents("#{config['Org']}/#{config['Repo']}").each do |i| repo_content << i[:name] end unless repo_content.include?('.gitmodules') puts Rainbow('Current repo does not include .gitmodules and command will not work.').color(WARNING_CODE) return false end true end |
#show_commits(enviroment, params) ⇒ Object
Show commits of current repo. If user is not in a repo, repository name for commit showing must be provided.
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/actions/orgs.rb', line 625 def show_commits(enviroment, params) = {} if !enviroment.config['Repo'].nil? repo = enviroment.config['Repo'] [:sha] = if params.empty? 'master' else params[0] end else repo = params[0] [:sha] = if params[1].nil? 'master' else params[1] end end begin enviroment.client.commits("#{enviroment.config['Org']}/#{repo}", ).each do |i| puts "\tSHA: #{i[:sha]}" puts "\t\t Commit date: #{i[:commit][:author][:date]}" puts "\t\t Commit author: #{i[:commit][:author][:name]}" puts "\t\t\t Commit message: #{i[:commit][:message]}" puts end rescue StandardError => exception puts exception puts Rainbow("If you are not currently on a repo, USAGE TIP: `commits <repo_name> [branch_name]` (default: 'master')").color(INFO_CODE) end end |
#show_files(client, config, params) ⇒ Object
Display files and directories within a repository
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/actions/orgs.rb', line 225 def show_files(client, config, params) if config['Repo'] = { path: '' } [:path] = params[0] unless params.empty? file_names_and_types = [] client.contents("#{config['Org']}/#{config['Repo']}", ).each do |i| file_names_and_types << "#{i[:name]} (#{i[:type]})" end file_names_and_types.sort_by!(&:downcase) puts file_names_and_types else puts Rainbow('Please change to organization repository to see its files.').color(INFO_CODE) end rescue StandardError => e puts Rainbow(e..to_s).color(ERROR_CODE) end |
#show_issues(config) ⇒ Object
Open default browser and shows open issues
457 458 459 460 461 462 463 464 |
# File 'lib/actions/orgs.rb', line 457 def show_issues(config) if config['Repo'] issues_url = "https://github.com/#{config['Org']}/#{config['Repo']}/issues" open_url(issues_url) else puts Rainbow('Change to repo in order to view all issues').color(INFO_CODE) end end |
#show_people(client, config, params) ⇒ Object
Display organization people. It shows all members and if the authenticated user is org admin
also displays outside collaborators.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/actions/orgs.rb', line 476 def show_people(client, config, params) spinner = custom_spinner("Fetching #{config['Org']} people :spinner ...") spinner.auto_spin org_members = [] client.organization_members(config['Org'].to_s).each do |member| org_members << [member[:login], 'member'] end membership = {} client.organization_membership(config['Org'].to_s).each do |key, value| membership[key] = value end if membership[:role] == 'admin' client.outside_collaborators(config['Org'].to_s).each do |collab| org_members << [collab[:login], 'outside collaborator'] end end spinner.stop(Rainbow('done!').color(4, 255, 0)) if params.nil? table = Terminal::Table.new headings: ['Github ID', 'Role'], rows: org_members puts table else unless params.include?('/') raise Rainbow('Parameter must be a Regexp. Example: /pattern/').color(ERROR_CODE) return end pattern = build_regexp_from_string(params) occurrences = build_item_table(org_members, pattern) puts Rainbow("No member inside #{config['Org']} matched \/#{pattern.source}\/").color(INFO_CODE) if occurrences.zero? end end |
#show_repos(client, config, params) ⇒ Object
Display organization repos
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/actions/orgs.rb', line 72 def show_repos(client, config, params) spinner = custom_spinner("Fetching #{config['Org']} repositories :spinner ...") spinner.auto_spin org_repos = [] client.organization_repositories(config['Org'].to_s).each do |repo| org_repos << repo[:name] end org_repos.sort_by!(&:downcase) spinner.stop(Rainbow('done!').color(4, 255, 0)) if params.nil? item_counter = 0 org_repos.each do |repo_name| puts repo_name item_counter += 1 end puts "\n#{item_counter} #{config['Org']} repositories listed." else pattern = build_regexp_from_string(params) occurrences = show_matching_items(org_repos, pattern) puts Rainbow("No repository inside #{config['Org']} matched \/#{pattern.source}\/").color(INFO_CODE) if occurrences.zero? puts "\n#{occurrences} #{config['Org']} repositories listed." end end |
#show_teams(client, config, params) ⇒ Object
Display organization teams
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/actions/orgs.rb', line 247 def show_teams(client, config, params) org_teams = [] spinner = custom_spinner("Fetching #{config['Org']} teams :spinner ...") spinner.auto_spin client.organization_teams(config['Org'].to_s).each do |team| org_teams << team[:name] end org_teams.sort_by!(&:downcase) spinner.stop(Rainbow('done!').color(4, 255, 0)) if params.nil? org_teams.each do |name| puts name end else pattern = build_regexp_from_string(params) occurrences = show_matching_items(org_teams, pattern) puts Rainbow("No team inside #{config['Org']} matched \/#{pattern.source}\/").color(INFO_CODE) if occurrences.zero? end end |