Class: GemContribute::CLI::Submit
- Inherits:
-
Object
- Object
- GemContribute::CLI::Submit
- Defined in:
- lib/gem_contribute/cli/submit.rb
Overview
‘gem-contribute submit` — push the current branch to the user’s fork and open a pre-filled PR compare page in the browser.
Run from inside a clone created by ‘gem-contribute fix`. Reads:
- origin remote → fork owner/repo (where the branch is pushed)
- upstream remote → canonical owner/repo (where the PR is filed)
- current branch → must match `gem-contribute/issue-<N>`
The PR itself is NOT opened via API. We push, then open GitHub’s compare page in the browser with title and body pre-filled. This mirrors the ‘auth login` UX (browser handles the human step) and means the user always reviews the PR text before submitting.
Constant Summary collapse
- BRANCH_REGEX =
%r{\Agem-contribute/issue-(\d+)\z}
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr, git: Git.new, adapter_factory: ->(token:) { HostAdapters::GitHubAdapter.new(token: token) }, store: TokenStore.new, browser_opener: nil, working_dir: Dir.pwd) ⇒ Submit
constructor
A new instance of Submit.
- #run(_argv) ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr, git: Git.new, adapter_factory: ->(token:) { HostAdapters::GitHubAdapter.new(token: token) }, store: TokenStore.new, browser_opener: nil, working_dir: Dir.pwd) ⇒ Submit
Returns a new instance of Submit.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gem_contribute/cli/submit.rb', line 23 def initialize(stdout: $stdout, stderr: $stderr, git: Git.new, adapter_factory: ->(token:) { HostAdapters::GitHubAdapter.new(token: token) }, store: TokenStore.new, browser_opener: nil, working_dir: Dir.pwd) @stdout = stdout @stderr = stderr @git = git @adapter_factory = adapter_factory @store = store @browser_opener = browser_opener || method(:default_browser_opener) @working_dir = working_dir end |
Instance Method Details
#run(_argv) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gem_contribute/cli/submit.rb', line 38 def run(_argv) branch = current_branch issue_number = parse_issue_number(branch) return 1 if issue_number.nil? origin = parse_remote("origin", required: true) return 1 if origin.nil? # When the user owns the upstream (e.g. self-dogfooding) there's no # separate fork and no `upstream` remote — fall back to origin and # build a same-repo PR. upstream = parse_remote("upstream", required: false) || origin title = fetch_issue_title(upstream, issue_number) push_branch(branch) url = compare_url(upstream, origin, branch, issue_number, title) open_and_print(url) 0 rescue AdapterError => e @stderr.puts "submit failed: #{e.}" 1 end |