Module: Dishwasher::Github

Extended by:
MessageFormatter
Defined in:
lib/dishwasher/github.rb

Class Method Summary collapse

Methods included from MessageFormatter

abort_message, body_message, title_message

Class Method Details

.canceled_messagestring

Canceled message

Returns:

  • (string)

    message indicating the operation was canceled



114
115
116
# File 'lib/dishwasher/github.rb', line 114

def canceled_message
  abort_message("Operation canceled by user.")
end

.choiceshash

Potential choices to choose from for deletion

Returns:

  • (hash)

    key: repo name, value: repo id



66
67
68
# File 'lib/dishwasher/github.rb', line 66

def choices
  forks.map { |f| [f[:full_name], f[:id]] }.to_h
end

.clientobject

GitHub Client Object

Returns:

  • (object)

    GitHub Client Object



28
29
30
# File 'lib/dishwasher/github.rb', line 28

def client
  @client ||= Octokit::Client.new(access_token: token, per_page: 1000)
end

.confirmation_promptboolean

Prompt to confirm deletion of repos

Returns:

  • (boolean)

    T:F depending on selection



86
87
88
89
# 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_selectionsarray

Selected forks for deletion

Returns:

  • (array)

    array of repo id’s



75
76
77
78
79
# 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) ⇒ Boolean

Delete passed in repository ID

Parameters:

  • r (int)

    repository ID

Returns:

  • (Boolean)

    success or failure



39
40
41
# File 'lib/dishwasher/github.rb', line 39

def delete_repo(r)
  client.delete_repository(r)
end

.forksobject

All forked repositories for the client

Returns:

  • (object)

    all forked repositories for the client



57
58
59
# File 'lib/dishwasher/github.rb', line 57

def forks
  repos.select { |hash| hash[:fork] == true }
end

.no_selectionsstring

No selection message

Returns:

  • (string)

    message indicating no selections were made



105
106
107
# File 'lib/dishwasher/github.rb', line 105

def no_selections
  abort_message("No selections were made.")
end

.promptobject

Initialize new TTY Prompt

Returns:

  • (object)

    TTY::Prompt



10
11
12
# File 'lib/dishwasher/github.rb', line 10

def prompt
  @prompt ||= TTY::Prompt.new
end

.reposobject

Repositories for the client object

Returns:

  • (object)

    repository objects



48
49
50
# File 'lib/dishwasher/github.rb', line 48

def repos
  client.repos(user: client.user, query: {type: "owner", sort: "asc"})
end

.selection(c) ⇒ array

Array of selected id’s

Returns:

  • (array)

    repo id’s chosen for deletion



96
97
98
# File 'lib/dishwasher/github.rb', line 96

def selection(c)
  prompt.multi_select(title_message("Select forks to delete"), c)
end

.tokenstring

Get GitHub Access Token so we can authenticate with GitHub’s API

Returns:

  • (string)

    GitHub Access Token



19
20
21
# 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