module Dishwasher::Github

Public Class Methods

canceled_message() click to toggle source

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
choices() click to toggle source

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
client() click to toggle source

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
confirmation_prompt() click to toggle source

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
confirmed_selections() click to toggle source

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_repo(r) click to toggle source

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
forks() click to toggle source

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_selections() click to toggle source

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
prompt() click to toggle source

Initialize new TTY Prompt

@return [object] TTY::Prompt

# File lib/dishwasher/github.rb, line 10
def prompt
  @prompt ||= TTY::Prompt.new
end
repos() click to toggle source

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
selection(c) click to toggle source

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
token() click to toggle source

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