Class: GemContribute::CLI::Submit
- Inherits:
-
Object
- Object
- GemContribute::CLI::Submit
- Includes:
- PlatformTools
- 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 the host’s compare/MR 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. The host-specific URL is built by the adapter (ADR-0011).
Constant Summary collapse
- BRANCH_REGEX =
%r{\Agem-contribute/issue-(\d+)\z}
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr, output: nil, git: GemContribute::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, output: nil, git: GemContribute::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.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gem_contribute/cli/submit.rb', line 25 def initialize(stdout: $stdout, stderr: $stderr, output: nil, git: GemContribute::Git.new, adapter_factory: ->(token:) { HostAdapters::GitHubAdapter.new(token: token) }, store: TokenStore.new, browser_opener: nil, working_dir: Dir.pwd) @output = output || Output::Standard.new(out: stdout, err: 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gem_contribute/cli/submit.rb', line 39 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 execute(branch, issue_number, origin, upstream) rescue AdapterError => e @output.error("submit failed: #{e.}") 1 end |