Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gh usage to prevent pushes and prompts #169

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions lib/sugarjar/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,29 +354,16 @@ def smartpullrequest(*args)
"this PR on #{base}? [y/n] ",
)
ans = $stdin.gets.strip
args += ['--base', base] if %w{Y y}.include?(ans)
args.unshift('--base', base) if %w{Y y}.include?(ans)
elsif @pr_autostack
args += ['--base', base]
args.unshift('--base', base)
end
end
# Ideally we'd have gh not push and not prompt, and thus not fuck
# with the local branch. However, it has a bug:
# https://github.com/cli/cli/issues/10448
SugarJar::Log.info(
"Please choose #{color(push_target_friendly_name, :green)}, at the" +
" prompt from 'gh' below",
)
# <org>:<branch> is the GH API syntax for:
# look for a branch of name <branch>, from a fork in owner <org>
args.unshift('--head', "#{push_org}:#{curr}")
SugarJar::Log.trace("Running: gh pr create #{args.join(' ')}")
system(which('gh'), 'pr', 'create', *args)
new_tracked = tracked_branch
# Until above bug is solved, make sure we fix what gh does
if base != new_tracked
SugarJar::Log.debug(
"Resetting tracked branch after 'gh' changed it from #{base} to " +
new_tracked,
)
git('branch', '-u', base)
end
else
SugarJar::Log.trace("Running: hub pull-request #{args.join(' ')}")
system(which('hub'), 'pull-request', *args)
Expand Down Expand Up @@ -963,9 +950,10 @@ def upstream
@remote
end

def push_target_friendly_name
# Whatever org we push to, regardless of if this is a fork or not
def push_org
url = git('remote', 'get-url', 'origin').stdout.strip
"#{extract_org(url)}/#{extract_repo(url)}"
extract_org(url)
end

def branch_from_ref(ref, type = :local)
Expand Down
Loading