Class: Geet::Services::CreateRepo
- Inherits:
-
Object
- Object
- Geet::Services::CreateRepo
- Extended by:
- T::Sig
- Defined in:
- lib/geet/services/create_repo.rb
Constant Summary collapse
- VISIBILITIES =
T.let(["private", "public"].freeze, T::Array[String])
- FORK_ATTEMPTS =
30- FORK_RETRY_DELAY =
1- DEFAULT_SLEEPER =
T.let(->(delay) { Kernel.sleep(delay) }, T.proc.params(delay: Integer).void)
Instance Method Summary collapse
- #execute(visibility: nil, upstream: nil) ⇒ Object
-
#initialize(directory: Dir.pwd, out: $stdout, git_client: Utils::GitClient.new, api_interface: nil, prompt: TTY::Prompt.new, sleeper: DEFAULT_SLEEPER, fork_attempts: FORK_ATTEMPTS) ⇒ CreateRepo
constructor
A new instance of CreateRepo.
Constructor Details
#initialize(directory: Dir.pwd, out: $stdout, git_client: Utils::GitClient.new, api_interface: nil, prompt: TTY::Prompt.new, sleeper: DEFAULT_SLEEPER, fork_attempts: FORK_ATTEMPTS) ⇒ CreateRepo
Returns a new instance of CreateRepo.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/geet/services/create_repo.rb', line 28 def initialize(directory: Dir.pwd, out: $stdout, git_client: Utils::GitClient.new, api_interface: nil, prompt: TTY::Prompt.new, sleeper: DEFAULT_SLEEPER, fork_attempts: FORK_ATTEMPTS) @directory = directory @out = out @git_client = git_client @api_interface = T.let( api_interface || Github::ApiInterface.new(ENV["GH_TOKEN"] || raise("GH_TOKEN not set!")), Github::ApiInterface ) @prompt = prompt @sleeper = sleeper @fork_attempts = fork_attempts end |
Instance Method Details
#execute(visibility: nil, upstream: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/geet/services/create_repo.rb', line 42 def execute(visibility: nil, upstream: nil) preflight(visibility:, upstream:) name = File.basename(@directory) branch = @git_client.current_branch selected_visibility = T.let(nil, T.nilable(String)) selected_visibility = visibility || T.cast(@prompt.select("Visibility:", VISIBILITIES), String) if !upstream repository = upstream ? create_fork(name, upstream) : Github::Repository.create(name, selected_visibility, @api_interface) @git_client.add_remote(Utils::GitClient::ORIGIN_NAME, repository.ssh_url) @git_client.add_remote(Utils::GitClient::UPSTREAM_NAME, upstream) if upstream @git_client.push(remote_branch: branch) repository.update_default_branch(branch) @out.puts "Repository address: #{repository.html_url}" @out.puts "Default branch: #{branch}" repository end |