class Recipes::Github
Public Instance Methods
ask()
click to toggle source
# File lib/potassium/recipes/github.rb, line 4 def ask github_repo_create = answer(:github) do Ask.confirm('Do you want to create a Github repository?') end set(:github_repo, github_repo_create) setup_repo if github_repo_create end
create()
click to toggle source
# File lib/potassium/recipes/github.rb, line 19 def create return unless selected?(:github_repo) create_github_repo copy_file '../assets/.github/pull_request_template.md', '.github/pull_request_template.md' end
setup_repo()
click to toggle source
# File lib/potassium/recipes/github.rb, line 12 def setup_repo setup_repo_private setup_repo_org setup_repo_name set(:github_access_token, get_access_token) end
Private Instance Methods
config_filename()
click to toggle source
# File lib/potassium/recipes/github.rb, line 104 def config_filename @config_filename ||= File.expand_path('~/.potassium') end
create_github_repo()
click to toggle source
# File lib/potassium/recipes/github.rb, line 55 def create_github_repo options = { private: get(:github_repo_private) } options[:organization] = get(:github_org) if get(:github_has_org) repo_name = get(:github_repo_name) is_retry = false begin github_client(is_retry).create_repository(repo_name, options) rescue Octokit::Unauthorized is_retry = true retry if retry_create_repo end end
get_access_token()
click to toggle source
# File lib/potassium/recipes/github.rb, line 90 def get_access_token return File.open(config_filename, 'r').read if File.exists?(config_filename) set_access_token end
github_client(is_retry = false)
click to toggle source
# File lib/potassium/recipes/github.rb, line 76 def github_client(is_retry = false) access_token = is_retry ? set_access_token : get(:github_access_token) octokit_client.new(access_token: access_token) end
octokit_client()
click to toggle source
# File lib/potassium/recipes/github.rb, line 81 def octokit_client if answer(:test) require_relative '../../../spec/support/fake_octokit' FakeOctokit else Octokit::Client end end
retry_create_repo()
click to toggle source
# File lib/potassium/recipes/github.rb, line 69 def retry_create_repo puts "Bad credentials, information on Personal Access Tokens here:" puts "https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token" puts "Make sure to give repo access to the personal access token" Ask.confirm("Do you want to retry?") end
set_access_token()
click to toggle source
# File lib/potassium/recipes/github.rb, line 96 def set_access_token access_token = answer(:github_access_token) do Ask.input('Enter a GitHub personal access token', password: true) end File.open(config_filename, 'w') { |f| f.write(access_token) } access_token end
setup_repo_name()
click to toggle source
# File lib/potassium/recipes/github.rb, line 48 def setup_repo_name repo_name = answer(:github_name) do Ask.input('What is the name for this repository?', default: get(:dasherized_app_name)) end set(:github_repo_name, repo_name) end
setup_repo_org()
click to toggle source
# File lib/potassium/recipes/github.rb, line 35 def setup_repo_org has_organization = answer(:github_has_org) do Ask.confirm('Is this repo for a Github organization?') end set(:github_has_org, has_organization) if has_organization repo_organization = answer(:github_org) do Ask.input('What is the organization for this repository?', default: 'platanus') end set(:github_org, repo_organization) end end
setup_repo_private()
click to toggle source
# File lib/potassium/recipes/github.rb, line 28 def setup_repo_private repo_private = answer(:github_private) do Ask.confirm('Should the repository be private?') end set(:github_repo_private, repo_private) end