Skip to content

Commit

Permalink
SPR: don't autofill when more than one commit exists
Browse files Browse the repository at this point in the history
* If > 1 commit exists, don't pass in --fill
* Add a new option to allow people to opt-out of --fill in all cases
* Tell people when we are autofilling

Closes #152

Signed-off-by: Phil Dibowitz <phil@ipom.com>
  • Loading branch information
jaymzh committed Mar 21, 2024
1 parent cc4ff44 commit 7eb41a5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bin/sj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ parser = OptionParser.new do |opts|
options['log_level'] = level
end

opts.on(
'--[no-]pr-autofill',
'When creating a PR, auto fill the title & description from the commit ' +
'if there is a single commit and if we are using "gh". [default: true]',
) do |autofill|
options['pr_autofill'] = autofill
end

opts.on('--[no-]use-color', 'Enable color. [default: true]') do |color|
options['color'] = color
end
Expand Down
20 changes: 19 additions & 1 deletion lib/sugarjar/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(options)
@repo_config = SugarJar::RepoConfig.config
SugarJar::Log.debug("Repoconfig: #{@repo_config}")
@color = options['color']
@pr_autofill = options['pr_autofill']
@feature_prefix = options['feature_prefix']
@checks = {}
@main_branch = nil
Expand Down Expand Up @@ -318,16 +319,33 @@ def version
def smartpullrequest(*args)
assert_in_repo
assert_common_main_branch

if dirty?
SugarJar::Log.warn(
'Your repo is dirty, so I am not going to create a pull request. ' +
'You should commit or amend and push it to your remote first.',
)
exit(1)
end

if gh?
if @pr_autofill
curr = current_branch
base = tracked_branch
num_commits = git(
'rev-list', '--count', curr, "^#{base}"
).stdout.strip.to_i
if num_commits > 1
SugarJar::Log.debug(
"Not using --fill because there are #{num_commits} commits",
)
else
SugarJar::Log.info('Autofilling in PR from commit message')
args.unshift('--fill')
end
end
SugarJar::Log.trace("Running: gh pr create #{args.join(' ')}")
system(which('gh'), 'pr', 'create', '--fill', *args)
system(which('gh'), 'pr', 'create', *args)
else
SugarJar::Log.trace("Running: hub pull-request #{args.join(' ')}")
system(which('hub'), 'pull-request', *args)
Expand Down
1 change: 1 addition & 0 deletions lib/sugarjar/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Config
'github_cli' => 'auto',
'github_user' => ENV.fetch('USER'),
'fallthru' => true,
'pr_autofill' => true,
}.freeze

def self._find_ordered_files
Expand Down

0 comments on commit 7eb41a5

Please sign in to comment.