module Dishwasher::Github
Public Class Methods
Canceled message
@return [string] message indicating the operation was canceled
# File lib/dishwasher/github.rb, line 114 def canceled_message abort_message("Operation canceled by user.") end
Potential choices to choose from for deletion
@return [hash] key: repo name, value: repo id
# File lib/dishwasher/github.rb, line 66 def choices forks.map { |f| [f[:full_name], f[:id]] }.to_h end
GitHub Client Object
@return [object] GitHub Client Object
# File lib/dishwasher/github.rb, line 28 def client @client ||= Octokit::Client.new(access_token: token, per_page: 1000) end
Prompt to confirm deletion of repos
@return [boolean] T:F depending on selection
# File lib/dishwasher/github.rb, line 86 def confirmation_prompt title_message("Are you sure you want to delete these forked repos?") prompt.yes?("→") end
Selected forks for deletion
@return [array] array of repo id's
# File lib/dishwasher/github.rb, line 75 def confirmed_selections selections = selection(choices) no_selections if selections.empty? confirmation_prompt ? selections : canceled_message end
Delete passed in repository ID
@param [int] r repository ID
@return [Boolean] success or failure
# File lib/dishwasher/github.rb, line 39 def delete_repo(r) client.delete_repository(r) end
All forked repositories for the client
@return [object] all forked repositories for the client
# File lib/dishwasher/github.rb, line 57 def forks repos.select { |hash| hash[:fork] == true } end
No selection message
@return [string] message indicating no selections were made
# File lib/dishwasher/github.rb, line 105 def no_selections abort_message("No selections were made.") end
Initialize new TTY Prompt
@return [object] TTY::Prompt
# File lib/dishwasher/github.rb, line 10 def prompt @prompt ||= TTY::Prompt.new end
Repositories for the client object
@return [object] repository objects
# File lib/dishwasher/github.rb, line 48 def repos client.repos(user: client.user, query: {type: "owner", sort: "asc"}) end
Array of selected id's
@return [array] repo id's chosen for deletion
# File lib/dishwasher/github.rb, line 96 def selection(c) prompt.multi_select(title_message("Select forks to delete"), c) end
Get GitHub Access Token so we can authenticate with GitHub's API
@return [string] GitHub Access Token
# File lib/dishwasher/github.rb, line 19 def token @token ||= prompt.mask(title_message("What is your GitHub Personal Access Token?"), default: ENV["GITHUB_ACCESS_TOKEN"]) end